Skip to content

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

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

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

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

@ibetitsmike

Copy link
Copy Markdown
Collaborator

PR might need a rebase I guess

@aslilac
aslilac changed the base branch from main to release/2.34 July 23, 2026 18:19
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.34 branch from e5b9457 to 8c2f0c9 Compare July 23, 2026 18:23
@aslilac aslilac added the cherry-pick/v2.34 Cherry-pick PR targeting release/2.34 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.34 Cherry-pick PR targeting release/2.34

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants