Skip to content

fix: remove CORS from the OAuth2 authorization endpoint - #29143

Merged
BobbyHo merged 6 commits into
mainfrom
coder-plat-601-remove-cors-oauth
Sep 10, 2026
Merged

BobbyHo merged 6 commits into
mainfrom
coder-plat-601-remove-cors-oauth

Conversation

@BobbyHo

@BobbyHo BobbyHo commented Sep 9, 2026 •

Copy link
Copy Markdown
Collaborator

TL;DR

The permissive OAuth2 CORS policy matched every path under /oauth2/, so /oauth2/authorize answered 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. No Access-Control-* header for any origin, on GET, POST, or a preflight.
  • The middleware collapses repeated slashes before choosing a policy. The router already does this when matching, so a request to /oauth2//authorize reached 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.
  • Tokens, revoke, register, clients, both .well-known documents, and MCP keep the permissive policy. OAuth 2.1 §3.2 says browser-based clients need CORS on those.
  • Adds the first tests for this middleware: a matrix over both policies including repeated-slash paths, and a router test that the middleware still sits in front of the OAuth2 routes and excludes the authorize endpoint for both spellings.
  • One bullet in the provider docs' security notes.

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

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.
@linear-code

linear-code Bot commented Sep 9, 2026

Copy link
Copy Markdown

PLAT-601

@github-actions

github-actions Bot commented Sep 9, 2026 •

Copy link
Copy Markdown
Contributor

Docs preview

Check 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.

@BobbyHo

BobbyHo commented Sep 9, 2026

Copy link
Copy Markdown
Collaborator Author

/coder-agents-review

@coder-agents-review

coder-agents-review Bot commented Sep 9, 2026 •

Copy link
Copy Markdown
Contributor

Chat: Review in progress (16/16 reviewers complete) | View chat
Requested: 2026-09-09 18:03 UTC by @BobbyHo

deep-review v0.9.0 | Round 1 | 74d1eef..b0c4fa7

Last posted: Round 1, 5 findings (1 P2, 1 P3, 1 Nit, 2 Note), COMMENT. Review

Finding inventory

Finding inventory: PR #29143

Findings

# Sev Status Location Summary Round Reviewer Posted
CRF-1 P2 Open coderd/httpmw/cors.go:82 /oauth2//authorize bypasses the authorize exclusion and still gets permissive CORS R1 Meruem P2, Razor P2, Knov P3 Yes
CRF-2 P3 Open coderd/httpmw/cors.go:82 CORS policy keyed on path-prefix string match in central middleware, not route-scoped; each exception is a hand-added hole R1 Ryosuke P3, Pariston Note Yes
CRF-3 Nit Open coderd/httpmw/cors.go:85 Comment "permissive CORS for OAuth2, MCP, and well-known" no longer matches the branch (authorize excluded) R1 Gon Yes
CRF-4 Note Open docs/admin/integrations/oauth2-provider.md:577 Docs state authorize "sends no CORS headers" as absolute, but the dangerous allow-all override re-enables * R1 Mafuuu, Leorio Yes
CRF-5 Note Open coderd/oauth2_test.go:2249 Authorize router subtest asserts absence; a missing middleware would also pass it. The Tokens subtest carries the wiring proof R1 Bisky, Ryosuke Yes
CRF-6 Note Dropped by orchestrator (trivial, no action change) coderd/httpmw/cors_test.go:159 86400 literal duplicated without the "24 hours" gloss R1 Gon No
CRF-7 Note Dropped by orchestrator (trivial, no action change) coderd/httpmw/cors_test.go:141 send doc first sentence restates the signature R1 Gon No

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 singleSlashMW normalizes r.URL.Path, so no bypass. Ground truth (coderd.go:2653): when rctx != nil, it normalizes rctx.RoutePath and leaves r.URL.Path untouched. Orchestrator reproduced end-to-end against a real coderdtest server: OPTIONS /oauth2//authorize returns Access-Control-Allow-Origin: * while routing to the authorize handler; /oauth2/authorize returns none. Empirical result wins; the P2 holds.

Round log

Round 1

Panel (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-review

CRF = Coder Review Finding (P0-P4, Nit, Note)

Reviewer Focus
Bisky tests
Chopper ops/errors
Churn-guard change verification
Ging language modernization
Gon naming
Hisoka edge cases
Killua perf
Kite change integrity
Knov contracts
Knuckle SQL
Komugi flake/determinism
Kurapika security
Law decomposition
Leorio docs
Luffy product
Mafu-san process
Mafuuu contracts
Melody dispatch/pairing
Meruem structural
Nami frontend
Netero mechanical checks
Pariston premise testing
Pen-botter product gaps
Razor verification
Robin duplication
Ryosuke Go arch
Takumi concurrency
Zoro shape

🤖 Managed by Coder Agents.

@coder-agents-review coder-agents-review Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread coderd/httpmw/cors.go Resolved
Comment thread coderd/httpmw/cors.go Resolved
Comment thread coderd/httpmw/cors.go Resolved
Comment thread coderd/oauth2_test.go Resolved
…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 dylanhuff-at-coder left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm, thanks for covering the repeated-slash case.

@BobbyHo
BobbyHo merged commit 42fcd33 into main Sep 10, 2026
31 checks passed
@BobbyHo
BobbyHo deleted the coder-plat-601-remove-cors-oauth branch September 10, 2026 17:49
@github-actions github-actions Bot locked and limited conversation to collaborators Sep 10, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants