# Office routes: threat model

<!-- toc -->
- [Assets](#assets)
- [Attackers](#attackers)
- [Threats and controls](#threats-and-controls)
- [Residual risks](#residual-risks)
<!-- /toc -->

The office routes of `scripts/contract-server.mjs` let a client watch the
agents on this machine, read what they said, answer and steer runs, and change
what runs here (autopilot, stacks, routines). A browser panel may be served at
`GET /office`. This file names what is protected, from whom, by which control,
and which test performs the attack.

Scope: the local server only. The office is local to this machine: nothing
pairs a phone with it or relays it to a site.

## Assets

| Asset | Where it lives | Why it matters |
|---|---|---|
| Bearer token | the server's memory and a 0600 file under `~/.claude/logs/multi-agent/contract-server/` | holds every desktop route |
| Transcripts | `~/.claude/projects/**.jsonl` | everything a session read, including file contents and command output |
| Credentials | the credential store (keychain), read only by the pipeline's own scripts | a leak is an account takeover |
| Run state | `agent-state.json`, `tracker-state.json` | an answer or steer written here changes what a run does |
| Machine configuration | autopilot `config.json` and launchd jobs, a repo's `.claude/settings.json`, routine commands | widening any of them changes what runs unattended |
| PR verdicts | posted to GitHub or Bitbucket with the user's own credential | an approval in the user's name |
| Learning stores | `~/.claude/memory/multi-agent/<repo>/` and `~/.claude/knowledge/<repo>/` | statements a run wrote down, which can quote code or a pasted secret |
| Run logs | `~/.claude/logs/multi-agent/<project>/<task>/` | deleting the wrong folder loses a live run's state |

## Attackers

1. **A malicious web page** in the user's browser, while the server runs.
2. **Another local user or process** that can reach 127.0.0.1.
3. **Hostile transcript content**: text an agent read (a web page, an issue, a
   file) written to make the panel run script or leak data.

## Threats and controls

| # | Threat | Control | Proof |
|---|---|---|---|
| T1 | DNS rebinding: a page on an attacker host resolves to 127.0.0.1 and calls the API under its own name | Every request, `/office` and the event stream included, must carry `Host: 127.0.0.1:<port>` or `localhost:<port>`; anything else is 403 before routing | `smoke-office-security.sh` T1, `test/office-routes.test.mjs` "403 under a rebound Host" |
| T2 | CSRF: a page posts to a write route | Writes (POST, DELETE) accept no `Origin` but the server's own, even an origin allowed with `--allow-origin`; a foreign preflight is 403 and no CORS header is ever sent to a foreign page; writes that widen what runs here take a second request with a single-use, route-bound confirm token | `smoke-office-security.sh` T2, `office-routes.test.mjs` "a write from a foreign page is refused" |
| T3 | Token theft or replay | The token is read from the `Authorization` header only (never a cookie or a query parameter), compared in constant time over digests, never written into a response, an error or a log line. It never appears in a URL: `office-on` opens the page with a one-time code in the fragment (10 seconds, one use, minted by the bearer holder at `POST /office/code` with no Origin), and the page trades it at `POST /office/exchange`, which accepts only the server's own Origin; a second use, an expired or an unknown code is 401. The code never reaches a command line, which every local user can read (`ps`): the browser is opened on a 0600 launcher page in the 0700 state directory that carries the code and forwards with `location.replace`, under a CSP that allows only its own script by hash; the launcher is removed after 15 seconds. An Origin header can be forged by a non-browser client, so the code's secrecy and its 10 second, single-use life are what protect the exchange. The page keeps the token in memory and strips the fragment. So that a reload of the same tab stays signed in, the exchange also returns a resume key, and that key, never the token, is what the page keeps, in its tab's sessionStorage (never localStorage): it buys the token only at `POST /office/exchange` from the server's own Origin, once, the answer carrying its replacement; it lapses after 12 hours and with the server, and a refused one leaves the page saying to open a fresh link with `office-on`. When a link's code is refused, the page tries its stored key once before saying so. The server keeps at most 16 live keys (`MAX_RESUMES`) and evicts the oldest when a seventeenth is minted, so a tab whose key was evicted is signed out at its next reload. sessionStorage is not memory only: browsers write it to disk to restore tabs after a restart, so the key sits in the browser profile until it is used, expires or the server stops. Duplicating a tab copies its sessionStorage, key included; the key is single use, so whichever copy reloads second is signed out and needs a fresh link. A server started by `contract-server.mjs` alone exits after 8 hours however busy it is; the panel's own server (`office-on`) runs until `office-off`, because a person keeps it open beside their work. Its token lives only in the server's memory, the page's memory and a 0600 file, is never on a command line or in a URL, and is replaced each time `office-on` starts a server | `office-control.test.mjs` "the opener's argv carries no code", "the launcher page has a strict CSP", "the launcher is deleted"; `office-routes.test.mjs` "a panel code trades for the token once", "a code is refused from a foreign page", "an expired code is 401", "a resume key trades for the token once", "an expired resume key is 401", "exits at its absolute lifetime"; `smoke-office-page.sh` "the code trades once"; `smoke-office-ui.sh` "a reload keeps the tab signed in" |
| T4 | Secret exposure through a response | Transcripts are read through `_transcript-tail.mjs`, which never parses api-request records and drops thinking blocks; every string passes the credential redactor and the scrubber; the finished office and chat documents are checked by the outbound gate; seat labels come from allow-listed fields (tool name, file basename, sidecar description), never a command line; credentials are read only by the service scripts and never returned | `smoke-office-privacy.sh`, `smoke-office-security.sh` T4, `test/office-activity.test.mjs` "carries no credential" |
| T5 | Path traversal into arbitrary files | Session, agent, run, routine, tool and evidence ids are matched against safe character sets after decoding; transcripts are looked up by name under the projects root only; a screenshot must resolve (real path) inside the run's evidence directory; an analysis document named in run state is read only when its real path is inside the run's log directory, its artifacts or a worktree git lists under the state's projectRoot, and only when it is Markdown or HTML | `smoke-office-security.sh` T5, `test/office-work.test.mjs` "nothing outside its directory", "analysis documents are read only inside the run's roots", "a worktreePath counts only when git lists it" |
| T6 | Oversized or malformed input | Bodies are capped at 64 KiB and validated against the route's schema; tool arguments are checked against the tool's inputSchema; launch input goes through `launch-request.mjs` validation only; chat paging is capped at 500 | `smoke-office-security.sh` T6, `office-work.test.mjs` "refuses an unknown tool, invalid arguments and an oversized body" |
| T7 | Resource exhaustion | At most four event streams and 64 connections; at most 256 confirm tokens, the oldest dropped first; service clients, the work list and autopilot control run as child processes, never blocking the event loop, one at a time per service (429 `busy` for a second write or service read; a second `GET /v1/prs`, `GET /v1/autopilot` or maturity read of the same issue shares the run in flight, and at most two maturity reads for different issues run at once); one snapshot is computed per poll from bounded tail reads; the session list is cached for ten seconds; a server started on its own exits after its idle time and after 8 hours in any case, the one `office-on` starts runs until `office-off`, and both stop on SIGTERM | `smoke-office-security.sh` T7; `office-routes.test.mjs` "connections past the cap are dropped", "confirm tokens are capped"; `office-work.test.mjs` "a slow service read neither blocks other routes nor runs twice at once", "maturity checks for different issues run at most two at a time" |
| T8 | XSS from hostile transcript or issue text | The panel renders every server string with `textContent` or canvas text; markdown is shown as plain text; server images only as `data:` URLs of image types; the office sprites are same-origin PNGs from `/office/assets/`, which answers only a plain file name (no separator or escape) whose real path is a PNG directly in the installed assets directory, and 404 otherwise; the page language the server stamps comes from a two-value set (`en`, `tr`), whatever the preferences file holds; the page's CSP allows only its per-response nonce for script and style, `connect-src 'self'`, no framing, no base URI, no form action | `smoke-office-page.sh`, `office-routes.test.mjs` "stamps the page language from outputLanguage", "serves a sprite and nothing else under /office/assets/", `office-build.test.mjs`, `smoke-office-runtime.sh` |
| T9 | Clickjacking | `frame-ancestors 'none'` on the page and on every API response | `office-routes.test.mjs` "serves the page without a token, with a nonce CSP" |
| T10 | An action nobody can account for | Every write leaves one line (who, route, step, status; never a body or token) in `office-actions.jsonl` | `office-routes.test.mjs` "every write leaves a line" |
| T11 | The panel widening the machine silently | Autopilot on, stack changes, routine removal and adding or removing a launch repository are tagged `local-only` and `high`, take two requests, and run the same scripts as the terminal commands where one exists (removing a launch repository has none). A repository is added only as a git checkout that is neither the home directory nor the root; a suggestion is named by an opaque id and resolved again on the server, so a page never sends or sees a path it did not type | `smoke-office-routes.sh`, `smoke-office-single-source.sh`, `office-repos.test.mjs`, `smoke-office-ui.sh` |
| T12 | A toolkit tool used as a reader of local files or services (a path, a `file://` or loopback URL, a shared browser page, an index of files) | Tool calls are denied by default: only a tool that declares readOnlyHint, is not destructive, is not in the `web` or `context` family and whose inputSchema takes no location (a property named for a path, URL, file, directory, output, project, root and similar, or a uri format, at any depth) is callable; everything else is 403 `tool-not-allowed` and never reaches the server. A `confirm` argument is refused, so a tool's own preview is never skipped. The toolkit child always runs with `MULTI_AGENT_UNATTENDED=1`, `MCP_TOOLKIT_URL_POLICY=strict` and the unattended profile's `MCP_TOOLKIT_INDEX_DENY`, applied after the registration's own environment. An `@latest` registration is pinned to a configured version or refused. The route is `local-only`, and its audit line names the tool and carries a SHA-256 of the arguments, never the arguments | `office-work.test.mjs` "refuses every tool outside the allowlist with 403 and never runs it", "refuses a confirm argument", "runs unattended with the strict URL policy", "pinned to a known version or refused", "the audit line names the tool and hashes the arguments" |
| T13 | A steer instruction injected into an unattended run | Steering is tagged `launch` and `high` and takes two requests: the first shows the text, the run's phase and the unread instruction it replaces, and returns a token bound to that run and exactly that text; the second carries only the token. A finished run cannot be steered | `office-routes.test.mjs` "previews first, then queues on confirm", "a steer token is single use, bound to its run and cannot carry new text" |
| T14 | A review verdict posted from a stale or unfinished review | A verdict is previewed only for a finished review whose every finding is accepted, rejected or deferred (409 `review-incomplete` otherwise); the confirm token is bound to the decision and a digest of the findings, and a confirmation after either changed is 409 `confirm-mismatch` | `office-work.test.mjs` "a running review or one with an untriaged finding cannot be previewed", "refused when the findings changed after the preview" |
| T15 | A service read pointed at another host | A Confluence URL is accepted only on the configured Confluence host, and with no host configured only a page id is accepted (409 `host-not-allowed`), before the client script runs; Crashlytics takes only a Firebase console URL | `office-work.test.mjs` "a Confluence URL on another host is refused before the client runs", "only a page id is accepted" |
| T16 | Machine paths leaking through errors, or `office-off` signalling a reused pid | Error bodies name no absolute path (the launchd refusal and the unreadable settings message say what failed, not where); `office-off` sends SIGTERM only when the recorded pid's token file still names it, its command is `contract-server.mjs` and its start time matches the token file's | `office-routes.test.mjs` "refused without naming its path", "reported without the plist path"; `smoke-office-control.sh` "off never signals a pid that is not its server" |
| T17 | A reload code minted for another page, or a stale server outliving an update | `POST /office/reload` and `GET /office/version` need the bearer token and refuse any Origin other than the panel's own (a request with no Origin, a terminal client, is accepted); the reload code is the same 10 second, single-use code `office-on` uses, so a page that already holds the token gains nothing it did not have. A server whose code changed on disk is reported stale and `office-on` replaces it instead of reusing it | `office-repos.test.mjs` "/office/version reports the installed build", "/office/reload mints a one-time code"; `smoke-office-ui.sh` |
| T18 | The panel starting work nobody asked for, or work wider than asked | `POST /v1/jobs` takes only a job named in `schemas/office-jobs.json`, each parameter checked by its kind (a pull request URL or `repo#N`, a Jira key, a run id the index knows, a branch name, a path that stays inside the repository, an enumerated value; a pipeline run's work item goes through the launch request rules). An enumerated value read from this machine is checked against what it offers there: the review-priority teams whose rule file parses, and only the presets of the team given. Two requests: the preview names the role, the repository, the exact prompt and what the job writes outside the machine (a branch and PR for a pipeline run; review and clarify jobs report locally, since agent-guard keeps GitHub writes to the runner), and the token is bound to that payload. At the confirmation the repository must still be allowed, the unattended profile installed, the workspace trusted, agent-guard.sh registered for every tool and the autopilot runner's sandbox check passing; the session runs `claude --bg` with no permission prompts under that profile, without a shell, and claude's own output stays in the server's log, not the page. The unattended profile denies reading the server's token directory, so a session it starts cannot pick up the bearer. A team job is refused while a run is live in the same repository, from the moment its session starts. Tagged `local-only`/`high`. Every start is recorded under `logs/multi-agent/office/jobs/` and in `office-actions.jsonl` | `office-jobs.test.mjs`, `smoke-office-ui.sh` |
| T19 | The key cabinet leaking a credential, or the panel becoming a place to enter one | `GET /v1/credentials` runs `lib/credential-inventory.sh`, whose probe reads each credential through the credential store with its output discarded, so no value reaches the server process. The route keeps the logical name, a state and a probe verdict from fixed vocabularies and a capability line cut to 160 characters; anything else in the script's output is dropped. Tagged `local-only`. There is no write route: renewing a credential stays in the terminal (`/multi-agent:setup`), so a secret never passes through the browser | `office-routes.test.mjs` "GET /v1/credentials names each credential and its verdict, never a value" |
| T20 | A learned statement carrying a secret or a machine path to the page | `GET /v1/memory` returns counts, the code graph's age and size, and the five newest learning statements per repository, each passed through the transcript redactor (provider credential rules, paths and addresses) and cut to 120 characters. Repository names are matched against a safe character set before any file is opened. Read only; `local-only` | `office-routes.test.mjs` "GET /v1/memory reports every shelf, redacted" |
| T21 | Machine details through the resource panel | `GET /v1/system` returns numbers only (cores, load, memory, free disk, process counts, log folder size) and two fixed warnings; no path, process argument, user or host name. The schema allows nothing else. The measurement runs as child processes off the event loop, concurrent requests share one measurement, and the log folder size is reused for a minute. It names nothing about the machine beyond those numbers | `office-routes.test.mjs` "GET /v1/system returns numbers only: no path, user or host name" |
| T22 | Old run logs deleted wider than asked, or a live run's log removed | `POST /v1/prune-logs` takes only an age from a fixed set (7, 30 or 90 days) and runs `prune-logs.sh`, the script `/multi-agent:prune-logs` runs: the dry run is the preview; the confirmed step lists the folders again, refuses with `changed` when they differ, and then prunes only the previewed list through `--only-from`, under a token bound to that age and list. The script never touches the audit trail, the metrics corpus or the task counters, refuses a log root that is `/`, the home folder or a git checkout, and spares a folder written in the last minutes and a run that can still be resumed. Tagged `local-only`/`high` | `office-routes.test.mjs` "POST /v1/prune-logs previews, then prunes only on the token" |
| T23 | Pull request listing exposing a token, or the native task mirror writing into another run | Each GitHub account gh is logged in to is asked with `gh auth token` for that host and login; the token travels in `GH_TOKEN` (and `GH_ENTERPRISE_TOKEN` for an Enterprise Server host) for the child process only, never on a command line, in a response or a log. Bitbucket Server is read over https only (a plain-http host is refused unless it is the loopback), redirects are not followed, and the token, read from the credential store with a deadline, travels in the `Authorization` header only; an unreachable host is a reason on that source, not a failure of the list. `GET /v1/prs/reach` (local-only) asks gh for the changed file paths of at most 20 GitHub pull requests, three at a time, each with its account's token in the environment; it asks nothing for a repository whose name is not `owner/repo` or that has no graph under `~/.claude/knowledge/<repo name>/`. The paths serve only as keys into the local graph: nothing is read from disk by them and none is returned, only counts. The graph is parsed in a child process, so no other route waits behind it. A redacted answer drops URLs and logins, numbering the accounts instead. The task-mirror hook (PostToolUse on TaskCreate and TaskUpdate) writes only into the run whose recorded session is the calling session, skips phase tiles, never prints, and exits 0 on any input it cannot read | `work-items-prs.test.mjs`, `task-mirror.test.mjs`, `pr-reach.test.mjs`, `office-work.test.mjs` "GET /v1/prs/reach says which pull requests have no graph to measure against" |
| T24 | The panel changing a preference wider than the terminal would | `POST /v1/settings` takes one of three settings and one of its two values, previews the change and runs, under a token bound to that setting and value, what `/multi-agent:language`, `/multi-agent:fable-on`/`fable-off` or `/multi-agent:route-on`/`route-off` runs; route on passes the saved strategy back so only the switch changes, nothing the panel sends can add rules or a free provider, and two changes never run at once. Tagged `local-only`/`high`. Report links: `channelResults` URLs must be https, travel only in the run record's `channelUrls` (local, dropped from a redacted answer) and are shown as text, never followed | `office-routes.test.mjs` "POST /v1/settings changes a switch only on the token, through its script", `runs-index.test.mjs` |
| T25 | The skill catalog reading files a request names, or a SKILL.md running as markup | `GET /v1/skills` reads only fixed roots: the command tree, the `local-only` command folders under `~/.claude/commands/multi-agent`, the marketplace clone under `~/.claude/plugins/marketplaces/multi-agent-plugins` and the routine registry. Its one parameter, `repo`, resolves the way `GET /v1/stack` resolves it (a configured or registered repository, nothing else) and only decides which plugin skills are on. A skill folder or SKILL.md whose real path leaves the clone is skipped, and a plugin name outside a safe character set is ignored. Descriptions are file content, so the page sets them as text only. Routine text is scrubbed, and the route is `local-only` because it names the routines and local-only commands kept on this machine | `office-skills.test.mjs`, `skill-catalog.test.mjs`, `smoke-office-ui.sh` "a skill description shows as text, never as markup" |
| T26 | The disk section deleting more than was ticked, the user's own files, or anything while nobody watches | `POST /v1/disk-clean` runs `disk-cleaner.mjs`, the script `/multi-agent:clean-disk` runs. Measuring is its dry run and mints no token. Only a preview of named categories returns one, and each category must be an id from the cleaner's own allow-list (`CATEGORIES`); nothing else from the request reaches its command line. The token is bound to those categories, and the confirmation sends only the token and applies exactly them with `--only`. The Trash and old transcripts need their id and their own `trash: true` / `transcripts: true`; the page leaves both unticked and shows what deleting them costs. A server started with `MULTI_AGENT_UNATTENDED=1` measures the cleaner's unattended set and refuses a preview and an apply. The cleaner guards every path again before deleting it (no symlink, no personal or credential folder, no git working tree but a merged clean agent worktree, nothing in use) and never stops a process. Real paths are shown, so the route is `local-only`/`high` | `office-disk.test.mjs` |

## Residual risks

- **Figma REST from the panel**: `GET /v1/services/figma` renders a frame
  with the user's Figma token through `figma-screenshot.sh`. It runs only for
  a panel request, in the server's own process, never inside a pipeline run's
  context; the pipeline's own rule that Figma is fetched only in the analysis
  phase is about runs and is unaffected. The Figma MCP is never called here.

- **Another process of the same user** can read the token file and call the
  API. The server does not defend against code already running as the user;
  nothing local does.
- **A page on the server's own origin** is trusted. Only the page this server
  serves can be there, and its CSP keeps other code out.
- **Starting a session**: `POST /v1/launch` returns the launch plan for a
  client to start. `POST /v1/jobs` starts a session itself, because the office
  is that client; it is bounded by T18.
- **Host permission prompts** are not forwarded: the host records none where
  another process can read them (`GET /v1/permissions` says `available:
  false`).
