Repository navigation
fix(auth): reject untrusted browser origins for local OAuth callbacks - #149
Conversation
pierreraby
left a comment
There was a problem hiding this comment.
Approved on exact head 6cc45b4 after an independent security review and local validation.
Local validation: node --test tests/test-oauth.ts 18/18 including the two new regressions, tsc --noEmit clean, Prettier clean. The fresh security review verified the gate runs before every side effect (preflight, URL/method routing, body accumulation, JSON.parse, the parsed.error rejection path, and closeServer) and found no browser-reachable bypass: Origin: null, case/scheme/host variants, duplicated Origin headers, DNS rebinding and redirect chains all fail closed, and GET navigations reach only 404/405 without body processing. The threat-model exploit (cross-origin text/plain POST with a forged access_denied) is pinned by the new regression and asserts the server keeps listening and the legitimate callback still resolves.
Non-blocking notes for a follow-up:
- Consider pinning
Origin: null-> 403 and an Origin-less POST to/callback-> 200 in tests, so the browser-scoped contract cannot regress silently. - Pre-existing, out of scope here: the
parsed.errorpath is not state-bound, so any Origin-less local request can cancel a pending login without the state token. Requiringstate === expectedStatethere would close it. - The trusted allowlist is preserved unchanged; we will confirm the Studio transfer page's posting origin with one real browser login (the flow constructs a same-origin
https://commandcode.ai/studio/auth/cliURL) and fall back to a quick patch if it differs.
Thanks for the thorough PR and threat-model write-up!
pierreraby
left a comment
There was a problem hiding this comment.
Re-approved at 48b2907 after the branch was refreshed onto current main.
The delta from the previously reviewed 6cc45b4 is exactly one merge commit bringing main into the branch: the PR's own source delta is byte-identical (same normalized diff SHA-256 for src/auth-server.ts + tests/test-oauth.ts versus the reviewed base and versus current main), and no conflict was resolved. Full local suite on this integrated head passes with both real hosts required (386 tests, 0 fail, 0 skip, pi 1.1.0 + OMP 18.4.2 against mocks), Prettier and git diff --check clean, and all 13 GitHub checks are green on this exact head.
The security review verdict and the three non-blocking follow-ups from my previous approval stand unchanged.
Summary
Origin, before any callback payload is processed.text/plainPOST and an untrusted OPTIONS preflight.Why
CORS response headers do not authorize side-effecting requests: cross-origin
text/plainPOSTs can reach the local listener without requiring the browser to expose a response. Previously, an unsolicited callback error could terminate the pending login even if the request originated from another website. This adds an explicit server-side browser-Origin check.Validation
node --test tests/test-oauth.ts— 18 passed, including two new regressions.npm run typecheck— passed.src/auth-server.tsandtests/test-oauth.ts— passed.Limitations
This is defense in depth for browser-originated requests, not a claim of account takeover or credential disclosure. Local processes can omit/spoof Origin. The separate question of whether the Studio error callback should echo OAuth
stateremains outside this PR; the existing compatibility behavior is unchanged.Review of the trusted-origin allowlist is welcome.