fix(mcp): evaluate security when listing tools and resources - #8483
Open
Amoifr wants to merge 1 commit into
Open
fix(mcp): evaluate security when listing tools and resources#8483Amoifr wants to merge 1 commit into
Amoifr wants to merge 1 commit into
Conversation
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.
ListHandlerreturned every registered element, so an anonymous caller could read the name, the description and the full input schema of a tool it was not allowed to invoke. Invocation itself was already denied since #8435; only discovery leaked.Elements whose operation-level
securitydenies the current caller are now dropped fromtools/listandresources/list.The two design questions from the issue
Only
securityis evaluated.securityPostDenormalizeandsecurityPostValidationneed arguments and an object that do not exist at list time, so they cannot take part. The filter is therefore best-effort onsecurityalone, which is what the class docblock now says.Expressions that need call-time variables leave the element listed. An expression reading
object,previous_objector a uri variable cannot be evaluated before the tool runs: the expression language rejects the unknown name, and the element stays visible.tools/callstill enforces it, so nothing is granted that was not granted before. This mirrors whatAccessCheckerProvideralready does when it skips thepre_readstage for expressions using the object, so I did not add a configuration flag: hiding those elements would hide tools the caller is perfectly allowed to call, and no flag is needed to describe a behaviour that is already the codebase's convention. Happy to turn it into an option if you would rather have it explicit.Notes
ListHandlerkeeps working unfiltered when security is not installed (ignoreOnInvalid()on the checker).SyntaxErroris only referenced in acatch, andapi-platform/mcpdoes not gain a dependency onsymfony/expression-language, the same wayHandleralready usesRequestStackwithout requiringsymfony/http-foundation.Tests
resources/list.McpSecuredToolsfixture: an anonymous caller no longer seessecured_toolbut still seessecured_post_denormalize_tool,secured_post_validation_toolandsecured_uri_variable_tool; an admin sees all of them. Both fail on4.3without the fix.