Repository navigation
security(validators): pin a bare wildcard in a mixed origin list - #853
Merged
Merged
Conversation
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.
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
*beside explicit entries inallowed_originsnever 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 readshttp://3405803783as203.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: addIsWildcardOrigin, the single definition of "this entry means any host", and decide on the NORMALISED value.*," *",https://*,http://*,*/,*:80and*:443are 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 onnormalizeOrigin, 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*:3000are 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 ashttp://localhost:3000and in-cluster names such ashttp://frontend:3000are unaffected, because an entry with no*is compared as a literal.internal/http_handlers/csrf.go,cmd/root.go: routeisWildcardOriginsand 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 withAccess-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.