Skip to content

fix(coderd/httpmw): anchor CSRF exemption patterns (#31125) - #31433

Merged
denisra merged 2 commits into
release/2.34from
backport/31125-to-2.34
Nov 3, 2026
Merged

denisra merged 2 commits into
release/2.34from
backport/31125-to-2.34

Conversation

@coder-backporter-app

Copy link
Copy Markdown

Backport of #31125

Original PR: #31125 — fix(coderd/httpmw): anchor CSRF exemption patterns
Merge commit: 0fd0775
Requested by: @BobbyHo

Warning

The automatic cherry-pick had conflicts.
Please resolve manually by cherry-picking the original merge commit:

git fetch origin backport/31125-to-2.34
git checkout backport/31125-to-2.34
git reset --hard origin/release/2.34
git cherry-pick -x -m1 0fd07754f509544df6f8e9e1c12e0e64c68557af
# resolve conflicts, then push

@coder-backporter-app coder-backporter-app Bot added the backport/v2.34 Backport PR targeting release/2.34 label Oct 28, 2026
@github-actions github-actions Bot added the community Pull Requests and issues created by the community. label Oct 28, 2026
fix(httpmw): restrict CSRF exemptions to intended routes

CSRF exemptions used shell-style patterns evaluated as unanchored regexes,
allowing unintended cookie-authenticated routes to bypass protection.
This enabled CSRF against role-management routes containing `derp` and
dev container recreate/delete endpoints.

- Anchor exemptions to their intended routes or subtrees.
- Remove the broad workspace-agent exemption, duplicate first-user entry,
  and obsolete `/api/v2/scim` pattern.
- Preserve intended exemptions and requests without session cookies,
  keeping agents, proxies, provisioners, and SCIM providers unaffected.
- Add regression tests for unintended matches, legitimate exemptions,
  requests without session cookies, and rejection of a cross-origin
  request to a formerly exempt route.

Validation: `go test ./coderd/httpmw/ -count=1`, `go vet`, and
`golangci-lint run ./coderd/httpmw/...` pass.

Backports: Omit the doubled-leading-slash test on branches without #29798.

Refs [PLAT-733](https://linear.app/codercom/issue/PLAT-733)

(cherry picked from commit 0fd0775)
@BobbyHo
BobbyHo force-pushed the backport/31125-to-2.34 branch from b7e44c7 to 07c3d2c Compare October 31, 2026 18:23
@BobbyHo BobbyHo changed the title fix(coderd/httpmw): anchor CSRF exemption patterns (#31125) (conflicts) fix(coderd/httpmw): anchor CSRF exemption patterns (#31125) Oct 31, 2026
@denisra
denisra merged commit 524d0f5 into release/2.34 Nov 3, 2026
27 checks passed
@denisra
denisra deleted the backport/31125-to-2.34 branch November 3, 2026 10:24
@github-actions github-actions Bot locked and limited conversation to collaborators Nov 3, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

backport/v2.34 Backport PR targeting release/2.34 community Pull Requests and issues created by the community.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants