From 7b671f1e81caaadfb9cddb2e5b72694e29ea38ec Mon Sep 17 00:00:00 2001 From: John Crenshaw Date: Wed, 28 Oct 2026 12:43:50 -0400 Subject: [PATCH] chore(security): take sentinel out of the repository The security audit runs by hand from outside the repository from now on, so nothing of the kit stays in it: the submodule, fast.yml, THREAT-MODEL.md, the review guidance, the semgrep ignore list and the audit output ignores. The main ruleset no longer requires the mechanical and security-review checks; test.yml's four are the ones left. --- .claude/claude-security-guidance.md | 77 ------ .github/dependabot.yml | 9 - .github/workflows/fast.yml | 290 ---------------------- .gitignore | 4 - .gitmodules | 3 - .semgrepignore | 25 -- .sentinel | 1 - SECURITY.md | 11 +- THREAT-MODEL.md | 371 ---------------------------- 9 files changed, 1 insertion(+), 790 deletions(-) delete mode 100644 .claude/claude-security-guidance.md delete mode 100644 .github/workflows/fast.yml delete mode 100644 .gitmodules delete mode 100644 .semgrepignore delete mode 160000 .sentinel delete mode 100644 THREAT-MODEL.md diff --git a/.claude/claude-security-guidance.md b/.claude/claude-security-guidance.md deleted file mode 100644 index d96be3b09..000000000 --- a/.claude/claude-security-guidance.md +++ /dev/null @@ -1,77 +0,0 @@ -# Baley security review rules - -## Threat model - -Baley is one Rust binary. Claude Code starts it as a stdio MCP server (`baley serve`) and as a pre-tool-use hook (`baley guard`), and the owner runs its command line. All three run as the interactive user, outside Claude Code's sandbox. It keeps a hash-chained SQLite ledger in Baley's home folder. - -The main attacker is the AI agent in the owner's session, along with any text injected into it. Its goals are to: - -- approve its own work or get any act recorded as the owner's; -- change the policy that judges it; -- commit or push to a protected branch; -- tamper with the ledger; -- run code outside the sandbox. - -Outside attackers come second: the update source, the network, a forge holding anchor tags, and a hostile cloned repository. - -The control everything rests on is the sandbox block and the `Read` and `Edit` deny rules that `baley install` writes into Claude Code's `settings.json` (`crates/baley/src/host_artifacts/security.rs`). They deny agents reads and writes of Baley's home and config folders, and writes of the executable, the versions folder and the placed files. Nothing else tells the owner at a terminal apart from an agent running the same command. The owner's recorded name (`owner.name`, or git `user.name`) is a label, not authentication. - -Ways in: - -- MCP frames over stdio; -- the hook's JSON on stdin; -- CLI arguments and stdin; -- environment variables (`CLAUDE_PROJECT_DIR`, `CLAUDE_CONFIG_DIR`, `BALEY_HOME`, `XDG_*`, `HOME`, `PATH`); -- the committed `baley.toml`, whose policy is HEAD's copy, and the owner's `config.toml`; -- git output and the repository's own `.git/config`; -- the update manifest and binary; -- anchor tags read back from the forge. - -Out of scope: the inherited engine listed in `crates/baley/src/inherited.rs`, which production does not reach. Flag any change that makes production reach it. - -## Review checklist - -**Owner acts and the sandbox** -- An owner act (an approval of scope, truths or plans) must be served on the command line only, never over MCP. A new `baley_apply` or `baley_query` operation that records `Actor::Owner` is a critical finding. Truths are approved only with `baley story truths approve` at the terminal; `context-submit` records a draft and must never approve one. -- An answer or deferral a session relays over MCP (`questions-answer`) must be recorded with actor `baley`, the session as the caller and `owner.name` in its payload. An MCP path that records one as `Actor::Owner` is a critical finding. Only `baley questions answer` at the terminal records actor `owner` (ADR 0047). -- Over MCP only `capture`, `scope-submit`, the ten change operations (`project-describe` to `backlog-reorder`), `project-start`, `work-order-fail`, `work-order-retry`, `questions-answer`, `story-refine`, `story-questions-submit` and `context-submit` may write the ledger. A new MCP write path needs the same project-in-ledger check as `crates/baley/src/mcp/prepare.rs`. -- Install must render `sandbox.enabled = true`, `failIfUnavailable = true`, `allowUnsandboxedCommands = false` and the deny lists. It must refuse a settings document that would weaken them (`crates/baley/src/host_artifacts/compose.rs`). Flag any change that drops a deny entry, adds an exclusion, or accepts an `allowRead` or `allowWrite` entry that reaches Baley's folders. -- `baley doctor` must keep reporting drift in those settings and what an agent can reach. - -**The guard (`crates/baley/src/guard_hook/`, `crates/baley-core/src/guard/`)** -- Design 0010 states these limits, so they are not findings: - - only `git commit` and `git push` are scanned, and a declined command shape passes; - - `PowerShell` is asked about, never scanned; - - command-tool input over 64 KiB passes; - - a failed git read passes unless `git.guard_hard_fail` is set. -- A command shape the scan claims to recognise but judges wrongly is a finding. -- The path tools (`Read`, `Grep`, `Glob`, `Write`, `Edit`, `NotebookEdit`) must fail closed. Unreadable input, an unresolvable path, or protected paths that cannot be derived must give deny. -- The guard must launch nothing but git, stay inside its time budget, and never record command text. - -**Processes (`crates/baley/src/process.rs`, `git_process.rs`)** -- Every child starts at `process.rs`. A new launch of a program other than git, `claude` or Baley's own binary needs a reason. -- A git argument built from data must not be readable as an option. Use `--`, `--end-of-options` or a leading-dash check. -- Git runs outside the sandbox in an agent-writable checkout and honours its `.git/config`. Flag new git calls that can run configured programs: network operations, operations that refresh the index (fsmonitor), or a hook-running command without `--no-verify`. -- Never run a shell, and never interpolate data into a command string. - -**Files** -- Writes go through `crates/baley/src/replace.rs` or an equivalent that refuses symlinks, checks the target is unchanged, and renames atomically. -- Install changes only what it can prove it wrote, by hash or exact match against the install record. -- The ledger home must stay 0700 with 0600 files, owned by the user, and every open must check that. - -**Ledger (`crates/baley-store`, `crates/baley-store-sqlite`)** -- SQL binds values as parameters. `format!` SQL may insert only identifiers checked by `safe_identifier` or compiled constants. -- Events stay append-only and hash-chained. A path that writes events without extending the chain, or that rewrites or deletes outside `purge`, is a finding. -- `baley-core` and `baley-store` must not depend on rusqlite. - -**Network and updates (`crates/baley/src/update/`, `crates/baley/src/ledger/forge.rs`)** -- Downloads stay HTTPS-only with no proxy and no credentials, within their size and time caps, and are checked against the manifest's SHA-256 before they are staged or run. The manifest being unsigned is tracked as #14. -- The only data that leaves the machine is anchor tags pushed to `git.remote`'s push URL, and the update downloads from `updates.source`. Any other network call, or telemetry of any kind, is a finding. - -**Secrets** -- Baley must never read, store, send or log API keys, and must never call a model provider. Keys stay in the owner's environment. -- Remote URLs and git stderr must have userinfo stripped before they are recorded or printed (`crates/baley/src/checkout/strip.rs`). -- Guard records keep the input digest, never the command. -- New text an agent supplies that is stored or echoed back needs bounds and must not carry secrets into new places. - -**Known and tracked, not findings:** #14 (unsigned manifests), #30 (the parked review engine still compiled in), #26 (file lease not enforced), #27 (anchors pushed by hand), #24 (macOS not qualified). diff --git a/.github/dependabot.yml b/.github/dependabot.yml index 195496cf4..138df730c 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -17,15 +17,6 @@ updates: github-actions: patterns: - "*" - # The .sentinel pin, so a kit change arrives as a pull request that runs the - # new kit's checks before it is merged. - - package-ecosystem: gitsubmodule - directory: / - schedule: - interval: weekly - open-pull-requests-limit: 0 - cooldown: - default-days: 7 - package-ecosystem: cargo directory: / schedule: diff --git a/.github/workflows/fast.yml b/.github/workflows/fast.yml deleted file mode 100644 index c7137125e..000000000 --- a/.github/workflows/fast.yml +++ /dev/null @@ -1,290 +0,0 @@ -# sentinel fast check, on every pull request and every push to main, and the -# review of a pull request from a fork when started by hand. -# -# Copy this file into .github/workflows/ (GitHub) or .forgejo/workflows/ -# (Forgejo) in the repo under audit. It expects sentinel as a git submodule at -# the path in SENTINEL_DIR. -# -# The mechanical job runs on both GitHub and Forgejo, on pull requests, on -# pushes to main, and once a week on main, so a new advisory against a -# dependency already in use shows up without waiting for a pull request. The -# review jobs run on GitHub only, because they post through the GitHub API, -# and a job skipped by its `if:` never downloads its actions. -# -# The required `security-review` check is posted by the review jobs once a -# review has passed. A pull request from this repository is reviewed by -# itself once it is not a draft, so push to a draft while iterating and -# mark it ready for one review. A pull request from a fork gets no Actions -# secrets, so it is not reviewed until someone with write access reviews it -# from main's copy of this workflow: -# -# gh workflow run fast.yml -f pr= -# -# or `.sentinel/ci/review-pr.sh `, which starts that run, -# waits for it and prints the review. That run reads the fork's code and -# never runs it, so the API key never meets code the fork controls, and only -# a run started from the default branch can review. -# -# A fork's pull request runs the fork's copy of the workflows, so it can add a -# job named security-review of its own and show the check green without a -# review. Only someone with write access can merge or turn on auto-merge, so -# nothing merges it on its own: read the review from the hand-started run -# before merging a fork's pull request, and never auto-merge one. -# -# On a public repo, set the repository variable SENTINEL_REVIEW_AGE_RECIPIENT -# to your age public key. The review is then encrypted and uploaded as the -# `security-review` artifact, and the comment, log and job summary show only -# the count of findings. `.sentinel/ci/read-review.sh ` -# decrypts it on your machine. Without the variable the whole review is posted. -name: sentinel-fast - -on: - # ready_for_review too: a draft pull request gets the mechanical checks on - # every push and no review, which runs once it is marked ready. - pull_request: - types: [opened, synchronize, reopened, ready_for_review] - # A push straight to main gets the mechanical checks too. - push: - branches: [main] - # Mondays at 06:17 UTC, mechanical checks only: the review job's `if:` keeps - # it to pull requests. - schedule: - - cron: '17 6 * * 1' - # The review of a pull request from a fork, started by hand. - workflow_dispatch: - inputs: - pr: - description: Pull request number - required: true - type: number - -env: - SENTINEL_DIR: .sentinel - -# A newer push to the same pull request cancels the review of the older one, -# so two pushes a minute apart do not pay for two reviews. Runs on main queue -# instead, so none is lost, and so do reviews started by hand, one queue per -# pull request. Marking a draft ready queues too: it is the same commit, and -# a cancelled mechanical check on it would block the merge. -concurrency: - group: ${{ github.workflow }}-${{ inputs.pr || github.ref }} - cancel-in-progress: ${{ github.event_name == 'pull_request' && github.event.action != 'ready_for_review' }} - -permissions: - contents: read - -jobs: - mechanical: - # A review started by hand runs on main, which pushes already check. - if: github.event_name != 'workflow_dispatch' - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 - with: - submodules: recursive - # gitleaks reads every commit, so fetch the whole history. - fetch-depth: 0 - # Builds run the pull request's code; keep the token out of .git/config. - persist-credentials: false - - name: Install check tools - run: '"$SENTINEL_DIR/ci/install-tools.sh"' - - name: Mechanical checks - run: '"$SENTINEL_DIR/mechanical/check.sh" .' - - review: - # Pull requests from this repository only. A pull request from a fork - # gets no Actions secrets, so the review could never run on it; review-pr - # reviews it when started by hand. Dependabot's get no secrets either; the - # dependabot job marks them. There is no `needs: mechanical`, so a failing - # gate, such as a new advisory against a dependency already in use, does - # not skip the review. - # Aimed at the default branch only, so a review that passed was a review - # against it, and a retarget runs no new review. - # Not on a draft, so pushes while iterating cost no review; GitHub does - # not merge a draft, and marking it ready runs the review. - if: github.event_name == 'pull_request' && github.server_url == 'https://github.com' && github.event.pull_request.head.repo.full_name == github.repository && github.event.pull_request.user.login != 'dependabot[bot]' && github.base_ref == github.event.repository.default_branch && !github.event.pull_request.draft - runs-on: ubuntu-latest - timeout-minutes: 30 - permissions: - contents: read - pull-requests: write - checks: write - steps: - - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 - with: - ref: ${{ github.event.pull_request.head.sha }} - fetch-depth: 0 - submodules: recursive - # The reviewer can read files; keep the token out of .git/config. - persist-credentials: false - # Claude Code needs Node 22 or newer; older Node gets an old CLI that - # cannot run current models. - - uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0 - with: - node-version: 22 - # The version is pinned. A global npm install has no lockfile, which is - # what zizmor's adhoc-packages audit looks for. - - name: Install Claude Code - run: npm install -g @anthropic-ai/claude-code@2.1.300 # zizmor: ignore[adhoc-packages] - - name: Install age - if: vars.SENTINEL_REVIEW_AGE_RECIPIENT != '' - run: sudo apt-get update -q && sudo apt-get install -y -q age - # The reviewer judges the change against the base branch's threat - # model, not one the pull request rewrote. The diff still shows any - # change to it. - - name: Use the base branch's threat model - env: - BASE_REF: ${{ github.base_ref }} - run: | - rm -f THREAT-MODEL.md - git show "origin/$BASE_REF:THREAT-MODEL.md" > THREAT-MODEL.md 2>/dev/null || rm -f THREAT-MODEL.md - - name: Review the diff - env: - ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }} - BASE_REF: ${{ github.base_ref }} - SENTINEL_REVIEW_AGE_RECIPIENT: ${{ vars.SENTINEL_REVIEW_AGE_RECIPIENT }} - run: '"$SENTINEL_DIR/ci/security-review.sh" "origin/$BASE_REF"' - - name: Upload the encrypted review - if: ${{ !cancelled() && hashFiles('security-review.md.age') != '' }} - uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2 - with: - name: security-review - path: security-review.md.age - retention-days: 14 - # One comment per pull request, rewritten on each push, so a stale - # review never sits above the current one. --edit-last edits the last - # comment github-actions left, which is this one unless another - # workflow comments with the same token. - - name: Post the review - env: - GH_TOKEN: ${{ github.token }} - PR: ${{ github.event.pull_request.number }} - run: gh pr comment "$PR" --body-file security-review.md --edit-last --create-if-none - # The required check. It is posted only after a review passed: a failed - # check of the same name would keep blocking the commit after a later - # pass. Its external_id names this run, which read-review.sh reads. - - name: Mark the commit reviewed - env: - GH_TOKEN: ${{ github.token }} - SHA: ${{ github.event.pull_request.head.sha }} - run: >- - gh api "repos/$GITHUB_REPOSITORY/check-runs" --silent - -f name=security-review -f head_sha="$SHA" -f status=completed -f conclusion=success - -f external_id="$GITHUB_RUN_ID" - -f "output[title]=Reviewed" - -f "output[summary]=Reviewed by $GITHUB_SERVER_URL/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID" - - dependabot: - # Dependabot's pull requests get no Actions secrets, so they are not - # reviewed; their dependency changes go through the mechanical job's - # checks. The required check is marked skipped, so they still merge, and - # auto-merge still works for them. The run has to be Dependabot's own: a - # push to its branch by anyone else goes unmarked. - # The actor test only narrows the author test, so zizmor's spoofing - # concern cannot widen who gets through. - if: github.event_name == 'pull_request' && github.server_url == 'https://github.com' && github.event.pull_request.head.repo.full_name == github.repository && github.event.pull_request.user.login == 'dependabot[bot]' && github.actor == 'dependabot[bot]' # zizmor: ignore[bot-conditions] - runs-on: ubuntu-latest - permissions: - checks: write - steps: - - name: Mark the commit not reviewed - env: - GH_TOKEN: ${{ github.token }} - SHA: ${{ github.event.pull_request.head.sha }} - run: >- - gh api "repos/$GITHUB_REPOSITORY/check-runs" --silent - -f name=security-review -f head_sha="$SHA" -f status=completed -f conclusion=skipped - -f "output[title]=Not reviewed" - -f "output[summary]=Dependabot pull requests are not reviewed; the mechanical job checks their dependencies." - - review-pr: - # A pull request from a fork, reviewed when someone with write access - # starts it by hand. The workflow and the kit come from the default - # branch, never from the pull request, and the pull request's code is - # only read: nothing in it runs, and its submodules are not fetched. - if: github.event_name == 'workflow_dispatch' && github.server_url == 'https://github.com' && github.ref == format('refs/heads/{0}', github.event.repository.default_branch) - runs-on: ubuntu-latest - timeout-minutes: 30 - permissions: - contents: read - pull-requests: write - checks: write - steps: - - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 - with: - submodules: recursive - persist-credentials: false - - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 - with: - ref: refs/pull/${{ inputs.pr }}/head - path: pr - fetch-depth: 0 - persist-credentials: false - # A symlink in the pull request could point the review's reads or - # writes outside its tree, at main's kit or /proc/self/environ. The - # diff is built from the commits, so it still shows any it adds. - - name: Remove the pull request's symlinks - run: find pr -path pr/.git -prune -o -type l -exec rm -f {} + - # The reviewer judges the change against main's threat model, not one - # the pull request rewrote. The diff still shows any change to it. - - name: Use main's threat model - run: | - rm -f pr/THREAT-MODEL.md - if [[ -f THREAT-MODEL.md ]]; then cp THREAT-MODEL.md pr/THREAT-MODEL.md; fi - # The commit marked is the one checked out, so a push during the review - # leaves the new head unmarked. - - name: Read the pull request - id: pr - env: - GH_TOKEN: ${{ github.token }} - PR: ${{ inputs.pr }} - MAIN: ${{ github.event.repository.default_branch }} - run: | - base=$(gh pr view "$PR" -R "$GITHUB_REPOSITORY" --json baseRefName -q .baseRefName) - # Reviewed against the default branch only: a review against another - # base would still mark the commit after the pull request is retargeted. - if [[ $base != "$MAIN" ]]; then - echo "::error::pull request $PR targets $base, not $MAIN; retarget it to $MAIN, then review it" - exit 1 - fi - echo "base=$base" >> "$GITHUB_OUTPUT" - echo "sha=$(git -C pr rev-parse HEAD)" >> "$GITHUB_OUTPUT" - - uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0 - with: - node-version: 22 - - name: Install Claude Code - run: npm install -g @anthropic-ai/claude-code@2.1.300 # zizmor: ignore[adhoc-packages] - - name: Install age - if: vars.SENTINEL_REVIEW_AGE_RECIPIENT != '' - run: sudo apt-get update -q && sudo apt-get install -y -q age - # The script is main's; its working directory is the pull request's - # tree, so the reviewer reads that tree and nothing outside it. - - name: Review the diff - working-directory: pr - env: - ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }} - BASE_REF: ${{ steps.pr.outputs.base }} - SENTINEL_REVIEW_AGE_RECIPIENT: ${{ vars.SENTINEL_REVIEW_AGE_RECIPIENT }} - run: '"$GITHUB_WORKSPACE/$SENTINEL_DIR/ci/security-review.sh" "origin/$BASE_REF"' - - name: Upload the encrypted review - if: ${{ !cancelled() && hashFiles('pr/security-review.md.age') != '' }} - uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2 - with: - name: security-review - path: pr/security-review.md.age - retention-days: 14 - - name: Post the review - env: - GH_TOKEN: ${{ github.token }} - PR: ${{ inputs.pr }} - run: gh pr comment "$PR" -R "$GITHUB_REPOSITORY" --body-file pr/security-review.md --edit-last --create-if-none - - name: Mark the commit reviewed - env: - GH_TOKEN: ${{ github.token }} - SHA: ${{ steps.pr.outputs.sha }} - run: >- - gh api "repos/$GITHUB_REPOSITORY/check-runs" --silent - -f name=security-review -f head_sha="$SHA" -f status=completed -f conclusion=success - -f external_id="$GITHUB_RUN_ID" - -f "output[title]=Reviewed" - -f "output[summary]=Reviewed by $GITHUB_SERVER_URL/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID" diff --git a/.gitignore b/.gitignore index e1d581d2f..7ad597392 100644 --- a/.gitignore +++ b/.gitignore @@ -15,7 +15,3 @@ scratch/ # Cargo build output target/ - -# Security audit output and Claude Security scan reports, which can name unfixed findings, never committed -audit/ -CLAUDE-SECURITY-*/ diff --git a/.gitmodules b/.gitmodules deleted file mode 100644 index 42013a07e..000000000 --- a/.gitmodules +++ /dev/null @@ -1,3 +0,0 @@ -[submodule ".sentinel"] - path = .sentinel - url = https://github.com/jcrenshaw-dev/sentinel diff --git a/.semgrepignore b/.semgrepignore deleted file mode 100644 index eff43ee0a..000000000 --- a/.semgrepignore +++ /dev/null @@ -1,25 +0,0 @@ -# This file replaces semgrep's built-in ignore list, so its defaults are kept here. -node_modules/ -build/ -dist/ -vendor/ -.env/ -.venv/ -.tox/ -*.min.js -.npm/ -.yarn/ -test/ -tests/ -testsuite/ -*_test.go -.semgrep -.semgrep_logs/ - -# Outside the security audit's scope (THREAT-MODEL.md). -crates/baley-bench/ -spikes/ - -# Inherited engine that production does not reach. Build 9 (#30) deletes both files. -crates/baley/src/pause/git.rs -crates/baley/src/task/mod.rs diff --git a/.sentinel b/.sentinel deleted file mode 160000 index a86de7ecd..000000000 --- a/.sentinel +++ /dev/null @@ -1 +0,0 @@ -Subproject commit a86de7ecde3aebe9225dd1a8d622fc2f1da1b20c diff --git a/SECURITY.md b/SECURITY.md index acef834b3..50b712f92 100644 --- a/SECURITY.md +++ b/SECURITY.md @@ -14,18 +14,9 @@ Baley is under active redesign and has no released version. Reports about the cu - secrets reaching logs, records or the material sent to review providers; - tampering with records that goes undetected. -## How this repository is audited - -Baley is audited with [sentinel](https://github.com/jcrenshaw-dev/sentinel), pinned as the `.sentinel` submodule, so the checks that run here are the ones of the kit version this repository was audited with. The full audit runs on the maintainer's machine, never in CI, so findings stay private until they are fixed. Once an audit has run, its record is `SENTINEL.md` at the repository root: the date, the commit it covered, what ran and how it went, and the open findings as counts by severity, with no finding's title or location. The audit only finds and records. It fixes nothing, writes no tests and commits nothing. - ## What runs on every pull request -Two workflows run on every pull request and every push to `main`. All six of their checks are required by the `main` ruleset, so a pull request cannot merge until each one passes. - -- `test.yml` runs `cargo-test`, `clippy`, `cargo-deny` and `fmt`. -- `fast.yml` is sentinel's workflow, copied from `.sentinel/ci/fast.yml`. Its `mechanical` job runs the kit's `check.sh`, which fails on cargo deny, clippy, semgrep and any audit output tracked in git, and reports the rest. Its `security-review` job runs on pull requests from this repository and has Claude review the diff against [THREAT-MODEL.md](THREAT-MODEL.md) with read-only tools. This repository is public, so the review is encrypted to the maintainer's key and the pull request comment shows only the number of findings by severity. The job fails only when the review did not run; findings do not fail it. `mechanical` also runs on `main` every Monday, so a new advisory against a dependency already in use shows up without a pull request. - -The full list of checks, which ones gate and which only report, is in the kit's README at `.sentinel/README.md`, at the version this repository is pinned to. +`test.yml` runs on every pull request and every push to `main`: `cargo-test`, `clippy`, `cargo-deny` and `fmt`. All four checks are required by the `main` ruleset, so a pull request cannot merge until each one passes. ## Fixed findings diff --git a/THREAT-MODEL.md b/THREAT-MODEL.md deleted file mode 100644 index 4ee9bc5b4..000000000 --- a/THREAT-MODEL.md +++ /dev/null @@ -1,371 +0,0 @@ -# Threat model: Baley - -Version or commit this describes: `daa2416e` on `main` -Last reviewed: 2026-10-15 - -Baley is one Rust binary that keeps AI coding agents accountable to the owner who answers for their work. Each Claude Code session starts it as an MCP server over stdio, a pre-tool-use hook runs it before each shell or file tool call, and the owner runs its command line at a terminal. It keeps an append-only, hash-chained event ledger in SQLite outside the repository. - -Every claim below was read from the code at the commit above. A claim marked `[VERIFY]` was not confirmed and needs checking. - -## Scope of an audit - -In scope: everything reachable from `crates/baley/src/main.rs` (the `serve` and `guard` modes and the command-line subcommands), the library crates `baley-core`, `baley-store` and `baley-store-sqlite`, and `install.sh`. - -Out of scope: - -- The inherited engine that `crates/baley/src/inherited.rs` lists, and code only it reaches: the review engine and its provider clients, the test runner, landing, the rail, pause, undo, milestone, why, recall and the transcript reader. Production does not reach it and Build 9 ([#30](https://github.com/jcrenshaw-dev/baley/issues/30)) deletes it. One check stays in scope: that nothing reachable from `main.rs` calls into it. `crates/baley/src/review/provider/credentials.rs` in particular still reads `OPENAI_API_KEY`, `GEMINI_API_KEY`, `DEEPSEEK_API_KEY` and a `providers.env` file, and must stay unreachable. -- `crates/baley-bench`, `spikes/`, and test code. - -## Attackers - -The main attacker is the AI agent working in the owner's Claude Code session, its main session or any subagent, together with any text injected into it through web pages, files or tool output. It already runs shell commands and edits files in the project. Its goals are to get around the process: - -- approve or rule on its own work, or get any act recorded as the owner's; -- change the policy that judges it (protected branches, the guard's settings, the sandbox settings); -- commit or push to a protected branch without the owner deciding; -- tamper with the ledger, or with what the ledger says happened; -- reach the owner's API keys or other credentials. - -Second come outside attackers: whoever controls the update source or the network path to it, a forge that holds anchor tags, and a cloned repository whose committed files are hostile. - -## What this tool reads - -**Baley's folders.** `crates/baley/src/folders.rs:45-133` resolves them from `BALEY_HOME`, `XDG_CONFIG_HOME`, `XDG_DATA_HOME` and `HOME`. `BALEY_HOME` must be absolute and becomes both folders. Otherwise: - -| Folder | Linux | macOS | -|---|---|---| -| Config | `${XDG_CONFIG_HOME:-~/.config}/crenshawdev/baley` | `~/Library/Application Support/crenshawdev/baley` | -| Home (data) | `${XDG_DATA_HOME:-~/.local/share}/crenshawdev/baley` | the same folder as config | - -An empty or relative XDG value is ignored. - -**Files.** - -- `/config.toml`, the owner's global settings. It is read whole and follows symlinks with no size cap (`crates/baley/src/settings.rs:72-109`). The guard caps it at 1 MiB (`settings.rs:44-57`). -- The ledger: `/baley.db` with its `-wal`, `-shm`, `.writer` and `.maintenance` files (`crates/baley-store-sqlite/src/checks.rs:8-14`). -- The project's `baley.toml`, in two copies. The working-tree copy gives the project id (`crates/baley/src/mcp/prepare.rs:363-371`), and policy comes from HEAD's committed copy, read through git (`crates/baley/src/committed.rs`, `crates/baley/src/policy_step/read.rs:39-62`). -- Each ancestor of the working directory or `CLAUDE_PROJECT_DIR`, lstat'ed for `baley.toml` and `.git` up to the repository root (`crates/baley/src/discovery.rs:44-97`). -- `.git`, a gitdir file and `HEAD`, read directly by the guard as a fallback when git gives no branch. These reads use `O_NOFOLLOW` and are capped at 4 KiB (`crates/baley/src/guard_hook/branch.rs:77-138`). -- Claude Code's files, under `$CLAUDE_CONFIG_DIR` or `~/.claude`: `settings.json`, `skills//SKILL.md`, `agents/.md`, and `.claude.json` (in that folder when `CLAUDE_CONFIG_DIR` is set, otherwise in `HOME`) (`crates/baley/src/host_artifacts/installed.rs:65-114`). Install, the doctor and the interview read them whole, following symlinks, with no size cap (`crates/baley/src/host_doctor/placed.rs:64-95`). The guard only derives these paths and reads none of them. - -**Git.** Every git read runs the `git` found on `PATH`: - -- `rev-parse`, `ls-tree` and `cat-file` for HEAD's `baley.toml` (`committed.rs:144-199`); -- `rev-parse`, `rev-list --max-parents=0` and `remote get-url` for checkout facts (`crates/baley/src/checkout/gather.rs`); -- `symbolic-ref` for the guard's branch (`guard_hook/branch.rs:25-42`); -- `config --get user.name` for the owner's name (`crates/baley/src/providers/identity.rs:21`); -- for anchors, `remote`, `remote get-url --push --all`, `ls-remote` and `fetch` (`crates/baley/src/ledger/forge.rs`). - -**Environment.** - -- `CLAUDE_PROJECT_DIR`: absolute, UTF-8, at most 4,096 bytes (`crates/baley/src/mcp/context.rs:170-182`). -- `CLAUDE_CODE_SESSION_ID`: at most 128 bytes. -- `CLAUDE_CONFIG_DIR`, `BALEY_HOME`, `XDG_CONFIG_HOME`, `XDG_DATA_HOME`, `HOME` and `PATH`. - -No clap argument reads the environment. - -**Standard input.** - -- In `baley serve`, MCP frames. -- In `baley guard`, Claude Code's hook JSON, read up to 64 KiB plus one byte (`crates/baley/src/hook_input/mod.rs:21`). -- `baley models import` reads curl's output, at most 4 MiB plus a trailer (`crates/baley/src/models.rs:546-565`). -- `baley skill-description` reads markdown with no limit (`crates/baley/src/main.rs`, the `Command::SkillDescription` arm of `run_command`). -- `baley config interview` reads answers. - -**Network.** The update manifest and binary from `updates.source`, and anchor tags read back through git from the remote that `git.remote` names. The section on network responses below gives the limits. - -**Not read by reachable code:** transcripts under `~/.claude/projects`, `.mcp.json`, a project's `.claude/` folder, `settings.local.json`, `CLAUDE.md`, agent files, `providers.env`, API key variables and `/proc`. An old `keys.env` in the config folder is never read (`folders.rs:59`). - -**Other users.** Every ledger open refuses a home or file that is a link, owned by another user, or has a mode wider than 0700 for the folder and 0600 for the files (`crates/baley-store-sqlite/src/checks.rs:160-188`). - -## What it writes - -| Path | How and with what mode | Where | -|---|---|---| -| ``, `` | The final folder is created 0700. Missing parents get the default mode, and an existing folder's mode is left alone. | `crates/baley/src/folders.rs:156-184` | -| `/baley.db` | Created `create_new` with mode 0600, in WAL mode, with `secure_delete = ON` | `crates/baley-store-sqlite/src/store.rs:255-262, 631, 724` | -| `/baley.db-wal`, `-shm` | Created by the bundled SQLite. Baley sets no mode, but checks 0600 on the next open. `[VERIFY]` the mode SQLite gives them on creation. | | -| `/baley.db.writer`, `.maintenance` | Created 0600 after the home check, without `O_NOFOLLOW` | `crates/baley-store-sqlite/src/queue.rs:46-52` | -| `/install.lock` | 0600, `O_NOFOLLOW`, flock | `crates/baley/src/install/command.rs:102-116` | -| `/config.toml` | Atomic replace (see below) | `crates/baley/src/config_command/set.rs:158, 241` | -| `/baley.toml` | Written by `baley init` and by `baley config set` on the project layer. A new file gets the umask mode, and an existing one keeps its mode. | `crates/baley/src/init.rs:226-238`, `crates/baley/src/replace.rs:141-148` | -| Git objects in the repository | `baley anchor` writes an empty tree and a tag object (`hash-object -w`, `mktag`). Fetching an anchor writes objects only: no refs and no `FETCH_HEAD`. | `crates/baley/src/ledger/forge.rs:189-197, 311-321` | -| `baley ledger export --to ` | Refuses an existing path. Creates the folder 0700 and its files 0600. | `crates/baley-store-sqlite/src/export.rs:72-75, 135-155` | -| `~/.local/lib/crenshawdev/baley/versions//baley` | Written to a `create_new` temporary file, set to 0755, fsynced, then renamed. The version folder is 0755. | `crates/baley/src/update/deliver.rs:93-157, 510-520` | -| `~/.local/bin/baley` | A symlink. The binary never creates it (`install.sh` does), and `baley update` swaps it with `renameat2(RENAME_EXCHANGE)`, verifies the new target, and restores the old one on failure. | `crates/baley/src/update/deliver.rs:159-195, 325-401` | - -**Outside its own folders.** - -- **Claude Code's `settings.json`.** Install writes four things into it: - - one `PreToolUse` hook (described under What it executes); - - the sandbox block: `sandbox.enabled = true`, `sandbox.failIfUnavailable = true`, `sandbox.allowUnsandboxedCommands = false`, with `sandbox.filesystem.denyRead` on the home and config folders and `sandbox.filesystem.denyWrite` on those folders, the versions folder, the placed files and the executable; - - `permissions.deny` `Read` and `Edit` rules on the same folders and files (`crates/baley/src/host_artifacts/security.rs:146-222`); - - the providers' API hosts in `sandbox.network.allowedDomains`, which the interview adds (`crates/baley/src/install/hosts.rs:58-82`). -- **The MCP registration.** Install runs `claude mcp add-json --scope user baley `, and sometimes `claude mcp remove --scope user baley` first. Claude Code writes `.claude.json`, and Baley never writes it directly (`crates/baley/src/install/registration.rs:40-57`). -- **Skill and agent stubs.** Install writes the seven skill stubs as `skills//SKILL.md` and the thirty agent stubs as `agents/.md` under the Claude Code folder, whose folders it creates with the default mode (`crates/baley/src/install/apply.rs:60-81`, `crates/baley/src/host_artifacts/installed.rs:106-114`). -- **The forge.** `baley anchor` pushes `refs/tags/baley-anchor//`. -- **Nothing else.** Nothing reachable writes shell rc files, systemd, launchd or cron units, git config or local refs. - -**How writes are done.** `crates/baley/src/replace.rs:121-187` is the atomic replace. It writes a `create_new` temporary file in the same folder, copies the target's mode, and fsyncs. It then re-reads the target with `O_NOFOLLOW` and refuses if the target changed, appeared, vanished or is a link. Last it renames over the target and fsyncs the folder. Only the final path component is checked, so parent folders are followed. Writes through a link are refused everywhere (`install/hosts.rs:109-112`, `install/stubs.rs:44-49`, `config_command/set.rs:592-600`). - -Install changes only what it can prove it wrote: - -- a stub, only when its bytes match a hash in the install record; -- the registration, only when it equals the recorded entry; -- older Baley settings entries, only on an exact match. - -Any conflict refuses the whole plan (`crates/baley/src/install/plan.rs:317`). The update refuses an existing occupant unless it holds identical bytes. One write path is weaker: `create_folder` in `update/deliver.rs:518` accepts an existing path whose `is_dir()` follows a link. - -**Standard output and error.** - -| Mode | Standard output | Standard error | -|---|---|---| -| `serve` | MCP JSON-RPC frames only. Tool results go into the model's context. | `baley:` diagnostics. `[VERIFY]` where Claude Code shows them. | -| `guard` | One `hookSpecificOutput` JSON object with `permissionDecision` `ask` or `deny` and a reason of at most 10,000 bytes, exit 0. A pass prints nothing. A deny reason reaches the model, and an ask reaches the owner. | A pass on failure prints one line, exit 0, and Claude Code sends that line only to its debug log. When standard output cannot be written, the reason goes here with exit 2, which blocks the call. | -| CLI | Results for the terminal | Errors prefixed `baley:` | - -The guard's output is at `crates/baley/src/guard_hook/render.rs:46-99` and `guard_hook/mod.rs:168-197`. - -## What it executes - -All of the binary's child processes start at one place, `Command::new` at `crates/baley/src/process.rs`, `System::command`. No launch clears the environment: each child inherits Baley's environment, plus or minus the variables its call site sets. - -| Program | Found by | When | Limits | -|---|---|---|---| -| `git` | `PATH` | Settings, checkout facts, the guard's branch, owner name, anchors | 60 s deadline (`crates/baley/src/git_process.rs:8`). The guard's calls get at most 5 s in total, in their own process group (`crates/baley/src/guard_budget.rs`). Forge calls set `GIT_TERMINAL_PROMPT=0` and cap output at 16 MiB. Local reads set `GIT_NO_LAZY_FETCH=1`. The branch read unsets `GIT_DIR`, `GIT_WORK_TREE`, `GIT_COMMON_DIR` and `GIT_NAMESPACE`. | -| `claude` | `PATH` | `baley install`: `mcp add-json` and `mcp remove` | 30 s, 64 KiB output | -| `~/.local/bin/baley update detached` | Absolute path | `baley serve` at startup, only when the global `updates.auto = true`, at most once a day | No timeout, output discarded (`crates/baley/src/update/detached.rs`, `should_start` and `launch_for`) | -| `//baley update seed` | Absolute path | After an update stages a new binary | 60 s, 4 KiB output (`crates/baley/src/update/seed.rs`, `launch_for`) | - -No reachable code runs a shell. Baley passes no `-c` overrides or `GIT_CONFIG_*` variables to git, so every git call honours the repository's own `.git/config`. That config can name programs: `core.sshCommand`, credential helpers, `core.fsmonitor` and protocol allow-lists. The anchor push passes `--no-verify`, which skips the `pre-push` hook. - -**Hooks installed into Claude Code.** One `PreToolUse` entry (`crates/baley/src/host_artifacts/hook.rs`, `EVENT`, `MATCHER`, `render`, `command` and `shell_quote`): - -- Matcher: `Bash|Monitor|PowerShell|Read|Grep|Glob|Write|Edit|NotebookEdit`. -- Command: the stable executable path, POSIX single-quoted, then `guard`. -- Timeout: 10 seconds. - -The guard launches no program except git (design 0010 GRD-R14). MCP tool calls (`mcp__baley__*`) are not in the matcher. - -**MCP registration.** `{"command": "", "args": ["serve"]}`, with no environment and no working directory (`crates/baley/src/host_artifacts/registration.rs`, `render`). The server finds the project from `CLAUDE_PROJECT_DIR`. - -**Commands, SQL and prompts built from data.** - -- **Git arguments.** - - The anchor push URL is the single output of `git remote get-url --push --all `, where `git.remote` comes from the committed `baley.toml`. It is passed to `push`, `ls-remote` and `fetch` without a `--` separator (`crates/baley/src/ledger/forge.rs`, `push_args`, `ls_remote_args`, `fetch_args` and `push_observation`). - - The remote name must appear in `git remote` output (`crates/baley/src/ledger/forge.rs`, `GitForge::call`, `GitForge::remote` and `GitForge::require_remote`). - - Tag names are built from the project id and a sequence number. -- **SQL.** rusqlite with bundled SQLite, and values are bound as parameters. `format!` SQL inserts only identifiers: compiled view names checked by `safe_identifier` (`crates/baley-store-sqlite/src/view.rs`, `safe_identifier`), registry table names, and constant PRAGMAs. The `main` or `source` schema name in `crates/baley-store-sqlite/src/view.rs`, `live_views_attached` is guarded only by a `debug_assert`. No FTS5. `[VERIFY]` that every query was covered; the trace did not read each one. -- **Regex.** None is built from input in reachable code. The MCP `document-search` operation that took a pattern is retired. -- **Prompts.** Instruction text is compiled into the binary and served by the `instruction` operation, and no prompt is built from read data. The `document` operation returns stored capture text, scope drafts and truth drafts, written earlier by agents; `document` and `context-intake` return a story's approved truths, drafted by an agent; and `document` returns a question set's question texts and recommended answers, written by an agent, with the answers and deferral reasons a session relayed or the owner gave, into the model's context unchanged. - -## What it must never touch - -- **API keys and providers.** It never reads, stores or sends API keys, and never calls a model provider. Keys stay in the owner's environment, and the owner's session sends any outside request. -- **Baley's home and config folders.** An agent must never read or write them. The sandbox, the `Read` and `Edit` deny rules, and the guard's refusal of `Read`, `Grep`, `Glob`, `Write`, `Edit` and `NotebookEdit` calls into them carry this (design 0010 GRD-R11, GRD-R13). -- **Placed artifacts.** An agent must never write the placed stubs, the Claude Code settings and registration files, the installed executable or the versions folder. -- **Owner acts.** An agent must never get an act recorded as the owner's. - - Approvals are served on the command line only, never over MCP, and `baley_apply` refuses `scope-approve` (`crates/baley/src/mcp/handler.rs`, `an_owner_approval_accepted_over_mcp_is_caught`; ADR 0044). A story's truths are approved only with `baley story truths approve` at the terminal, and no MCP spelling approves them: `context-submit` records a draft, never an approval (`crates/baley/src/refine/command.rs`, `approve`). - - An answer or deferral a session relays through `questions-answer` is recorded with actor `baley`, the session as the caller and `owner.name` in its payload. Only `baley questions answer` at the terminal records actor `owner` (ADR 0047), so no MCP call gets an act recorded as the owner's (`crates/baley/src/mcp/questions.rs`, `serve`; `crates/baley/src/questions/command.rs`, `record_answers`). - - Over MCP, only the `baley_apply` operations listed under MCP over stdio write to the ledger. -- **Data leaving the machine.** Data must never leave except in two ways: - - anchor tags pushed to the push URL of `git.remote` when the owner runs `baley anchor`; - - downloads from `updates.source`. - - There is no telemetry. -- **Git on the owner's behalf.** It never commits, pushes anything but anchor tags, changes git config, or creates local refs. -- **Sandbox settings.** Install must never write settings that weaken the sandbox. It refuses a conflicting document instead (`crates/baley/src/host_artifacts/compose.rs`, `scan` and `runs_guard`): - - `sandbox.enabled` or `sandbox.failIfUnavailable` set to anything but `true`, or `sandbox.allowUnsandboxedCommands` set to anything but `false`; - - `disableAllHooks` or `sandbox.filesystem.disabled` set to `true`; - - another guard hook or another registration under Baley's key; - - an `allowRead` or `allowWrite` entry that reopens Baley's folders or cannot be judged; - - any `sandbox.excludedCommands` entry. -- **Privileges.** It never runs with elevated privileges. Everything it writes is under `HOME`, and `install.sh` uses no `sudo`. - -## Who runs it and with what privileges - -Everything runs as the interactive user. There is no service user, no root, and no timer or login item. - -| Process | Started by | Inside Claude Code's sandbox? | -|---|---|---| -| `baley serve` | Claude Code, once per session, as a user-scope stdio MCP server | No. Hooks and local MCP servers run outside it (`crates/baley/src/host_artifacts/security.rs`, its module comment), with Claude Code's environment. | -| `baley guard` | Claude Code, before each call of the nine matched tools | No | -| `baley ` | The owner at a terminal | No | -| `baley ` run by an agent through `Bash` or `Monitor` | The agent | Yes. `denyRead` and `denyWrite` on Baley's home stop it from opening the ledger. | -| `baley update detached` | `baley serve`, when `updates.auto = true` | No | -| `install.sh` | The owner, by hand | No. It ends by running the downloaded binary as `baley install`. | - -Nothing in the code tells the owner at a terminal apart from an agent running the same command. The sandbox is the only thing that separates them. `baley scope approve` records the actor `Owner` under the name in `owner.name`, or git's `user.name` when that is unset, read in the current directory so a repository-local value applies (`crates/baley/src/providers/identity.rs`, `crates/baley/src/scope/command.rs`, `checkout`, `open` and `approve`). `baley questions answer` records the actor `Owner` under the same name (`crates/baley/src/questions/command.rs`, `record_answers`), and so does `baley story truths approve` (`crates/baley/src/refine/command.rs`, `approve`). That name is a label, not authentication. - -The control everything rests on is therefore the sandbox block and deny rules `baley install` writes. If they are missing or weakened, an agent's `baley scope approve`, `baley story truths approve` or `baley questions answer` counts as the owner's. These belong in scope as critical: - -- that install writes them correctly; -- that install refuses a document that would weaken them; -- that `baley doctor` reports drift and what an agent can reach (`crates/baley/src/host_doctor/`). - -The user can already do everything Baley does. A real escalation is either: - -- code confined by the sandbox reaching owner powers or code running outside the sandbox; -- an outside party getting code run as the user. - -## What the worst outcome looks like - -1. **An agent gets an owner act recorded,** such as approving its own scope draft or truth draft (and, in later builds, plans). Ways it could happen: - - sandbox settings that install wrote wrong, that someone weakened, or that the doctor misses; - - sandboxed code reaching the ledger; - - an MCP operation that writes an owner act. -2. **Code runs outside the sandbox on the agent's behalf.** The guard, the server and the owner's own commands all run git outside the sandbox, in the agent's working tree, honouring that repository's `.git/config`. An agent that can write `.git/config` or `.git/hooks` from inside the sandbox can name programs that git then runs with the user's full rights. One example is a `core.sshCommand`, which the owner's `baley anchor` would run. `[VERIFY]` whether Claude Code's sandbox write-protects `.git/config` and `.git/hooks`. -3. **An agent commits to a protected branch, or pushes, without the owner deciding,** through a guard bypass within the shapes the guard claims to recognise, or by changing the policy at HEAD. -4. **The ledger is rewritten without detection.** The chain is unkeyed SHA-256 (`crates/baley-store/src/chain.rs`, `DOMAIN` and `chain_hash`), so anyone who can write `baley.db` can rewrite it consistently. Only an anchor on the forge shows the rewrite, and anchors are pushed only when the owner runs `baley anchor` (Build 6, [#27](https://github.com/jcrenshaw-dev/baley/issues/27), automates it). -5. **A malicious binary is installed by an update.** Whoever controls `updates.source`, or TLS to it, controls the binary, since the manifest is unsigned ([#14](https://github.com/jcrenshaw-dev/baley/issues/14)). It then runs as the user in every new session. -6. **A secret leaks.** A secret pasted into capture text or a scope draft is stored raw in the ledger and returned over MCP into the model's context. - -What the owner would not notice: - -- a guard pass, which prints nothing; -- a declined command, which passes with nothing recorded; -- a pass on failure, whose stderr line Claude Code sends only to its debug log; -- a detached update, whose output is discarded; -- a ledger rewrite, until `baley verify` or `baley doctor` runs against an anchor. - -## Trust boundaries (where untrusted data enters) - -### 1. MCP over stdio - -`baley serve` uses its own transport (`crates/baley/src/mcp/serve.rs`, `run`). There is no HTTP listener. - -- **Frames.** One JSON line per frame, at most 4 MiB (`MAX_FRAME_BYTES`, `crates/baley/src/mcp/frame.rs`, `MAX_FRAME_BYTES`) and 128 levels deep. Each frame must be valid UTF-8 and pass a syntax check. A bad frame is answered and reading continues. An id over 256 bytes is answered with null. -- **Queue.** One call running and four waiting, with 16 MiB of frame bytes in total (`crates/baley/src/mcp/queue.rs`, `WAITING_SLOTS` and `BYTE_CAP`). -- **Client.** Its identity is self-reported, and only the `claude-code` host is accepted (`crates/baley/src/mcp/client.rs`, its module comment, `crates/baley/src/mcp/gate.rs`, `before_queue`). The identity is not authorization. -- **Tools.** Three tools: `baley_version`, `baley_query` and `baley_apply` (`crates/baley/src/mcp/tools.rs`, `tools`). - - Query serves `help`, `schema`, `instruction`, `document`, `context-intake` and `route`. - - Apply serves `capture`, `scope-submit`, the ten change operations (`project-describe`, `phase-declare`, `phase-edit`, `phase-reorder`, `phase-withdraw`, `story-declare`, `story-edit`, `story-reassign`, `story-drop` and `backlog-reorder`), `project-start`, `work-order-fail` and `work-order-retry`, `questions-answer`, and `story-refine`, `story-questions-submit` and `context-submit`. - - A spelling a tool's list marks retired, one an earlier build served, is refused `operation-unavailable` naming the build that replaces it. Any other name, such as `scope-approve`, and a call with no `operation` string, is refused `unknown-operation` (`crates/baley/src/mcp/operations.rs`, `QUERY_OPERATIONS`, `APPLY_OPERATIONS`, `lookup`, `operation_unavailable` and `unknown_operation`). -- **Arguments.** Each operation parses with serde and refuses unknown fields. `request_id` must be a lowercase hyphenated UUID, and so must a `work_order` id, on `story-questions-submit` and `context-submit` too (`crates/baley/src/mcp/work_order.rs`, `judge_request_id` and `judge_order_id`). A story id is a whole number. Capture text, a project brief and a failure reason must not be blank. Error echoes are capped at 128 bytes. - - A brief holds at most 65,536 bytes and a failure reason at most 4,096 (`crates/baley/src/mcp/work_order.rs`, `MAX_BRIEF_BYTES` and `MAX_REASON_BYTES`). Capture text, scope-submit fields and the change operations' fields have no length or count limit beyond the frame. Capture text over 4,096 bytes is stored as a payload. - - A `questions-answer` item's question id, answer and reason, and a question set's ids, question texts and recommended answers, hold at most 4,096 bytes each, and a longer one is refused `typed-content` (`crates/baley-core/src/questions/answer.rs`, `judge_call`; `crates/baley-core/src/questions/set.rs`, `judge_set`). The number of items in a call, and of questions in a set, is bounded only by the frame. A `set` id is not judged for form: one the project's `questions` view does not hold is refused `no-such-question-set`, which echoes none of it. - - Each text in a truth `context-submit` sends, its id, trigger, observer, outcome and `human_verify` among them, holds at most 4,096 bytes as written, the bound a question set's texts keep through `judge_set`, and a longer one is refused `truth-form` with nothing recorded (`crates/baley-core/src/truth/submission.rs`, `judge_truths`). The number of truths in a submission is bounded only by the frame. The analyzer's questions `story-questions-submit` sends are judged by `judge_set` as above. - - No argument supplies a path or a working directory. -- **Writes.** Every apply operation first records `checkout.seen` and `policy.effective`, and needs the project already in the ledger (`crates/baley/src/mcp/prepare.rs`, `next` and `perform`). Write preparation runs git in the project with no output cap (`crates/baley/src/process.rs`, `Launch::new`, whose output `limit` is `usize::MAX`). - -### 2. The guard hook's standard input - -- **Input.** Read up to 64 KiB plus one byte. The guard reads `tool_name`, `cwd`, `session_id`, `tool_use_id` and `hook_event_name`, plus `command`, `file_path`, `notebook_path`, `path`, `glob` and `pattern` from `tool_input` (`crates/baley/src/hook_input/mod.rs:281-318`). It never reads `transcript_path`. -- **Fields.** `tool_name` is taken as given. A missing `hook_event_name` is accepted. `cwd` must be absolute and is the base for commit targets and path checks. -- **Project.** The project comes from `CLAUDE_PROJECT_DIR` and a `baley.toml` above it, never from `cwd` (`crates/baley/src/guard_hook/context.rs:70-178`). -- **Commands.** The scan of a `Bash` or `Monitor` command is `crates/baley-core/src/guard/scan.rs`. Its stated limits are listed below. -- **Path tools.** Their targets are canonicalized, following links, compared by component and by (device, inode) identity, and denied when they cannot be resolved (`crates/baley/src/protected_paths/`). - -### 3. Command-line arguments and standard input - -Parsed by clap. - -- `baley scope approve` takes a digest of exactly 64 lowercase hex characters (`crates/baley/src/scope/command.rs`, `approve`). -- `baley story truths approve` takes a digest of exactly 64 lowercase hex characters, and `baley story refinement` a story id (`crates/baley/src/refine/command.rs`, `approve` and `refinement`). -- `baley questions answer` takes a set id and repeatable `--take`, `--answer` and `--defer` values, a text or reason allowed to begin with a hyphen, and judges them as the items a session sends (`crates/baley/src/questions/command.rs`, `terminal_items`). -- `purge` validates its hashes and reason (`crates/baley/src/ledger/args.rs`, `payload_hash` and `purge_reason`). -- `models import` checks its trailer strictly. Model ids only have to be non-empty (`crates/baley-core/src/catalog/detection/parse.rs`, `parse_body`). - -### 4. Environment variables - -Listed under What this tool reads. A relative `HOME`, or one containing `..`, is refused for the update layout (`crates/baley/src/update/installation.rs:80-107`). - -### 5. Settings files - -Parsed with the `toml` crate (`crates/baley-core/src/policy/parse.rs:509-527`). `[VERIFY]` whether it limits nesting depth. - -- **Global only:** `updates.auto`, `updates.source` (must be `https://` with no query or fragment) and `owner.name`. -- **Project only:** `git.remote`, `git.protected_branches` (default `main` and `master`), `git.on_protected` (`ask`, `refuse` or `allow`, default `ask`) and `git.guard_hard_fail`. -- **Either file:** role models and effort, `escalate_on_failure`, and `review.reviewers`. - -The schema is at `crates/baley-core/src/policy/schema.rs:197-385`. Scope is enforced at `parse.rs:776-783`. - -- **The global `config.toml`** is the owner's. Agents cannot read or write it through the sandbox. -- **The project's `baley.toml`** is committed, so it is whatever the repository says. - - The guard binds a project on any `baley.toml` with no ledger check, and takes the policy from HEAD's copy. A cloned repository's committed `git.on_protected = "allow"` or `protected_branches = []` turns commit gating off there. Push still asks. - - The guard denies `Write`, `Edit` and `NotebookEdit` on the session project's `baley.toml`. The sandbox's `denyWrite` does not list it, because install is user-level and knows no project, so sandboxed `Bash` can edit the working-tree copy. A changed policy takes effect only once it is committed at HEAD. `[VERIFY]` that this is intended. - -### 6. Git output and repository-local git config - -Git's stdout and stderr are parsed: branch names, object ids, remote URLs and HEAD's `baley.toml`. Remote URLs have userinfo stripped before `checkout.seen` records them, but query strings keep their contents (`crates/baley/src/checkout/strip.rs:13-77`). Git's stderr has control characters and userinfo removed before it is printed or recorded. Repository-local config is agent-writable from inside the sandbox unless Claude Code protects it (see worst outcome 2). - -### 7. Claude Code's settings files - -Read by install, the doctor and the interview with no size cap, following links for reads and refusing links for writes. Each must be a JSON object. - -### 8. The update source - -`crates/baley/src/update/fetch.rs`: - -- **Client.** `https_only(true)`, rustls with bundled webpki roots (not the system store), no proxy, no referer, and the Authorization header that URL userinfo would add is removed. -- **Limits.** 20 s to connect. The manifest gets 64 KiB in 20 s, and the binary 256 MiB in 10 min. -- **Manifest.** Exactly two lines (`crates/baley/src/update/manifest.rs:100-135`). Only a strictly newer version is taken. -- **Check.** The binary's SHA-256 must match the manifest, which comes from the same source and is not signed ([#14](https://github.com/jcrenshaw-dev/baley/issues/14)). -- **Redirects.** reqwest's default policy. `[VERIFY]` that `https_only` holds on every redirect hop. -- **install.sh.** Uses `curl -q --proto =https --tlsv1.2 -fsSL` with the same SHA-256 check (`install.sh:67-71, 142-171`). - -### 9. Anchors read back from the forge - -Read through git with a 60 s deadline and a 16 MiB output cap. - -- `ls-remote` output is parsed strictly (`crates/baley/src/ledger/forge.rs:238-286`). -- The tag message's first line must match the canonical JSON byte for byte, and its sequence must match the tag name (`crates/baley-core/src/forge.rs:84-123`). -- Tag signatures are ignored, and transport security is whatever git uses for that remote. - -### 10. Trusted only because Baley wrote it earlier - -- **The ledger.** Opening it runs only `PRAGMA quick_check` (`crates/baley-store-sqlite/src/health.rs:22-38`). - - Full chain verification runs only in `verify`, `doctor` and `anchor` (`crates/baley-store-sqlite/src/ledger.rs:227-278`). - - Appends extend the head stored in the project table (`crates/baley-store-sqlite/src/transact.rs:518-524`). - - Replays on MCP and in the guard return the stored answer without judging again. - - Views are read as stored. - - Payloads are opened by hash without re-hashing, and zstd decompression has no output limit (`crates/baley-store-sqlite/src/payload.rs:96-121, 317-320`). -- **The guard's remembered policy** can only add denials (`crates/baley-core/src/guard/answer.rs:104-131`). -- **A staged binary** is reused when its hash matches. -- **The install record** in the ledger drives the install plan. - -### Stated limits of the guard, not findings - -Design 0010 states these. They are not new findings: - -- **GRD-R3: only commit and push.** - - Only `git commit` and `git push` in a `Bash` or `Monitor` command are scanned, and no other git verb is covered. - - A segment counts only when its first word is `git` or ends in `/git`, so git aliases and wrappers such as `env`, `sudo`, `sh -c` or `X=1 git` are not recognised. - - The scan declines substitutions, backticks, redirects, subshells, braces, a leading comment, a NUL, an unclosed quote and a trailing backslash, and a declined command passes with nothing recorded. - - A command that moves a commit by a means outside the recognised shapes is judged as though it ran from the hook's working directory. - - A `PowerShell` call in a project is asked about, never scanned. -- **GRD-R2: outside a project.** The command guard is silent for `Bash`, `Monitor` and `PowerShell`. -- **GRD-R14: input size and the time bound.** - - Command-tool input over 64 KiB, or input that cannot be parsed, passes. The six path tools are denied instead. - - The check of the `user` chain on each guard write is unbounded, so the 10-second answer is not guaranteed on a long chain. Build 9 bounds it. -- **GRD-R6: failed git reads.** A failed git read for a detected commit passes, with a stderr line and a recorded guard failure, unless `git.guard_hard_fail` is set and the branch is provably protected. -- **GRD-R13: Bash file access and keys.** - - The guard does not check `Bash` file access. The sandbox carries it. - - The folder denials do not protect API keys in the owner's environment (CFG-R24, ADR 0039). Every child process inherits that environment. - -### Known and tracked, not findings - -- **[#14](https://github.com/jcrenshaw-dev/baley/issues/14):** release manifests are unsigned. -- **[#30](https://github.com/jcrenshaw-dev/baley/issues/30):** the parked review engine is still compiled in. -- **[#26](https://github.com/jcrenshaw-dev/baley/issues/26):** a plan's file lease is not enforced when a task closes. -- **[#27](https://github.com/jcrenshaw-dev/baley/issues/27):** anchors are pushed only by hand. -- **[#24](https://github.com/jcrenshaw-dev/baley/issues/24):** macOS is written but not run or qualified, and CI runs on Linux only. - -## Secrets that may pass through - -**Secrets that can appear in the data Baley handles:** - -- API keys or tokens an agent pastes into capture text or a scope draft; -- credentials in git remote URLs, as userinfo or query strings; -- credentials in git's stderr; -- credentials in the `updates.source` URL. - -**Where they can end up:** - -- **The ledger and the model's context.** Capture text and scope drafts are stored unredacted in the ledger and returned unredacted by the MCP `document` operation. The remedy is `baley purge`, which reminds the owner to rotate the secret (`crates/baley/src/ledger/display.rs:20`), with `secure_delete = ON`. Question texts, recommended answers, answers and deferral reasons are inline in their events, never payloads, so `baley purge` cannot remove them, and `document` returns them too: a secret written into one stays in the hash-chained record. -- **Remote URLs.** They are recorded with userinfo stripped. A secret in a query string is kept. -- **Process arguments.** The anchor push URL, including any `user:token@`, is passed in git's arguments and is visible in the process list. Only the timeout text is redacted (`crates/baley/src/ledger/forge.rs:167-175, 872-892`). -- **The terminal.** An update failure prints the `updates.source` address in full, including any userinfo (`crates/baley/src/update/command.rs:277`). Recorded update events hold codes only. -- **Guard records.** They keep the digest of the input fields the guard read, never the command text, and git's stderr excerpt is replaced by `[redacted]` (`crates/baley/src/guard_hook/record.rs:33, 356-366`). -- **Child processes.** Every child (git, claude, the detached update) inherits the full environment, including any API keys in it. Nothing scrubs a key that a command prints. - -**Secrets the tool itself holds.** None. It holds no signing key, token or keyring, and anchor tags are unsigned. Anchor pushes use the owner's own git credentials (credential helper, SSH agent or the inherited environment) with prompts disabled. File modes: the home and config folders are 0700, and `baley.db`, its lock files, exports and `install.lock` are 0600. `config.toml` and `baley.toml` keep their existing mode, or get the umask default when new.