0108. Reviewing outside code: sensitive paths, fork approval and a read-only token
Source:
docs/decisions/0108-reviewing-outside-code.md. Generated at build time; edit the source file.
Date: 2026-11-24. Status: accepted (lane prsec, branch ci/contribution-security). Builds on ADR 0095.
Context
Section titled “Context”The repository is public, and outside pull requests have started to arrive (#85, and the Dependabot updates #1 to #9). The owner asked us to “be aware of code contributors, they could be injecting malware or what not”. A pull request can attack the project in three places:
- CI. A
pull_requestworkflow runs the pull request’s own workflow files and scripts. With a read-only token and no secrets that run can waste minutes, but it cannot push, release or read a secret. - The maintainer’s machine. A changed
package.jsonscript, apostinstallhook in a new dependency, abuild.rs, adocker-composemount or a.vscode/tasks.jsonruns as soon as the maintainer installs, builds or opens the branch. - The AI agents. Agents build most of Rematch, and they read
CLAUDE.md,.claude/and.mcp.jsonas instructions. A sentence added there is prompt injection with the agent’s permissions. The coach’s prompts (backend/crates/ai/prompts/) and the sidecar’s permission options do the same to the coach in production.
Decision
Section titled “Decision”- The sensitive-paths check.
.github/workflows/sensitive-paths.ymlfails when a pull request changes.github/, a Dockerfile, a compose file,deploy/ordocker/, a lockfile, package-manager or toolchain configuration (pnpm-workspace.yaml,.npmrc,Cargo.toml,deny.toml,pyproject.toml,.cargo/), the risky fields of apackage.json(scripts,pnpm,packageManager,binand the dependency lists), abuild.rs, anyscripts/directory, editor auto-run configuration,CLAUDE.md,AGENTS.md,.claude/,.mcp.json, the coach’s prompts and the sidecar’s permission files,algorithm/, orSECURITY.md. The rules and their reasons are inscripts/github/sensitive-paths.mjs, tested byscripts/github/test-sensitive-paths.mjswith fixtures of changed-file lists. - It runs no pull request code. It runs on
pull_request, neverpull_request_target, withcontents: read, the checkout action pinned by commit andpersist-credentials: false. It checks out the base commit, fetches the pull request’s commits as data, and runs the base copy of the matcher overgit diff --name-only --no-renames -z. A pull request therefore cannot weaken the matcher; it can edit the workflow file, which is why.github/is itself a sensitive path and why the check is advisory (point 4). - The override is a label. The maintainer reviews the flagged files by hand (the checklist in
docs/SDLC.md) and addssensitive-reviewed. Labels need triage rights, so a contributor cannot set it. The label counts only on the run its ownlabeledevent starts, so a commit pushed after the review fails the check again until the label is removed and added back. Pull requests opened by the owner,Terkea, are exempt. Dependabot’s lockfile and workflow updates trip the check on purpose. - Advisory, not required. The check is visible on every pull request but is not in the ruleset’s required checks. A required check that the pull request can rewrite gives false assurance: a hostile
sensitive-paths.ymlcould simply exit 0. The real gates are the ones a pull request cannot touch: fork approval (point 5), CODEOWNERS, and the maintainer as the only person who merges. Making it required would also put a failing check on every Dependabot pull request until labelled, with nothing gained, since the maintainer’s admin bypass skips required checks anyway. - Actions settings as code.
.github/settings/repo.jsongainsactions:fork_pr_contributor_approval: all_external_contributors(every outside contributor’s workflow run waits for the maintainer’s approval, not only a first-timer’s), anddefault_workflow_permissions: readwithcan_approve_pull_request_reviews: false.scripts/github/apply-settings.shreadsactions/permissions/fork-pr-contributor-approvalandactions/permissions/workflowand writes only what differs. The dry run on 2026-11-24 found the token already read-only and the approval policy atfirst_time_contributors. - CODEOWNERS names every sensitive path explicitly, so a later, narrower rule cannot hand one to someone else.
- The maintainer never runs pull request code outside an isolated container. Diffs are read with
gh pr diff; a branch is built only inside the compose containers with no host mounts beyond the checkout, never withpnpm installon the host.
Options considered
Section titled “Options considered”pull_request_targetwith a trusted workflow (recommended against). It would run the base copy of the workflow and make the check tamper-proof, but it runs with a write token and secrets in the base repository’s context. One later edit that checks out the head ref turns it into the best-known way to steal a repository’s secrets. ADR 0095 rules it out and so do we.- A required check (rejected, point 4).
- An advisory check plus fork approval and CODEOWNERS (chosen).
Consequences
Section titled “Consequences”- Each outside pull request needs one approval click before its workflows run, and one label before the sensitive-paths check turns green.
.github/settings/labels.jsongainssensitive-reviewed. Untilapply-settings.shruns after the merge, the settings drift check reports that label and the approval policy as drift.- A new kind of sensitive file needs a rule in
sensitive-paths.mjs, a fixture in its test and a line in CODEOWNERS.