# Agent permissions

Status: **implemented for MCP** (Phase A, `25b7c50`) and **for the Bridge
API** (Phase B, `590b515`: `bridge` grants checked per route and vault,
[Agent Bridge protocol](bridge-protocol.md)) and **for model providers**
(Phase D, `6ba2743`: function calls run through the same wrapper under
a provider principal, gated by approvals, see "Provider agents").

One permission system for every way an agent reaches Phantom. Tool
annotations (`read_only`, `destructive`, …) stay descriptive metadata;
enforcement is the grant check described here.

## Model

A grant set maps a **resource** to the **actions** allowed on it
(`app/core/agents/permissions.py`). Only applicable actions can be
granted; anything else is refused with `invalid_value`.

| Resource | Covers | Grantable |
|---|---|---|
| `vault_meta` | vaults (create, change, delete), scope, targets, scans (read), workstation status | read create update delete |
| `http_evidence` | proxy history, bodies, WebSocket frames, held intercept messages, Repeater send results, HAR; `delete` deletes, clears and prunes history | read create update delete export |
| `notes` | research notes, folders, links, templates | read create update delete export |
| `files` | vault files: metadata, text contents, revisions, folders, storage statistics; `delete` moves to the trash; a Markdown file that is a note also needs the matching `notes` action ([Vault files](../files/index.md)) | read create update delete export |
| `findings` | findings and their evidence | read create update delete export |
| `payloads` | the vault's payload collections, and reading the global library | read create update delete export |
| `payloads_global` | changing global payload collections (shared by every vault) | read create update delete export |
| `reports` | report drafting, comments, validation, preview; `update` also finalises and reopens, `export` produces the file | read create update delete export |
| `workspace` | tags, bookmarks, saved views, Repeater tabs, comparisons, assets | read create update delete |
| `sensitive` | unmasked values, where the user's redaction policy allows reveal | read |
| `testing` | replay, Repeater send, intercept decisions, proxy start/stop, scans, Intruder, signatures, proxy and intercept settings | read create update delete execute |
| `bridge` | conversations, messages, tasks, approvals, events, workspace context (Bridge API and MCP inbox tools; nothing uses `delete` yet); `execute` lets an agent open, highlight, select and navigate in your window ([Interface control](ui-control.md)) | read create update delete execute |
| `skills` | reading the skill library, suggestions and skill content ([Skills](../skills/index.md)); creating, editing, enabling and importing skills are user actions, so nothing else can be granted | read |

AI access is **global**: tokens created in Settings → AI & Agents reach
every vault, including vaults created later, and model providers work in
any vault. The backend still supports a token limited to a list of vaults
(created over the API, or before this change); such a token keeps its
limit, and Settings → AI & Agents → Access offers "Allow every vault".

## Presets

`app/core/agents/presets.py`. A preset is a starting point; the token
stores the resulting grants, and the interface shows a token whose grants
match no preset as Custom.

| Preset | Grants |
|---|---|
| **Read only** (default) | `read` on `vault_meta`, `http_evidence`, `notes`, `files`, `findings`, `payloads`, `reports`, `workspace`, `skills`; `bridge` read and create. Nothing on `sensitive`, `testing`, `payloads_global`; no export, no delete. |
| **Research assistant** | Read only, plus read, create, update on `notes`, `files`, `findings`, `payloads`, `workspace`, `bridge`, and `bridge.execute` (control the interface). No testing, no deletes, no exports, no secrets. |
| **Report drafting** | Read only, plus read, create, update on `reports`, `notes`, `bridge`; read and update on `findings` (triage). No testing, no deletes, no exports, no secrets. |
| **Full access** (`full_access`; the former key `full_research` is still accepted) | Literally every grantable action on every resource: `testing.execute`, `sensitive.read`, `payloads_global`, every delete and export, creating, changing (scope included) and deleting vaults, deleting, clearing and pruning history, finalising, reopening and exporting reports, `bridge.execute`. Only the hard rules below stay refused. |

