Files
coder/coderd/httpmw
Bobby Ho 0fd07754f5 fix(coderd/httpmw): anchor CSRF exemption patterns (#31125)
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)
2026-10-28 11:16:55 -07:00
..
…
…
…