Skip to content

fix(security): require authentication for metadata MCP tools#120

Merged
epugh merged 1 commit into
apache:mainfrom
adityamparikh:fix/security-preauthorize-metadata-tools
May 8, 2026
Merged

fix(security): require authentication for metadata MCP tools#120
epugh merged 1 commit into
apache:mainfrom
adityamparikh:fix/security-preauthorize-metadata-tools

Conversation

@adityamparikh
Copy link
Copy Markdown
Contributor

Summary

Adds @PreAuthorize(\"isAuthenticated()\") to four MCP tools that previously allowed anonymous access in HTTP mode (when security is enabled):

  • CollectionService.listCollections
  • CollectionService.getCollectionStats
  • CollectionService.checkHealth
  • SchemaService.getSchema

These expose collection inventory, document counts, cache/handler stats, health, and schema fields — useful reconnaissance for an attacker probing the underlying Solr cluster. They were reachable anonymously because the SecurityFilterChain permits /mcp at the HTTP layer (matching the upstream spring-ai-community/mcp-security "secured tools" sample, which relies entirely on @PreAuthorize for per-tool gating). The other tool methods (search, index-*, create-collection) already had this annotation.

This is the canonical pattern from the upstream sample — the filter chain stays permitAll on /mcp, and method-level security gates each tool individually.

Behavior

  • STDIO mode: no change. MethodSecurityConfiguration is @Profile(\"http\"), so the annotation is inert.
  • HTTP mode with http.security.enabled=false: no change. Method security bean isn't loaded.
  • HTTP mode with http.security.enabled=true: previously-anonymous tools now require a valid OAuth2 bearer token. This is the intended security model.

Test plan

  • ./gradlew spotlessApply clean
  • ./gradlew build passes (unit + integration tests)
  • Manual verification with MCP Inspector: confirm tools return 401 when no token is sent and 200 with a valid token

🤖 Generated with Claude Code

Adds @PreAuthorize("isAuthenticated()") to the four MCP tools that
previously allowed anonymous access in HTTP mode with security enabled:

- CollectionService.listCollections
- CollectionService.getCollectionStats
- CollectionService.checkHealth
- SchemaService.getSchema

These tools expose collection inventory, document counts, cache/handler
statistics, health, and schema fields — useful reconnaissance for an
attacker probing the underlying Solr cluster. Without method-level
security they were reachable anonymously because the SecurityFilterChain
permits the /mcp endpoint at the HTTP layer (matching the upstream
spring-ai-community/mcp-security "secured tools" sample, which relies
entirely on @PreAuthorize for tool gating).

The annotation is inert in STDIO mode (MethodSecurityConfiguration is
@Profile("http")) and inert in HTTP mode when http.security.enabled is
false, so this is non-breaking for existing users.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Signed-off-by: adityamparikh <aditya.m.parikh@gmail.com>
@epugh epugh merged commit 8b473f6 into apache:main May 8, 2026
3 checks 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.

2 participants