Skip to content

fix(coderd): harden oauth2 redirect validation (#27274)#27464

Open
aslilac wants to merge 1 commit into
release/2.35from
backport/27274-to-2.35
Open

fix(coderd): harden oauth2 redirect validation (#27274)#27464
aslilac wants to merge 1 commit into
release/2.35from
backport/27274-to-2.35

Conversation

@aslilac

@aslilac aslilac commented Jul 23, 2026

Copy link
Copy Markdown
Member

Backport of #27274

Original PR: #27274 — fix(coderd): harden oauth2 redirect validation
Merge commit: 2f87991
Requested by: @aslilac

Closes DEVEX-604

Hardens `redirect` URL handling in the OAuth2/OIDC/external-auth
callback flows so redirects are always reduced to a safe, relative path
local to the application. Previously a redirect value with an opaque
scheme (e.g. `javascript:...`) or a path with multiple leading slashes
(e.g. `///evil.com`) could survive sanitization mostly intact.

Also de-duplicates the previously copy-pasted `uriFromURL` helper (now
exported `httpmw.URIFromURL`) so there's a single implementation shared
by `coderd/userauth.go`, `coderd/externalauth.go`, and
`coderd/httpmw/oauth2.go`.

<details>
<summary>Context</summary>

Addresses a low-severity finding reported via a pentest disclosure: the
redirect sanitizer used `url.Parse(...).RequestURI()`, which doesn't
reject non-hierarchical (opaque) URLs and doesn't collapse extra leading
slashes, so crafted `redirect` values could partially survive
sanitization.

</details>

This PR was authored by a Coder Agent on behalf of @aslilac.

(cherry picked from commit 2f87991)
@aslilac
aslilac force-pushed the backport/27274-to-2.35 branch from bd34624 to 17a3b2b Compare July 23, 2026 18:21
@aslilac
aslilac changed the base branch from main to release/2.35 July 23, 2026 18:21
@aslilac aslilac added the cherry-pick/v2.35 Cherry-pick PR targeting release/2.35 label Jul 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cherry-pick/v2.35 Cherry-pick PR targeting release/2.35

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants