Repository navigation
fix: remove CORS from the OAuth2 authorization endpoint - #29143
Conversation
OAuth 2.1 §3.1 forbids CORS at the authorization endpoint because the client redirects the user agent there and never fetches it. The permissive OAuth2 policy matched on the /oauth2/ prefix, so /oauth2/authorize answered every origin with a wildcard. - Send /oauth2/authorize, with or without a trailing slash, to the standard CORS policy. Tokens, revoke, register, clients, metadata, and MCP keep the permissive policy. - Add TestCors covering both policies, and a router test that the middleware still sits in front of the OAuth2 routes. - Document the posture in the OAuth2 provider security notes. Closes PLAT-601.
Docs previewCheck off each page once it's been reviewed. If a page changes in a later push, its checkbox clears automatically so it gets a fresh look. Pages not yet wired into the docs navigation aren't listed here. |
|
/coder-agents-review |
|
Chat: Review in progress (16/16 reviewers complete) | View chat deep-review v0.9.0 | Round 1 | Last posted: Round 1, 5 findings (1 P2, 1 P3, 1 Nit, 2 Note), COMMENT. Review Finding inventoryFinding inventory: PR #29143Findings
Citation resolution: Pariston and Kite flagged the "OAuth 2.1 §3.1 forbids CORS" comment/docs wording as stronger than the spec. Leorio chased the source and confirmed the OAuth 2.1 draft says CORS "MUST NOT be supported at the Authorization Endpoint," so the citation is accurate. Not a finding. Contradiction resolution (CRF-1): Pariston and Kurapika asserted Round logRound 1Panel (15 reviewers) + Netero. Netero: clean, no findings. Findings: 1 P2, 1 P3, 1 Nit, 2 Notes posted; 2 Notes dropped. Reviewed against 74d1eef..b0c4fa7. About deep-reviewCRF = Coder Review Finding (P0-P4, Nit, Note)
|
There was a problem hiding this comment.
Tight, well-scoped security fix with a test suite that earns its keep: 11 production lines carry 114 lines of test, the negative assertions walk every response header and fail on any Access-Control- prefix rather than checking one, and the matrix covers both policies across GET/POST/preflight plus the allowAll escape hatch. The OAuth 2.1 §3.1 citation checks out against the spec source ("MUST NOT be supported at the Authorization Endpoint"), the consent page is genuinely same-origin, and the AllowCredentials: false claim holds.
One substantive gap, found independently by three reviewers and reproduced end-to-end: the exclusion keys on r.URL.Path, but chi routes on the slash-normalized RoutePath, so /oauth2//authorize routes to the authorize handler yet still answers cross-origin with Access-Control-Allow-Origin: *. I confirmed it against a real coderdtest server: /oauth2/authorize returns no ACAO, /oauth2//authorize returns *. The stated conformance invariant is bypassable with one extra slash. Practical exposure stays at the low level the PR describes (credentials disallowed), so it is P2, not higher, but the control does not yet hold. Two earlier reviewers argued singleSlashMW normalizes r.URL.Path and there is no bypass; the code normalizes rctx.RoutePath and leaves r.URL.Path untouched, and the live server disproves that argument.
Severity count: 1 P2, 1 P3, 1 Nit, 2 Notes. Netero's first pass was clean. Kite on the test quality: "asserts the negative case with real teeth ... This is the test truthfulness bar other PRs should hit." The P2 should be closed before merge, and the fix and structural note (CRF-2) point at the same root: the CORS decision and the router must read the same normalized path.
🤖 This review was automatically generated with Coder Agents.
…path The router collapses repeated slashes before matching, so a request to /oauth2//authorize reaches the authorize handler while the CORS middleware saw a path that did not match the exclusion and applied the permissive policy. Normalize the path before choosing a policy.
dylanhuff-at-coder
left a comment
There was a problem hiding this comment.
lgtm, thanks for covering the repeated-slash case.
TL;DR
The permissive OAuth2 CORS policy matched every path under
/oauth2/, so/oauth2/authorizeanswered any origin with a wildcard. OAuth 2.1 §3.1 says the authorization endpoint must not support CORS: the client redirects the user there and never fetches it. Low practical exposure since credentials were already disallowed, but a conformance failure./oauth2/authorize, with or without a trailing slash, now gets the standard CORS policy like the rest of the site. NoAccess-Control-*header for any origin, on GET, POST, or a preflight./oauth2//authorizereached the authorize handler while the raw path skipped the exclusion. Normalizing in the middleware rather than reading chi's route path keeps the check correct in wsproxy too, which mounts the same middleware without the slash-collapsing one..well-knowndocuments, and MCP keep the permissive policy. OAuth 2.1 §3.2 says browser-based clients need CORS on those.Consent page behavior is unchanged. It is a same-origin form and never needed CORS.
Refs #18920
Closes https://linear.app/codercom/issue/PLAT-601
🤖 Generated with Claude Code