Skip to content

Commit 069a70f

Browse files
committed
fix(app-router): encode returnTo in login redirect to prevent OAuth param injection
URLencode returnTo in appRouteHandlerFactory so the query params don't break out into /auth/login and get forwarded to /authorize (e.g., scope, audience, etc). Also obey the local returnTo instead of the global opt. This bug was found with ZeroPath. Signed-off-by: Joshua Rogers <[email protected]>
1 parent 0055cc4 commit 069a70f

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

src/server/helpers/with-page-auth-required.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ export const appRouteHandlerFactory =
196196
: opts.returnTo;
197197
const { redirect } = await import("next/navigation.js");
198198
redirect(
199-
`${config.loginUrl}${opts.returnTo ? `?returnTo=${returnTo}` : ""}`
199+
`${config.loginUrl}${returnTo ? `?returnTo=${encodeURIComponent(returnTo)}` : ""}`
200200
);
201201
}
202202
return handler(params);

0 commit comments

Comments
 (0)