Handle UTM params in redirect
This commit is contained in:
@@ -11,6 +11,11 @@ type Events = {
|
|||||||
whitelisted: 'unknown' | 'yes'
|
whitelisted: 'unknown' | 'yes'
|
||||||
blocked: boolean
|
blocked: boolean
|
||||||
warned: boolean
|
warned: boolean
|
||||||
|
utm_source?: string
|
||||||
|
utm_medium?: string
|
||||||
|
utm_campaign?: string
|
||||||
|
utm_content?: string
|
||||||
|
utm_term?: string
|
||||||
}
|
}
|
||||||
invalid_redirect: {
|
invalid_redirect: {
|
||||||
link: string
|
link: string
|
||||||
|
|||||||
@@ -101,6 +101,11 @@ export default function (ctx: AppContext, app: Express) {
|
|||||||
whitelisted,
|
whitelisted,
|
||||||
blocked,
|
blocked,
|
||||||
warned,
|
warned,
|
||||||
|
utm_source: req.query.utm_source?.toString(),
|
||||||
|
utm_medium: req.query.utm_medium?.toString(),
|
||||||
|
utm_campaign: req.query.utm_campaign?.toString(),
|
||||||
|
utm_content: req.query.utm_content?.toString(),
|
||||||
|
utm_term: req.query.utm_term?.toString(),
|
||||||
})
|
})
|
||||||
|
|
||||||
return res.end(html)
|
return res.end(html)
|
||||||
|
|||||||
@@ -360,4 +360,21 @@ describe('link service no safelink', async () => {
|
|||||||
// No blocked-site div, always safe
|
// No blocked-site div, always safe
|
||||||
assert.doesNotMatch(html, /"blocked-site"/)
|
assert.doesNotMatch(html, /"blocked-site"/)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('normal redirect with query params', async () => {
|
||||||
|
const urlToRedirect = 'https://bsky.app/settings'
|
||||||
|
const url = new URL(`${baseUrl}/redirect`)
|
||||||
|
url.searchParams.set('u', urlToRedirect)
|
||||||
|
url.searchParams.set('utm_source', 'test')
|
||||||
|
const res = await fetch(url, {redirect: 'manual'})
|
||||||
|
assert.strictEqual(res.status, 200)
|
||||||
|
const html = await res.text()
|
||||||
|
assert.match(html, /meta http-equiv="refresh"/)
|
||||||
|
assert.match(
|
||||||
|
html,
|
||||||
|
new RegExp(urlToRedirect.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')),
|
||||||
|
)
|
||||||
|
// No blocked-site div, always safe
|
||||||
|
assert.doesNotMatch(html, /"blocked-site"/)
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user