## Enforcement

- Every MCP tool and resource declares `requires=(Resource, Action)` and
  where its vault comes from (`app/mcp/enforcement.py`). Registration
  without it raises `TypeError`; `test_every_capability_declares_a_requirement`
  checks every tool and resource, and the parity matrix shows the
  requirement next to every capability. The requirement is also published
  to clients as `_meta["phantom/requires"]` in `tools/list` and
  `resources/list`.
- Vault sources: `argument` (the call's `vault_id`; none when absent),
  `proxy` (the vault the live proxy captures into: intercept tools,
  `proxy_stop`), `all` (workstation-wide changes: `vault_create`,
  signature writes, `proxy_settings_update`, `intercept_rules_set`; these
  need a token on all vaults, refused with reason `all_vaults`), `none`
  (workstation information: `system_info`, `proxy_status`, settings reads).
- The wrapper (`Toolkit.guarded`) takes the principal, checks the vault and
  the grant, runs the tool, then writes one audit row in its own session,
  so the tool's transaction is untouched and an audit failure never
  changes a result.
- Listings without a `vault_id` are filtered: `vault_list` and
  `phantom://vaults` show only permitted vaults.
- Payload collections without a vault are the global library: creating,
  changing or deleting one needs `payloads_global`; reading needs
  `payloads.read`. A global collection reached from a vault (`vault_id`
  given) is checked again in the payload services
  (`PayloadAccess.guard_global`), which know the collection's owner.
- Disclosure: revealing needs the user's MCP policy to allow it **and**
  `sensitive.read`. With `reveal_secrets` and no grant the call is refused;
  with the policy in `reveal` mode and no grant results stay redacted. The
  user's policy is the ceiling a grant never exceeds.
- A denied call fails with `permission_denied` and
  `details = {resource, action, vault_id, reason}`, `reason` one of
  `grant`, `vault`, `all_vaults`.

Requirement of every capability (generated from the registry):

| Requirement | Tools and resources |
|---|---|
| `vault_meta.read (none)` | `system_info`, `vault_list`, `proxy_status`, `proxy_settings_get`, `proxy_ca_certificate`, `proxy_capture_get`, `proxy_retention_get`, `phantom://vaults`, `phantom://proxy/status` |
| `vault_meta.read` | `vault_get`, `engagement_get`, `engagement_decisions`, `target_list`, `target_get`, `scan_list`, `scan_get`, `scan_logs`, `phantom://vault/{vault_id}`, `phantom://vault/{vault_id}/scan/{scan_id}`, `phantom://vault/{vault_id}/scope` |
| `vault_meta.create` / `update` / `delete` | `target_create`; `vault_update` (narrowing the scope only: adding an inclusion or lifting an exclusion is the user's), `target_update`; `vault_delete`, `target_delete`; `vault_create` needs all vaults, and the vault starts with active testing off |
| `http_evidence.read` | `flow_list`, `flow_hosts`, `flow_get`, `flow_body`, `flow_stats`, `flow_prune` (preview only), `ws_frames_list`, `ws_frame_get`, `repeater_sends_list`, `repeater_send_get`, `phantom://vault/{vault_id}/flows/recent`; proxy vault: `intercept_get`, `intercept_list`, `intercept_get_item`, `phantom://intercept/queue` |
| `http_evidence.create` / `delete` / `export` | `flow_import_har`; `flow_clear`, `flow_delete`, `flow_prune_apply` (all destructive); `flow_export_har` |
| `findings.*` | `finding_list`, `finding_get`, `phantom://vault/{vault_id}/findings` (read); `finding_create`; `finding_update`; `finding_delete` |
| `notes.*` | `note_list`, `note_get`, `note_backlinks`, `note_graph`, `note_folder_list`, `note_templates` (read); `note_create`; `note_update` |
| `files.*` | read: `file_list`, `file_get`, `file_read`, `file_revisions`, `file_folder_list`, `file_stats`, `file_attachments`; create: `file_create`, `file_folder_create`; update: `file_update`, `file_write`, `file_attach`, `file_detach` (these two also need `findings.update` or `reports.update`); delete: `file_delete` (to the trash). Note-backed Markdown files also need `notes.read` / `create` / `update` for reading, creating, writing and trashing them. |
| `payloads.*` | read: `payload_collection_list`, `payload_collection_get`, `payload_categories`, `payload_items_list`, `payload_import_preview`; create: `payload_collection_create`, `payload_collection_duplicate`, `payload_items_append`, `payload_import`; update: `payload_collection_update`, `payload_collection_archive`, `payload_items_update`, `payload_items_normalize`; delete: `payload_collection_delete`, `payload_items_delete`; export: `payload_export` |
| `reports.*` | read: `report_templates`, `report_list`, `phantom://vault/{vault_id}/reports`, `report_get`, `report_validate`, `report_render`; create: `report_create`, `report_section_add`, `report_comment_add` (a report can only cite what the token reads: findings need `findings.read`, embedded notes `notes.read`, evidence requests `http_evidence.read`; without the last, automatic evidence is skipped); update: `report_section_update`, `report_status` (submit, finalise, reopen); export: `report_export` (keeping secrets in the file also needs `sensitive.read` and an export policy that allows it) |
| `workspace.*` | read: `phantom://vault/{vault_id}/assets`, `session_profile_list`, `tag_list`, `annotation_get`, `view_list`, `repeater_tab_list`, `repeater_tab_get`, `comparison_list`, `comparison_get`, `asset_list`, `asset_search`, `asset_get`, `asset_graph`, `asset_import_preview`; create: `tag_create`, `view_create`, `repeater_tab_create`, `comparison_create`, `asset_create`; update: `tag_update`, `annotation_set`, `annotation_batch`, `view_update`, `repeater_tab_update`, `asset_sync`; delete: `tag_delete`, `view_delete` |
| `testing.read` | `attack_estimate`, `attack_get`, `attack_results`, `attack_result_get`; no vault: `engine_list`, `signature_list`, `signature_get`, `signature_validate`, `intercept_rules_get`, `intercept_rules_test` |
| `testing.execute` | `flow_replay`, `repeater_send`, `scan_start`, `scan_cancel`, `proxy_start`, `proxy_set_vault`, `attack_start`, `attack_pause`, `attack_cancel`; proxy vault: `proxy_stop`, `intercept_update`, `intercept_forward`, `intercept_drop`, `intercept_release_all` |
| `testing.create` / `update` / `delete` | `attack_create`; all vaults: `signature_create`, `signature_update`, `signature_set_active`, `proxy_settings_update`, `intercept_rules_set`, `signature_delete`; `scan_delete` |
| `bridge.read (none)` | `bridge_inbox`, `workspace_context_get`, `phantom://bridge/inbox` (the services check each conversation's vault) |
| `bridge.create (none)` / `bridge.update (none)` | `bridge_reply`; `task_claim`, `task_update` |
| `bridge.execute` | `ui_open`, `ui_highlight`, `ui_select`, `ui_navigate`, plus the read grant of what they show ([Interface control](ui-control.md)) |

`testing.execute` adds to, never replaces, the existing guards: scope
checks, the workstation-control guard (`app/mcp/guards.py`), the Intruder
agent policy and quotas.

## Hard rules no grant can override

Only what would let an agent widen its own access or reach outside the
workstation. Enforced in the services through `in_agent_call()` and the
user-only routes whatever the grants (also listed by
`GET /connections/permissions`, `app/core/agents/rules.py`):

- creating, changing, rotating or revoking tokens and their grants, its
  own or any other;
- adding, changing or removing model providers, their keys, grants or
  "allowed without asking";
- renaming, disconnecting or removing connected agents;
- turning the MCP server on or off;
- changing the privacy policies: the MCP and export redaction policies,
  the Intruder agent policy and the history retention policy;
- submitting anything to an external program or platform;
- creating, changing, enabling, disabling, importing or deleting skills
  (agents only read them, and a skill never grants anything).

Since the AI & Agents redesign these are **grants, not hard rules**:
changing a vault's scope (`vault_meta.update`), creating and deleting
vaults (`vault_meta.create` / `delete`), deleting, clearing and really
pruning captured history (`http_evidence.delete`), finalising and
reopening a report (`reports.update`) and exporting one
(`reports.export`). Without the grant they are refused with
`permission_denied` like any other action; the services check them too
(`require(...)`), so no path skips the grant.

Agents also cannot reach another vault through a global collection (writes
need `payloads_global`) or turn content into authority: grants are read
only from the database, never from tool arguments, captured traffic,
notes or messages.

## Provider agents

A model provider ([Model providers](model-providers.md)) is a registry
agent (`connection_type = provider`) whose grants live on an internal
token (`purpose = provider`, never issued, refused by authentication).

- Grants are chosen in Settings → AI & Agents (Add connection → Standard
  AI, or the Access tab) like a token's (preset or matrix); **Read only**
  by default. A provider reaches every vault, but
  each turn acts only in its conversation's vault (`vault_ids = {vault}`,
  transport `provider`), and `vault_id` is forced on every call.
- Phantom runs the provider's own Bridge plumbing, so its principal
  always holds `bridge` read, create and update; Bridge tools are never
  offered to the model.
- Offered: tools whose vault is their `vault_id` argument and reads of
  workstation information (`none` source). Never `all` (workstation-wide
  changes, `vault_create` included, because a turn's principal holds only
  the conversation's vault) or `proxy` (the live proxy's vault) tools.
  Within its vault a granted provider may change the scope or delete the
  vault (`vault_update`, `vault_delete`).
- **Allowed without asking** (`agent_tokens.auto_approve`, stored with
  the grants): a list of granted `resource.action` keys other than
  `read`. Everything else beyond reading, every open-world tool and every
  destructive tool waits for an approval in the conversation unless its
  key is allowed without asking (the interface offers Select all and
  Deselect all; destructive keys are shown in the accent colour).
  Narrowing the grants drops lost keys; changing them stops the
  provider's work like a token edit.
- Hard rules apply unchanged; a scope change, by contrast, is an
  ordinary `vault_meta.update` call (asked for unless allowed without
  asking).

## Audit

Every tool call and resource read writes one `agent_audit` row: actor
(`agent`, `dev`, or `user` for connection management), agent, token,
vault, transport (`mcp`, `rest`, `provider`), operation (tool name or resource URI template),
resource and action actually checked, outcome (`ok`, `denied`, `error`),
error code, and object ids (`*_id` / `*_ids` arguments only). Never other
arguments, content or credentials. `initialize`, refused authentications
(expired, revoked), token create / update / rotate / revoke and agent
disconnect are recorded too. The trail is bounded: every 200 rows, rows
beyond the newest 20 000 and rows older than 90 days are deleted.

## Mapping of earlier agent behaviour

| Before | Now |
|---|---|
| Notes, annotations, payload writes stamped `agent` | still stamped from the principal; need `notes` / `workspace` / `payloads` create or update |
| Writes to global payload collections | `payloads_global.<action>` |
| `flow_replay`, `repeater_send`, `intercept_forward`, `scan_start`, `attack_start` | `testing.execute` plus the existing guards |
| Report drafting tools | `reports.create` / `update` |
| Finalise, reopen, export reports; delete, clear, prune history | `reports.update` / `reports.export`; `http_evidence.delete` (hard rules until the AI & Agents redesign) |
| Changing a vault's scope | `vault_meta.update` (a hard rule in Phases A to D) |
| Policy writes, tokens, providers, MCP switch | still refused (hard rules) |
| Full research preset | Full access (the old key is accepted) |
