acme/web · PR #1210
Fix auth redirect loop
Back to summaryResolved threads fold away.Nothing here is posted to GitHub.
api/auth/redirect.ts
@@ -18,6 +18,8 @@ export function afterSignIn(req, res)@@ -18,6 +18,8 @@ afterSignIn(req, res)
1919− const next = req.query.next || "/login";const next = req.query.next || "/login";
19+ const next = safeNext(req.query.next) ?? "/";const next = safeNext(req.query.next) ?? "/";
Open redirect through ?next= · resolved in this sample
20+ if (!req.session?.valid) {if (!req.session?.valid) {
@@ +26,4 @@@@ +26,4 @@
27+function safeNext(p) {function safeNext(p) {
28+ return typeof p === "string" && p.startsWith("/") && !p.startsWith("//") ? p : null;return typeof p === "string" && p.startsWith("/") && !p.startsWith("//") ? p : null;
Also reject /\ in safeNext()Suggestion · Codex: suggestion · Claude Code: nit· line 28
Codex red team · Sample
/\evil.example passes this check. The sample router normalises it; the suggested line closes this case.
−return typeof p === "string" && p.startsWith("/") && !p.startsWith("//") ? p : null;
+return typeof p === "string" && /^\/(?![\/\\])/.test(p) ? p : null;
Claude Code · Sample
Agree with the change. I’d call it a nit: fine as a follow-up.
Alex Chen · Sample
Let’s take it in this sample while it’s fresh.