Fix/validate redirect uri#502
Merged
Merged
Conversation
…irect token theft Six endpoints accepted user-controlled redirect_uri without validating against AllowedOrigins, allowing attackers to steal tokens by redirecting to malicious URLs. Added validators.IsValidOrigin() checks to: - ForgotPassword (GraphQL mutation) - MagicLinkLogin (GraphQL mutation) - SignUp (GraphQL mutation) - InviteMembers (GraphQL mutation) - OAuthLoginHandler (HTTP handler) - VerifyEmailHandler (HTTP handler, both query param and JWT claim fallback)
Tests verify that ForgotPassword, MagicLinkLogin, SignUp, and InviteMembers reject attacker-controlled redirect_uri values not matching AllowedOrigins, and accept valid ones.
… format IsValidOrigin compares hostname:port (without protocol), so AllowedOrigins must be specified without the http:// prefix. Also use SQLite to allow tests to run without Docker/Postgres.
…ctly The previous implementation compared allowed origins (e.g. "https://example.com") as raw regex against "hostname:port", so protocols in AllowedOrigins caused matches to always fail. Now both input URL and allowed origins are normalized via net/url.Parse to strip protocol/path before comparison. Also anchors the regex with ^...$ to prevent partial matches (e.g. "example.com" matching "notexample.com"). Adds comprehensive unit tests covering: exact domains, custom ports, standard ports (80/443), bare domains without protocol, subdomains, deep subdomains, wildcard subdomains, wildcard with port, multiple origins, attacker URLs, www variants, and live domain scenarios.
The test was using "https://authorizer.dev/" which is not in AllowedOrigins, so it now correctly gets rejected by the new redirect_uri validation. Updated to use "http://localhost:3000/" which matches the test config's AllowedOrigins.
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.
What does this PR do?
Resolves: GHSA-x3f4-v83f-7wp2
Which issue(s) does this PR fix?
If this PR affects any API reference documentation, please share the updated endpoint references