fix(security): enable JWT audience validation and declare MCP resource path#123
Merged
epugh merged 1 commit intoMay 8, 2026
Merged
Conversation
…e path
Per the MCP Authorization specification, MCP servers MUST validate that
tokens were specifically issued for them — otherwise any valid JWT from
the same IdP for any sibling application is accepted, enabling
token-confusion pivots (CWE-345).
Wires the existing McpServerOAuth2Configurer with:
- resourcePath("/mcp") — declares the canonical resource indicator
surfaced via OAuth 2.0 Protected Resource Metadata (RFC 9728), which
MCP clients use to discover the authorization server.
- validateAudienceClaim(true) — enforces that the JWT "aud" claim
matches that resource indicator (RFC 8707).
Operators must configure their IdP to populate "aud" with the MCP
server's URL. The application-http.properties comment block documents
the required setup for Auth0, Okta, and Keycloak (which does not yet
honor RFC 8707 `resource=` natively and needs an Audience protocol
mapper on a client scope).
Refs:
- MCP Authorization spec, "Token Audience Binding and Validation":
https://modelcontextprotocol.io/specification/2025-06-18/basic/authorization
- RFC 8707 (Resource Indicators):
https://www.rfc-editor.org/rfc/rfc8707.html
- RFC 9728 (Protected Resource Metadata):
https://www.rfc-editor.org/rfc/rfc9728.html
- Keycloak MCP integration docs (Audience mapper workaround):
https://www.keycloak.org/securing-apps/mcp-authz-server
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Signed-off-by: adityamparikh <aditya.m.parikh@gmail.com>
This was referenced May 2, 2026
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.
Summary
Per the MCP Authorization specification:
Without audience validation, any valid JWT from the same IdP issued for any sibling application is accepted by this server — a classic token-confusion pivot (CWE-345).
This PR wires the existing `McpServerOAuth2Configurer` with:
These options are already provided by the upstream `spring-ai-community/mcp-server-security` library; this PR just turns them on.
Operator impact
When `http.security.enabled=true`, the IdP must populate the JWT `aud` claim with the MCP server's URL. The expanded comment block in `application-http.properties` documents the per-IdP setup:
`http.security.enabled=false` (current default) is unaffected.
Test plan
Note on PR ordering
Touches `HttpSecurityConfiguration.java` and `application-http.properties`, which overlap with PR #121 (CORS allowlist). Whichever lands second will need a small rebase.
🤖 Generated with Claude Code