Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions apps/web/lib/middleware/utils/get-final-url.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export const getFinalUrl = (

if (via) {
urlObj.searchParams.set("via", via);
urlObj.searchParams.set("afsrc", "1");
}
Comment on lines 36 to 39
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Prevent partner params from being overridden by incoming query params.

via/afsrc=1 are set here, but later passthrough merging can overwrite them (Line 125–129). A request like ?via=spoof&afsrc=0 can break the intended partner-link behavior.

Suggested fix
   for (const [key, value] of searchParams) {
     // we will pass everything except internal query params (dub-no-track and redir_url)
     if (["dub-no-track", REDIRECTION_QUERY_PARAM].includes(key)) continue;
+    // preserve enforced partner attribution params
+    if (via && (key === "via" || key === "afsrc")) continue;
     urlObj.searchParams.set(key, value);
   }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@apps/web/lib/middleware/utils/get-final-url.ts` around lines 36 - 39, Ensure
partner parameters 'via' and 'afsrc' cannot be overridden by incoming query
params: when merging passthrough query parameters into urlObj.searchParams (the
merge loop currently around the passthrough logic), skip keys 'via' and 'afsrc'
(i.e., do not set/overwrite urlObj.searchParams for those keys) or move the code
that sets urlObj.searchParams.set("via", via) and
urlObj.searchParams.set("afsrc","1") to run after the passthrough merge in
get-final-url.ts so that urlObj.searchParams always ends up with the intended
partner values; reference the existing urlObj.searchParams usage and the
passthrough merge block (the loop that applies incoming query params) to
implement the fix.


if (clickId) {
Expand Down
1 change: 1 addition & 0 deletions apps/web/tests/redirects/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ async function assertRedirectWithDubIdCookie(

if (options?.via != null) {
expect(redirectUrl.searchParams.get("via")).toBe(options.via);
expect(redirectUrl.searchParams.get("afsrc")).toBe("1");
}

expect(response.headers.get("x-powered-by")).toBe(poweredBy);
Expand Down
Loading