fix: prevent open redirect from whitelist subdomain suffix bypass - #6
Open
hacktron-app-stg[bot] wants to merge 1 commit into
Open
fix: prevent open redirect from whitelist subdomain suffix bypass#6hacktron-app-stg[bot] wants to merge 1 commit into
hacktron-app-stg[bot] wants to merge 1 commit into
Conversation
IsValidRedirect matched any hostname ending in the bare whitelisted
domain when the domain was configured with a leading dot, so
badexample.com bypassed a .example.com whitelist. Require the matched
suffix to be preceded by a dot (".example.com") so only real subdomains
are accepted; exact-domain matches remain handled separately.
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.
Vulnerability
IsValidRedirectinoauthproxy.govalidates redirect targets againstwhitelistDomains. For a domain configured to allow subdomains via a leading dot (e.g..example.com), the leading dot was trimmed intodomainHostname(splitHostPort(strings.TrimLeft(domain, "."))) and the subdomain check used:Because
domainHostnameis the bareexample.com, any hostname merely ending in that string matched — e.g.badexample.comis a suffix ofexample.com. An attacker could therefore pass?rd=http://badexample.comand pass validation, yielding an open redirect.Fix
Match the suffix against
"." + domainHostnameso only true subdomains (where the whitelisted domain is preceded by a dot) are accepted:Exact-domain redirects continue to be accepted through the unchanged
redirectHostname == domainHostnamebranch, and legitimate subdomains likebaz.bar.foostill end with.bar.foo. This mirrors the correct upstream behavior.Verification
TestIsValidRedirectagainst the new condition: exact-domain (bar.foo), subdomain (baz.bar.foo), and port variants all still evaluate as before; the new suffix restriction only rejects the bypass class (evilbar.foono longer matches.bar.foo).invalidHTTPSubdomainSuffixBypass(http://evilbar.foo/redirect→ expectedfalse).go testcould not be executed; verification was done by static tracing and diff review.Automated fix by Hacktron for finding: https://staging.hacktron.ai/i-need-an-org/findings/45d3a08d-d7e5-4b45-985b-b12f7ff7dbb8