ChangesAttempt 1 · 2 files · +17 −15
api/auth/redirect.ts+14 −9
@@ -18,12 +18,14 @@ export function afterSignIn(req, res)
1818export function afterSignIn(req, res) {
19− const next = req.query.next || "/login";
20− if (!req.session) return res.redirect(next);
19+ const next = safeNext(req.query.next) ?? "/";
20+ if (!req.session?.valid) {
21+ return res.redirect(`/login?next=${encodeURIComponent(next)}`);
22+ }
2123 return res.redirect(next);
2224}
2325
26+function safeNext(p) {
27+ return typeof p === "string" && p.startsWith("/") && !p.startsWith("//") ? p : null;
28+}
Sample: safeNext() closes the red team’s open-redirect finding. Contract tests recorded as passed. Evidence
api/auth/redirect.ts+14 −9
@@ -18,12 +18,14 @@ export function afterSignIn(req, res)
18export function afterSignIn(req, res) {
19−const next = req.query.next || "/login";
20−if (!req.session) return res.redirect(next);
19+const next = safeNext(req.query.next) ?? "/";
20+if (!req.session?.valid) {
21+ return res.redirect(`/login?next=${encodeURIComponent(next)}`);
22+}
23return res.redirect(next);
24}
25
26+function safeNext(p) {
27+return typeof p === "string" && p.startsWith("/") && !p.startsWith("//") ? p : null;
28+}
Sample: safeNext() closes the red team’s open-redirect finding. Contract tests recorded as passed. Evidence
2 of 2 files · +17 −15 · read only. A person chooses when to merge.
Not available in this sample. Nothing runs here.
Moves to Done in this sample. A person merges.More