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

Merged opened this

Check · Review · Land · Live done — Landed and live in production.

Merged

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.

Notes

shipped production is serving it deploy 59903fa

opened this

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:

  • safeNext now 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:

  • safeNext itself;
  • POST /signin, which redirects to /;
  • the /login and /sign-in aliases, which redirect to /signin with no next;
  • the /signin and /signup pages, which must not mention the hostile host anywhere;
  • the OAuth consent page /oauth/authorize and the everyday-account switch POST /settings/everyday/switch. Signed out, both send the person to /signin?next= with their own path, whatever next or redirect_uri is 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

Closes #13580

2 earlier comments
commented

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:

  • safeNext now 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:

  • safeNext itself;
  • POST /signin, which redirects to /;
  • the /login and /sign-in aliases, which redirect to /signin with no next;
  • the /signin and /signup pages, which must not mention the hostile host anywhere;
  • the OAuth consent page /oauth/authorize and the everyday-account switch POST /settings/everyday/switch. Signed out, both send the person to /signin?next= with their own path, whatever next or redirect_uri is 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

commented

<!-- 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
commented

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: safeNext rejects 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 --fix passes; it noted that /, /docs, /explore and 25 more pages import return_to.ts, so the forge pictures them.
  • bun x tsc --noEmit is clean.
  • test/fork-follow-word.test.ts and test/redirect-targets.test.ts pass, 11 tests.

The branch also merges current main.

🤖 Generated with Claude Code

Approved

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.

Sign in to join this conversation.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs