Skip to content

security(validators): pin a bare wildcard in a mixed origin list - #853

Merged
lakhansamani merged 2 commits into
mainfrom
security/bare-wildcard-origin
Nov 8, 2026
Merged

lakhansamani merged 2 commits into
mainfrom
security/bare-wildcard-origin

Conversation

@lakhansamani

Copy link
Copy Markdown
Contributor
  • Fixes GHSA-f9fw-76m6-wc75. A bare * beside explicit entries in allowed_origins never hit the one-element wildcard special case, so it reached the matcher and was rewritten as the regex [^.]*. That matches every DOTLESS host, and a browser reads http://3405803783 as 203.0.113.7, so an attacker writing their address as a single decimal number received OAuth codes, ID tokens and password-reset tokens from /authorize.
  • internal/validators/url.go: add IsWildcardOrigin, the single definition of "this entry means any host", and decide on the NORMALISED value. *, " *", https://*, http://*, */, *:80 and *:443 are all spellings of the same entry, and a guard that compared the raw string let every one but the first reach the regex. Risk to check: the predicate now depends on normalizeOrigin, so a change there changes what counts as a wildcard.
  • internal/validators/url.go: refuse a wildcard with no literal dot to anchor it. ** and *:3000 are not spellings of *, but they splice to [^.]*[^.]* and [^.]*:3000, which match a dotless host just the same. Breaking change: a wildcard entry that relied on matching a dotless host is now denied — list the host explicitly, which already works. Explicit dotless entries such as http://localhost:3000 and in-cluster names such as http://frontend:3000 are unaffected, because an entry with no * is compared as a literal.
  • internal/http_handlers/csrf.go, cmd/root.go: route isWildcardOrigins and the startup warning through the same predicate. pflag does not trim the elements of a comma-separated flag, so --allowed-origins "https://app.acme.com, *" yields " *"; the three sites disagreed about it, and CORS took the explicit-allowlist branch and reflected ANY caller's Origin back with Access-Control-Allow-Credentials: true. Both CSRF layers fell with it.
  • internal/validators/url.go: a * entry keeps its two deliberately different meanings — allow-all for CORS, the server's own hostname only for redirects — and is now applied per entry rather than only to a one-element list.

A "*" beside explicit origins reached originMatches, which re-opened it as
[^.]*, so every dotless host passed and the server's own origin did not.
The first fix guarded the raw config string while originMatches spliced the
normalized one, so "https://*", "*:443" and "*/" still became [^.]* and matched
any dotless host. One shared predicate now answers the question everywhere.
@lakhansamani
lakhansamani merged commit 0ef997c into main Nov 8, 2026
3 of 4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant