Skip to content

fix(agent): enforce scope.allows_resource in read_resource#408

Merged
intendednull merged 1 commit into
mainfrom
claude/issue-305-agent-read-resource-scope
Apr 27, 2026
Merged

fix(agent): enforce scope.allows_resource in read_resource#408
intendednull merged 1 commit into
mainfrom
claude/issue-305-agent-read-resource-scope

Conversation

@intendednull
Copy link
Copy Markdown
Owner

Why

list_resources filters by scope.allows_resource, but read_resource historically dispatched directly. dormant today (allows_resource always returns true), but as soon as a scope returns false for 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_resource now rejects with ErrorCode::INVALID_REQUEST before delegating, mirroring call_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 contents
  • denied_uri_rejects_with_invalid_request — stub scope denying one URI yields INVALID_REQUEST, same code call_tool uses when blocked

mirror 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 --check clean
  • cargo clippy -p willow-agent --all-targets -- -D warnings zero warnings
  • cargo test -p willow-agent 32 e2e + 31 unit pass (2 new)

Closes #305


Generated by Claude Code

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
@intendednull intendednull merged commit f72d00b into main Apr 27, 2026
7 checks passed
@intendednull intendednull deleted the claude/issue-305-agent-read-resource-scope branch April 27, 2026 09:23
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.

[SEC-A-02] Agent read_resource does not enforce allows_resource scope

2 participants