Skip to content

Fix/validate redirect uri#502

Merged
lakhansamani merged 5 commits into
mainfrom
fix/validate-redirect-uri
Mar 29, 2026
Merged

Fix/validate redirect uri#502
lakhansamani merged 5 commits into
mainfrom
fix/validate-redirect-uri

Conversation

@lakhansamani
Copy link
Copy Markdown
Contributor

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

…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.
@lakhansamani lakhansamani merged commit 6d9bef1 into main Mar 29, 2026
@lakhansamani lakhansamani deleted the fix/validate-redirect-uri branch March 29, 2026 08:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

1 participant