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
Check · Review · Land · Live done — Landed and live in production.
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.
shipped production is serving it deploy 6dfa34b
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_uriandverification_uri_completeare accepted only on a host the origin was registered with, meaning itswebUrlorapiUrl(so a sibling likeapi.github.comis 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 withinvalid_response. The check isonOriginHost. - Lifetime and polling:
expires_inis clamped toMAX_DEVICE_EXPIRES_SECS(15 minutes, as RFC 8628 suggests and GitHub uses).intervalis clamped toMAX_DEVICE_INTERVAL_SECS(60 s). - New test:
test/oauth-device-target.test.tsrunsstartDeviceagainst a stub origin. It checks that a foreignverification_uriis refused, that a foreign_completeis refused even next to a validverification_uri, and thatexpires_in: 315360000andinterval: 86400are 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.tsused to give outhttps://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 ashttps://localhost, now useshttps://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
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).
startDeviceinsrc/origins/oauth.tsnow 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.examplealive for about ten years.verification_uriandverification_uri_completeare accepted only on a host the origin was registered with, meaning itswebUrlorapiUrl(so a sibling likeapi.github.comis 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 withinvalid_response. The check isonOriginHost.expires_inis clamped toMAX_DEVICE_EXPIRES_SECS(15 minutes, as RFC 8628 suggests and GitHub uses).intervalis clamped toMAX_DEVICE_INTERVAL_SECS(60 s).test/oauth-device-target.test.tsrunsstartDeviceagainst a stub origin. It checks that a foreignverification_uriis refused, that a foreign_completeis refused even next to a validverification_uri, and thatexpires_in: 315360000andinterval: 86400are clamped. It also covers look-alike hosts, credentials in the URL, other schemes and plain http. These cases fail on main.test/fake-origin.tsused to give outhttps://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 ashttps://localhost, now useshttps://localhost/login/device.Left out: the issue's third fix, re-checking the target's host in
targetForShortCodewhen/go/<code>is served, is not done; it would be defence in depth only. The brokered path is covered because the parent callsstartDevicebefore passing the result on, butsrc/origins/broker.tsstill only checks for https.Checks run:
bun scripts/gate.ts --fix(it rewrapped one comment, which is committed) andbun x tsc --noEmitpass.scripts/fast.tsnamed 2555 files becausefake-origin.tsis 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