fix(agent): enforce scope.allows_resource in read_resource#408
Merged
Conversation
Production gate was added in 13c7dc6; this commit pins the contract with explicit tests for both branches: - read_resource_allowed_uri_returns_resource: scope-allowed URI delegates and returns contents. - denied_uri_rejects_with_invalid_request: stub scope denying one URI produces ErrorCode::INVALID_REQUEST, matching call_tool's gate. Mirrors readonly_scope_rejects_send_message pattern (RequestContext cannot be built externally, so we replicate the gate logic). Closes #305
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.
Why
list_resourcesfilters byscope.allows_resource, butread_resourcehistorically dispatched directly. dormant today (allows_resourcealways returnstrue), but as soon as a scope returnsfalsefor any URI, a probing client could still read it by URI. defense-in-depth gap.Fix
production gate already landed in 13c7dc6 (server.rs:167) —
read_resourcenow rejects withErrorCode::INVALID_REQUESTbefore delegating, mirroringcall_tool.this PR pins the contract with two unit tests in
crates/agent/tests/e2e.rs:read_resource_allowed_uri_returns_resource— allowed URI returns contentsdenied_uri_rejects_with_invalid_request— stub scope denying one URI yieldsINVALID_REQUEST, same codecall_tooluses when blockedmirror pattern from
readonly_scope_rejects_send_message(RequestContext<RoleServer>not externally constructible, so we replicate the gate logic + stub the scope predicate).Verify
cargo fmt --checkcleancargo clippy -p willow-agent --all-targets -- -D warningszero warningscargo test -p willow-agent32 e2e + 31 unit pass (2 new)Closes #305
Generated by Claude Code