Public: anyone can read this; the crew can change it.
A sign-in or consent redirect target that points off this origin is ignored #13607
Check · Review · Land · Live done — Landed and live in production.
A return address containing a tab no longer sends a signed-in person off this forge. safeNext in src/web/returnto.ts is the one check every door uses on its next. It already refused //host, https://host, backslashes and CR/LF, but let tabs and other control characters through.
shipped production is serving it deploy 59903fa
2 earlier comments
A return address containing a tab no longer sends a signed-in person off this forge. safeNext in src/web/return_to.ts is the one check every door uses on its next. It already refused //host, https://host, backslashes and CR/LF, but let tabs and other control characters through. A browser deletes those before reading an address, so /signin?next=%2F%09%2Fevil.example became //evil.example after sign-in.
The fix:
safeNextnow refuses every control character (U+0000–U+001F and U+007F).- It also refuses any value that the URL parser resolves to another origin, which covers forms nobody listed.
- Plain paths with a query string still come through unchanged, so deep links keep working.
The test: test/redirect-targets.test.ts has one table of 16 hostile inputs, including //host, https://host, javascript:, backslashes, tab, LF, CRLF, NUL, %2F%2F…, a leading space and a bare host. It runs them through:
safeNextitself;POST /signin, which redirects to/;- the
/loginand/sign-inaliases, which redirect to/signinwith nonext; - the
/signinand/signuppages, which must not mention the hostile host anywhere; - the OAuth consent page
/oauth/authorizeand the everyday-account switchPOST /settings/everyday/switch. Signed out, both send the person to/signin?next=with their own path, whatevernextorredirect_uriis passed.
Three deep links, including /kim/proj/issues?state=open&q=a%20b, still go back to themselves.
With the old safeNext, four of the six tests fail. The consent and everyday-switch rows already held before this change; for those, the test is the proof. I didn't change OAuth redirect_uri handling: by design it goes to the client's own registered address, which can be on another origin, and it is checked against what that client registered.
Checks: the gate, tsc --noEmit and seven test files pass (the new one plus web-ui, deadends, deadends-fixes, toolbar-signed-out, web-browse and guest-contribute). scripts/fast.ts named 2015 test files, too many to run in the sandbox, so the forge's full check covers the rest. I couldn't record the plan on the issue because there was no keep_plan tool in this session.
Try it: on the preview, open /login?next=%2F%09%2Fevil.example and sign in. You land on /. Then open /login?next=%2Fsettings%2Fkeys%3Fa%3D1 and sign in. You land on /settings/keys?a=1.
🤖 Generated with Claude Code
<!-- look-pages b3e3124961c1 --> Look pages for b3e3124, from the gate:
look pages (inferred): this pull changes src/web/return_to.ts; the forge pictures / (src/web/return_to.ts), /docs (src/web/return_to.ts), /explore (src/web/return_to.ts) and 20 more, the pages whose routes import it. A "Looks: <path>" or "No look: <why>" line in a commit message overrides
A return address on sign-in or consent is now refused if it contains a tab or other control character, or if a URL parser would read it as another origin. Opening /login?next=%2F%09%2Fevil.example and signing in lands on /, not on evil.example (#13580).
Changes
src/web/return_to.ts:safeNextrejects these addresses, which the old check let through.test/redirect-targets.test.ts: covers them at the boundary and through a real sign-in.
Fix for the check's red
The check failed on 2 tests in test/fork-follow-word.test.ts, which is unrelated to this change. They pass here every time, alone and in all of check shard 9, before and after merging main.
The cause is a race in that test. In setup, the parent's second commit starts a follow of the fork in the background. On a busy shard that follow can finish after the first test has switched the fork to take-updates. The follow reads the mode only when it finishes, so it then merges the parent, and the fork is no longer "1 behind". The test was wrong, not the app: setup now sets the fork to dont-follow for that one push, and every later test sets the mode it needs.
That leftover follow also printed "Cannot use a closed database" after the file finished. That error no longer appears, which confirms the follow was outliving the file.
Checks
bun scripts/gate.ts --fixpasses; it noted that/,/docs,/exploreand 25 more pages importreturn_to.ts, so the forge pictures them.bun x tsc --noEmitis clean.test/fork-follow-word.test.tsandtest/redirect-targets.test.tspass, 11 tests.
The branch also merges current main.
🤖 Generated with Claude Code
Approved. Preview checked: /login?next=%2F%09%2Fevil.example redirects to /signin with no next; a deep link /settings/keys?a=1 is kept. safeNext now refuses every control character and any value a URL parser resolves off-origin. The 16-row hostile table runs through safeNext, POST /signin, the aliases, both forms, consent and the everyday switch. The fork-follow-word race fix is small, and its comment says why. No UI markup changed, so there is no design-principle break. Next, two things I would do: (1) hoist the HOSTILE table into test/helpers so the OAuth redirect_uri and other next-readers can reuse it; (2) add a gate or lint rule that every door reads next through safeNext, so a new door cannot skip it.
A return address containing a tab no longer sends a signed-in person off this forge.
safeNextinsrc/web/return_to.tsis the one check every door uses on itsnext. It already refused//host,https://host, backslashes and CR/LF, but let tabs and other control characters through. A browser deletes those before reading an address, so/signin?next=%2F%09%2Fevil.examplebecame//evil.exampleafter sign-in.The fix:
safeNextnow refuses every control character (U+0000–U+001F and U+007F).The test:
test/redirect-targets.test.tshas one table of 16 hostile inputs, including//host,https://host,javascript:, backslashes, tab, LF, CRLF, NUL,%2F%2F…, a leading space and a bare host. It runs them through:safeNextitself;POST /signin, which redirects to/;/loginand/sign-inaliases, which redirect to/signinwith nonext;/signinand/signuppages, which must not mention the hostile host anywhere;/oauth/authorizeand the everyday-account switchPOST /settings/everyday/switch. Signed out, both send the person to/signin?next=with their own path, whatevernextorredirect_uriis passed.Three deep links, including
/kim/proj/issues?state=open&q=a%20b, still go back to themselves.With the old
safeNext, four of the six tests fail. The consent and everyday-switch rows already held before this change; for those, the test is the proof. I didn't change OAuthredirect_urihandling: by design it goes to the client's own registered address, which can be on another origin, and it is checked against what that client registered.Checks: the gate,
tsc --noEmitand seven test files pass (the new one plusweb-ui,deadends,deadends-fixes,toolbar-signed-out,web-browseandguest-contribute).scripts/fast.tsnamed 2015 test files, too many to run in the sandbox, so the forge's full check covers the rest. I couldn't record the plan on the issue because there was nokeep_plantool in this session.Try it: on the preview, open
/login?next=%2F%09%2Fevil.exampleand sign in. You land on/. Then open/login?next=%2Fsettings%2Fkeys%3Fa%3D1and sign in. You land on/settings/keys?a=1.🤖 Generated with Claude Code
Closes #13580