feat: support dynamic port matching for localhost redirect URIs#874
Open
roncodingenthusiast wants to merge 1 commit intoory:masterfrom
Open
feat: support dynamic port matching for localhost redirect URIs#874roncodingenthusiast wants to merge 1 commit intoory:masterfrom
roncodingenthusiast wants to merge 1 commit intoory:masterfrom
Conversation
Add localhost handling to isLoopbackAddress so that native OAuth 2.0 clients registering http://localhost/callback can use dynamic ports (e.g. http://localhost:54321/callback) per RFC 8252 Section 7.3. Previously, isLoopbackAddress only used net.ParseIP which returns nil for the hostname "localhost", preventing port-flexible loopback matching. The existing hostname equality check in isMatchingAsLoopback prevents cross-matching between localhost and IP literals. Closes ory#873 Made-with: Cursor
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.
Add
localhosthandling toisLoopbackAddressso that native OAuth 2.0 clients registeringhttp://localhost/callbackcan use dynamic ports (e.g.http://localhost:54321/callback) for loopback redirect URIs.Previously,
isLoopbackAddressonly usednet.ParseIPwhich returnsnilfor the hostname"localhost", preventing port-flexible loopback matching. The existing hostname equality check inisMatchingAsLoopbackprevents cross-matching betweenlocalhostand IP literals.Related Issue or Design Document
#873
Checklist
If this pull request addresses a security vulnerability,
I confirm that I got approval (please contact security@ory.sh) from the maintainers to push the changes.
Further comments
RFC 8252 §7.3 strictly defines loopback redirect URIs using IP literals only, and §8.3 says
localhostis NOT RECOMMENDED. However, Fosite already acceptslocalhostas a valid loopback host for transport security purposes viaIsLocalhost. This one-line change alignsisLoopbackAddress(used for port matching) with that existing decision, unblocking real-world MCP/OAuth clients that registerhttp://localhost/callbackby convention.Test cases added:
http://localhost:9999/callbackmatches registeredhttp://localhost/callback(dynamic port)http://localhost/callbackmatches itself (exact match)http://localhost:9999/callbackdoes NOT match registeredhttp://127.0.0.1/callback(hostname mismatch)http://127.0.0.1:9999/callbackdoes NOT match registeredhttp://localhost/callback(hostname mismatch)