Public: anyone can read this; the crew can change it.

A device-flow short link redirects only to the origin's own host, for a bounded time #15013

Merged opened this

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

Merged

startDevice in src/origins/oauth.ts now checks the verification address and lifetime an origin sends back before either is stored as the target of the anonymous /go/ redirect. This closes the #14771 finding where a member's own "github" host could keep /go/ → https://phish.example alive for about ten years.

Notes

shipped production is serving it deploy 6dfa34b

opened this

startDevice in src/origins/oauth.ts now checks the verification address and lifetime an origin sends back before either is stored as the target of the anonymous /go/<code> redirect. This closes the #14771 finding where a member's own "github" host could keep /go/<code> → https://phish.example alive for about ten years.

  • Verification address: verification_uri and verification_uri_complete are accepted only on a host the origin was registered with, meaning its webUrl or apiUrl (so a sibling like api.github.com is allowed because it is configured, not guessed). They must be https and carry no credentials in the URL. Plain http is accepted only when the registered web URL is itself plain http on exactly the same origin, which discovery already allows only for loopback or a host the operator named. Anything else fails with invalid_response. The check is onOriginHost.
  • Lifetime and polling: expires_in is clamped to MAX_DEVICE_EXPIRES_SECS (15 minutes, as RFC 8628 suggests and GitHub uses). interval is clamped to MAX_DEVICE_INTERVAL_SECS (60 s).
  • New test: test/oauth-device-target.test.ts runs startDevice against a stub origin. It checks that a foreign verification_uri is refused, that a foreign _complete is refused even next to a valid verification_uri, and that expires_in: 315360000 and interval: 86400 are clamped. It also covers look-alike hosts, credentials in the URL, other schemes and plain http. These cases fail on main.
  • Test fixture changes (the old fixtures were wrong, not the code):
    • test/fake-origin.ts used to give out https://example.invalid/device, which is now a foreign host. It now gives out its own /login/device.
    • test/origin-broker.test.ts, where the fake stands in as https://localhost, now uses https://localhost/login/device.

Left out: the issue's third fix, re-checking the target's host in targetForShortCode when /go/<code> is served, is not done; it would be defence in depth only. The brokered path is covered because the parent calls startDevice before passing the result on, but src/origins/broker.ts still only checks for https.

Checks run: bun scripts/gate.ts --fix (it rewrapped one comment, which is committed) and bun x tsc --noEmit pass. scripts/fast.ts named 2555 files because fake-origin.ts is shared widely, so I ran the 15 test files that touch device flows or the OAuth fake instead: 185 pass, 0 fail. The forge's check runs the full suite on push.

To try it: bun test test/oauth-device-target.test.ts test/origins-oauth.test.ts test/origin-broker.test.ts test/web-origins.test.ts

🤖 Generated with Claude Code

Closes #14952

commented

startDevice in src/origins/oauth.ts now checks the verification address and lifetime an origin sends back before either is stored as the target of the anonymous /go/<code> redirect. This closes the #14771 finding where a member's own "github" host could keep /go/<code> → https://phish.example alive for about ten years.

  • Verification address: verification_uri and verification_uri_complete are accepted only on a host the origin was registered with, meaning its webUrl or apiUrl (so a sibling like api.github.com is allowed because it is configured, not guessed). They must be https and carry no credentials in the URL. Plain http is accepted only when the registered web URL is itself plain http on exactly the same origin, which discovery already allows only for loopback or a host the operator named. Anything else fails with invalid_response. The check is onOriginHost.
  • Lifetime and polling: expires_in is clamped to MAX_DEVICE_EXPIRES_SECS (15 minutes, as RFC 8628 suggests and GitHub uses). interval is clamped to MAX_DEVICE_INTERVAL_SECS (60 s).
  • New test: test/oauth-device-target.test.ts runs startDevice against a stub origin. It checks that a foreign verification_uri is refused, that a foreign _complete is refused even next to a valid verification_uri, and that expires_in: 315360000 and interval: 86400 are clamped. It also covers look-alike hosts, credentials in the URL, other schemes and plain http. These cases fail on main.
  • Test fixture changes (the old fixtures were wrong, not the code):
    • test/fake-origin.ts used to give out https://example.invalid/device, which is now a foreign host. It now gives out its own /login/device.
    • test/origin-broker.test.ts, where the fake stands in as https://localhost, now uses https://localhost/login/device.

Left out: the issue's third fix, re-checking the target's host in targetForShortCode when /go/<code> is served, is not done; it would be defence in depth only. The brokered path is covered because the parent calls startDevice before passing the result on, but src/origins/broker.ts still only checks for https.

Checks run: bun scripts/gate.ts --fix (it rewrapped one comment, which is committed) and bun x tsc --noEmit pass. scripts/fast.ts named 2555 files because fake-origin.ts is shared widely, so I ran the 15 test files that touch device flows or the OAuth fake instead: 185 pass, 0 fail. The forge's check runs the full suite on push.

To try it: bun test test/oauth-device-target.test.ts test/origins-oauth.test.ts test/origin-broker.test.ts test/web-origins.test.ts

🤖 Generated with Claude Code

Approved

Clean, single-purpose, backend-only. startDevice now refuses a verification address off the registered web/API host (https only, no credentials; http only on an identical plaintext registration) and clamps expires_in (15 min) and interval (60 s). New tests cover foreign uri, foreign _complete, look-alikes, credentials, schemes and huge lifetimes; fixtures were corrected rather than the tests loosened. No new dependency, no UI/TUI surface, so no docs needed. Not done, and fine: re-checking the host when /go/<code> is served (defence in depth).

Sign in to join this conversation.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs