fix(ai): tools inherit caller capabilities instead of ai.chat acting as a blanket read grant#51
Merged
Merged
Conversation
…olContext Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
…cope through it Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
list_users -> users.manage; list/get/search documents -> the requireDataAccess six-cap set; collections/schema -> data.tables.read|manage; list_media -> media.read. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
…caps Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Content write tools mirror their data-route gates (create/edit/publish/reassign); site tools mirror the editor change-class model (structure/content/style, site.read for snapshot reads). The executeAiTool re-check now covers browser tools too. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
…es gating Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
|
Important Review skippedDraft detected. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
…y-gating # Conflicts: # server/ai/runtime/types.ts
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.
What changed
Security hardening finding #1 (2026-06-12 audit): the AI chat toolset only filtered write tools by
ai.tools.write— read tools were never capability-scoped, andexecuteAiTooldispatched handlers with no check. Any role grantedai.chat(the chat handler explicitly anticipates "a Client granted chat") could have the model calllist_users(every email + role),get_document/list_documents/search_documents(any row, drafts included), andlist_media(the whole library) — reads its own HTTP routes would refuse.Now the agent inherits the caller's capabilities by construction:
AiTool.requiredCapabilities(ANY-OF) declares each tool's gate, mirroring its HTTP-route equivalent:list_users→users.manage; document reads → therequireDataAccesssix-cap set;list_media→media.read; collection/schema reads →data.tables.read|manage.toolAllowedForCapabilities(server/ai/tools/capabilityGate.ts) is the single gate:mutates⇒ai.tools.write, plus the ANY-OFrequiredCapabilities.selectToolsForScopefilters the offered toolset through it (load-bearing: the tool loop only executes offered tools).executeAiToolre-checks before dispatch — server and browser tools — as defence in depth.ToolContext/ToolContextBasenow carry the caller's capability set.site.read.Why
Pre-release roles ship with
ai.chatonly on Owner/Admin, but custom roles (which the AI feature invites operators to create) would otherwise turnai.chatinto a privilege escalation / email-enumeration / draft-exfiltration vector.Impact
No behavior change for Owner/Admin (they hold every mapped capability). Restricted roles now see exactly the tools matching what they could do over HTTP.
Verification
bun run build— cleanbun test— 5386 pass / 0 fail (includes newsrc/__tests__/agent/aiToolCapabilityGate.test.ts: 13 cases across the helper, selection filtering, and dispatch re-check)bun run lint— clean🤖 Generated with Claude Code