Skip to content

fix(coderd/httpmw): normalize repeated slashes before CSRF exemption check - #29798

Merged
BobbyHo merged 2 commits into
mainfrom
bobby/plat-672-csrf-exemption-bypass-via-path-respelling
Sep 23, 2026
Merged

BobbyHo merged 2 commits into
mainfrom
bobby/plat-672-csrf-exemption-bypass-via-path-respelling

Conversation

@BobbyHo

@BobbyHo BobbyHo commented Sep 23, 2026

Copy link
Copy Markdown
Collaborator

The CSRF middleware decides whether to protect a request based on the raw URL path, but the router collapses repeated slashes before matching. A path like /oauth2//authorize or //api/v2/... reaches the real handler while skipping CSRF checks.

  • Normalize the path before the exemption check, the same way cors.go already does.
  • Add test cases for respelled /api and /oauth2/authorize paths.

Fixes https://linear.app/codercom/issue/PLAT-672/csrf-exemption-bypass-via-path-respelling-post-oauth2authorize-forges

…check

The router collapses repeated slashes before matching routes, but the
CSRF exemption check used the raw request path. A respelled path such
as "/oauth2//authorize" or "//api/v2/..." reached the real handler
while skipping CSRF verification.

Normalize the path the same way the CORS middleware already does so
CSRF, CORS, and routing all agree on which route a request targets.

Fixes PLAT-672
@linear-code

linear-code Bot commented Sep 23, 2026

Copy link
Copy Markdown

PLAT-672

@BobbyHo
BobbyHo marked this pull request as ready for review September 23, 2026 19:00

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

Nice fix, lgtm

@BobbyHo
BobbyHo merged commit 6372f67 into main Sep 23, 2026
30 of 33 checks passed
@BobbyHo
BobbyHo deleted the bobby/plat-672-csrf-exemption-bypass-via-path-respelling branch September 23, 2026 19:50
@github-actions github-actions Bot locked and limited conversation to collaborators Sep 23, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants