Validate redirect URIs at OAuth registration and authorize#57
Merged
Conversation
Contributor
There was a problem hiding this comment.
Code Review
This pull request implements a redirect-URI host allowlist policy for OAuth client registration and authorization to prevent open redirect vulnerabilities. It introduces new configuration options, allowedRedirectUriHosts and allowAnyRedirectUriHost, along with structural validation checks and comprehensive tests. Feedback focuses on ensuring the file: scheme is explicitly blocked across configuration loading, static validation, and runtime checks to align with the documentation. Additionally, there is a recommendation to refine the port matching logic to handle default ports more flexibly, ensuring that explicit ports in the allowlist correctly match URIs where the port is omitted but implied.
Open dynamic client registration accepted any redirect_uri value without validation. An attacker could register a client whose redirect URI pointed at their own host and then, via phishing, walk a victim through the OAuth flow to receive that victim's authorization code at the attacker's host. Adds an allowedRedirectUriHosts allowlist enforced at /register and re-checked at /authorize. Required in non-dev; set allowAnyRedirectUriHost to opt out for development. Also moves redirect_uri validation up front in /authorize so failures there return a direct 400 instead of 302'ing to the raw query value, per RFC 6749 §3.1.2.4. The standard OAuth error channel (302 to a registered URI with ?error=...) is preserved for other validation failures.
4b2419a to
4910248
Compare
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.
Open dynamic client registration accepted any
redirect_urivalue without validation. An attacker could register a client whose redirect URI pointed at their own host, then use the auth flow to collect a victim's authorization code at that host. Adds anallowedRedirectUriHostsallowlist enforced at/registerand re-checked at/authorize. Required in non-dev. SetallowAnyRedirectUriHostto opt out for development.Also moves
redirect_urivalidation up front in/authorizeso failures there return a direct 400 instead of 302'ing to the raw query value, per RFC 6749 §3.1.2.4. The standard OAuth error channel (302 to a registered URI with ?error=...) is preserved for other validation failures.