Skip to content

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

Open
github-actions[bot] wants to merge 1 commit into
release/2.33from
backport/27274-to-2.33
Open

fix(coderd): harden oauth2 redirect validation (#27274)#27462
github-actions[bot] wants to merge 1 commit into
release/2.33from
backport/27274-to-2.33

Conversation

@github-actions

@github-actions github-actions Bot commented Jul 23, 2026

Copy link
Copy Markdown

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.33 branch from 94da85c to 20cf53a Compare July 23, 2026 18:03
@aslilac aslilac changed the title fix(coderd): harden oauth2 redirect validation (#27274) (conflicts) fix(coderd): harden oauth2 redirect validation (#27274) Jul 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant