fix(webui): open redirect in dashboard token-exchange handler #947

Closed
opened 2026-10-27 13:38:24 +00:00 by sam · 0 comments
Owner

CodeQL alert (go/unvalidated-url-redirection, medium severity): the dashboard token-exchange handler in internal/webui/auth.go redirected to a Location built directly from the incoming request's path and query, with no validation.

A request whose path starts with // (e.g. GET //evil.example/x?t=<token>) causes clean.RequestURI() to reproduce //evil.example/x verbatim. Browsers treat a Location header starting with // as protocol-relative, so this redirects the client off-host after a legitimate token exchange -- a classic open-redirect via the Go net/url double-slash gotcha.

Fix

Added sameOriginPath() in internal/webui/auth.go, which collapses any leading // down to a single / before the value ever reaches http.Redirect. Covered by a red-then-green test in internal/webui/auth_test.go (TestRequireToken_RedirectRejectsProtocolRelativePath) that reproduces the exploit path and asserts the Location header is never protocol-relative.

Ref: code-scanning alert #4 (dismissed alerts #1-3 on that same scan were false positives -- allocations already bounded by min(), see their dismissal comments).


Imported from beads archie-core-1786637500871-419-5bee4d20 · GitHub #440 · type bug · priority P2 · created 2026-08-08 · closed 2026-08-08

CodeQL alert (`go/unvalidated-url-redirection`, medium severity): the dashboard token-exchange handler in `internal/webui/auth.go` redirected to a Location built directly from the incoming request's path and query, with no validation. A request whose path starts with `//` (e.g. `GET //evil.example/x?t=<token>`) causes `clean.RequestURI()` to reproduce `//evil.example/x` verbatim. Browsers treat a Location header starting with `//` as protocol-relative, so this redirects the client off-host after a legitimate token exchange -- a classic open-redirect via the Go `net/url` double-slash gotcha. ### Fix Added `sameOriginPath()` in `internal/webui/auth.go`, which collapses any leading `//` down to a single `/` before the value ever reaches `http.Redirect`. Covered by a red-then-green test in `internal/webui/auth_test.go` (`TestRequireToken_RedirectRejectsProtocolRelativePath`) that reproduces the exploit path and asserts the Location header is never protocol-relative. Ref: [code-scanning alert #4](https://github.com/samcharles93/archie-core/security/code-scanning/4) (dismissed alerts #1-3 on that same scan were false positives -- allocations already bounded by `min()`, see their dismissal comments). --- _Imported from beads `archie-core-1786637500871-419-5bee4d20` · GitHub #440 · type bug · priority P2 · created 2026-08-08 · closed 2026-08-08_
sam added the mediumbug labels 2026-10-27 13:38:24 +00:00
sam self-assigned this 2026-10-27 13:38:24 +00:00
sam closed this issue 2026-10-27 13:38:24 +00:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: sam/archie#947