Fix token validation to prevent cross-provider enumeration #3
+190
−2
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.
Fix OAuth client enumeration bug in oidc-auth-lib
Problem Statement
When multiple OAuth providers are configured via
AUTH_PROVIDERS, there was an enumeration bug where tokens from one provider could be incorrectly validated when intended for another. This was caused by swapping the order of AUTH_PROVIDERS fixing the issue temporarily (workaround in mcp-fhir-agent PR #68).Root Cause Analysis
Two critical issues were identified:
Missing issuer/audience validation: After JWT signature verification, the code never validated that the token's issuer/audience matched any configured auth provider. This meant ANY validly-signed token would be accepted regardless of which provider it came from.
Duplicate key ID handling: When multiple providers use the same key ID (kid), only the first provider's key was kept, potentially causing signature verification failures.
Solution Implemented
Modified
oidcauthlib/auth/token_reader.py:Added issuer/audience validation (lines 241-268):
AuthorizationBearerTokenInvalidExceptionwith clear message when validation failsAdded duplicate key ID warning (lines 125-130):
Fixed exception handling (lines 315-317):
AuthorizationBearerTokenInvalidExceptionto re-raise without wrappingStrip whitespace from AUTH_PROVIDERS (
environment_variables.py:45):Changes Made
verify_token_async()Testing
test_token_validation_rejects_wrong_issuer_and_audience- Passes ✅Security Summary
No new security vulnerabilities introduced. The fix actually improves security by preventing tokens from one OAuth provider being accepted when intended for another provider.
Original prompt
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.