Skip to content

fix(auth): strip trailing slash in OAuth2 discovery paths - #8478

Open
1828703450qqcom-ux wants to merge 1 commit into
google:mainfrom
1828703450qqcom-ux:fix/oauth2-discovery-trailing-slash
Open

1828703450qqcom-ux wants to merge 1 commit into
google:mainfrom
1828703450qqcom-ux:fix/oauth2-discovery-trailing-slash

Conversation

@1828703450qqcom-ux

Copy link
Copy Markdown
Contributor

Link to Issue or Description of Change

Problem:
In src/google/adk/auth/oauth2_discovery.py:

  1. discover_auth_server_metadata and discover_resource_metadata only ignored path == "/", leaving trailing slashes on path-prefixed URLs (e.g. https://auth.example.com/oauth/ or https://resource.example.com/tenant1/) intact. This violates RFC 8414 Section 3.1 and RFC 9728 Section 3.1 (which require stripping any terminating / before inserting /.well-known/...) and produced a double slash in the path-appended OpenID Connect discovery URL (https://auth.example.com/oauth//.well-known/openid-configuration).
  2. discover_resource_metadata compared metadata.resource against resource_url.rstrip("/") without calling .rstrip("/") on metadata.resource (unlike discover_auth_server_metadata at line 137 which calls metadata.issuer.rstrip("/")), rejecting valid servers that return a trailing slash in resource.

Solution:

  • Normalize path = parsed_url.path.rstrip("/") in both discover_auth_server_metadata and discover_resource_metadata and check if path:.
  • Normalize metadata.resource.rstrip("/") during MIX-UP validation in discover_resource_metadata.
  • Add unit tests in tests/unittests/auth/test_oauth2_discovery.py covering path-prefixed trailing-slash discovery URLs and trailing-slash metadata.resource responses.

Testing Plan

Unit Tests:

  • pytest tests/unittests/auth/test_oauth2_discovery.py -q (18 passed)

Checklist

  • I have read the CONTRIBUTING.md document.
  • I have performed a self-review of my own code.
  • New and existing unit tests pass locally with my changes.

Note: Prepared with AI assistance; reviewed and verified locally.

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