fix: validate PRM resource field per RFC 9728 Section 3.3 #1597
+62
−5
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.
Motivation and Context
Resolves #1581
Adds RFC 9728 Section 3.3 validation to prevent metadata impersonation attacks during PRM discovery. Uses pre-existing
check_resource_allowed()to validate origin and path hierarchy before storing metadata. Invalid metadata triggers SEP-985 fallback (already implemented).How Has This Been Tested?
Created the following tests:
test_reject_metadata_with_mismatched_origin- validates rejection of wrong scheme/host/porttest_reject_metadata_with_invalid_path_hierarchy- validates path parent/child relationshipsUpdated:
Existing test test_auth_flow_with_no_tokensupdated to use valid resource fieldRan all tests in
tests/client/test_auth.pyto ensure they all pass.Tested manually as well using
examples/clients/simple-auth-client/mcp_simple_auth_clientandexamples/servers/simple-auth/mcp_simple_authBreaking Changes
None.
Types of changes
Checklist
Additional context