Skip to content

Allow any port for loopback redirect URIs (RFC 8252 §7.3)#3

Merged
wille merged 1 commit into
masterfrom
rfc8252-loopback-redirect-uri
Jul 6, 2026
Merged

Allow any port for loopback redirect URIs (RFC 8252 §7.3)#3
wille merged 1 commit into
masterfrom
rfc8252-loopback-redirect-uri

Conversation

@wille

@wille wille commented Jul 6, 2026

Copy link
Copy Markdown
Owner

Summary

Ports modelcontextprotocol/typescript-sdk#1738 (shipped upstream in v1.29.0), which this package predates since the auth server code was forked at ~1.24.0.

Per RFC 8252 §7.3 (OAuth 2.0 for Native Apps), authorization servers MUST allow any port for loopback redirect URIs, because native clients bind an ephemeral OS-assigned port at runtime. Previously redirect_uri validation required an exact string match against the registered URIs, so such clients were rejected with Unregistered redirect_uri.

Changes

  • New redirectUriMatches(requested, registered) helper (exported, mirroring upstream): ignores the port when both URIs target the same loopback host (localhost, 127.0.0.1, [::1]). Scheme, hostname, path, and query must still match exactly — no localhost127.0.0.1 cross-matching, per the RFC.
  • Applied at all three validation sites: authorizationHandler, authenticateHandler, and OAuthServer.authenticate().
  • The token-endpoint redirect_uri comparison intentionally remains an exact match (it must equal the value used in the authorization request).

Tests

  • New redirect-uri.test.ts unit suite covering port relaxation, hostname/scheme/path/query strictness, and unparseable URIs.
  • Loopback cases added to the authorize-handler and authorization-flow suites.

Port of modelcontextprotocol/typescript-sdk#1738: redirect_uri
validation now ignores the port when both the requested and registered
URIs target the same loopback host (localhost, 127.0.0.1, [::1]), so
native clients that bind an ephemeral OS-assigned port can authorize.
Scheme, hostname, path, and query must still match exactly.
@wille wille self-assigned this Jul 6, 2026
@wille
wille merged commit e61f1a0 into master Jul 6, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant