Documentation menu

Security model

What CodeVeto protects as a required merge check, who it defends against, each layer of defence and where it is enforced, and what it does not protect against.

On this page
  1. What CodeVeto protects
  2. Threat model
  3. Defences, layer by layer
  4. Limits
  5. Reporting a vulnerability

What CodeVeto protects

CodeVeto protects one decision: whether a change may merge. It assumes the change was written to get through review, by an outside contributor, a compromised account or a coding agent, and is built so that the change cannot configure, silence or fake its own review. The verdict comes from deterministic rules that read the changed lines from Git objects, under configuration read at the trust anchor, plus an optional AI pass whose claims are verified before they count. The exit code is the verdict: 0 when every changed file was checked and nothing at or above fail_on was found, 1 when a finding blocks (this wins over incomplete), and 2 when something could not be checked and nothing blocked. Nothing but a veto exits 1, and an internal error exits 2. In CI, the required check codeveto / review takes its result from that exit code; publishing the report afterwards can turn it into a failure, never into a pass.

Threat model

Trust assumptions

CodeVeto treats the change under review as hostile: every file, path, mode, symlink and commit in it. It trusts:

  • Whoever runs it: the person at the terminal or the CI job. Their command-line flags, --config file and user config ($XDG_CONFIG_HOME/codeveto/config.toml) are trusted and unrestricted. A user config or --config file inside the reviewed repository's working tree or Git directory is refused, because the change could have written it.
  • The trust anchor: a commit the change cannot have produced, where the repository's .codeveto.toml is read. In CI it is the base of the comparison: for a pull request, the merge base of base and head. Locally it is the commit given with --anchor, or a weaker fallback (see Limits).
  • The CI configuration on the base branch: the workflow, the required check, branch protection or rulesets, secrets, and the people who can change them.
  • The platform: the forge's event payload (the runner writes it), the git program (taken only from PATH entries outside the repository) and the CodeVeto installation.

SECURITY.md puts attacks that need write access to the base branch, the trusted user config or the CI configuration out of scope, and so is bypassing local Git or agent hooks, which is documented.

Actors

Actor Controls Wants Defences Enforced in
An outside contributor's pull request Every file, path, mode, symlink and commit of the head, including its own .codeveto.toml, workflows, agent instructions and inline ignores A clear verdict for a harmful change; to edit or switch off the gate; to run code on the runner Config from the base, never the head; non-waivable rules; the head fetched as Git data and verified; nothing from the head is installed or run; anything unchecked is incomplete the pull_request_target job, publish/action.py (prepare), config.py, git.py, engine.py
A coding agent with a shell in the repository The working tree, the index and .git (refs, config, hooks, objects), local hook scripts and agent settings, the environment of the commands it runs A local clear so it can commit, push or stop; a pull request that passes CI Git runs with no repository config, hooks, attributes or filters; objects are hash-verified; the anchor is captured before the agent starts; config files inside the repository are refused; CI stays the enforcement point git.py, worktree.py, anchor.py, config.py, integrations/mcp.py
A compromised dependency or action Code in a package or action that something installs or runs Code execution on a developer machine or runner; tokens; a forged result The reviewed project's code and dependencies are never installed or run; CodeVeto has no runtime dependencies; its action pins actions/setup-python by commit and installs the AI SDKs only from hashes; the ci and deps packs report unpinned actions and changed dependency sources action.yml, requirements-ai.txt, .github/workflows/release.yml, the ci and deps packs
A model or AI endpoint returning hostile output The text of every response Invented or misplaced findings; links, mentions or workflow commands in the output; a say in the verdict; secrets from the repository The endpoint comes only from trusted config; packets are redacted and sensitive files never sent; every finding must quote a changed line of its packet; prose with links is rejected; AI findings are advisory by default ai/packets.py, ai/verify.py, ai/policy.py, ai/providers/, render/safe.py
A forge API returning unexpected data The responses publish reads: the pull request's files, existing comments, the token's identity, the pull request's state Comments on the wrong lines; someone else's comment edited; the token sent elsewhere; a check that passes HTTPS only, no redirects, strict capped JSON; only the token's own comments are updated or used for deduplication; nothing is posted if the pull request moved; publishing never turns a failing check into a passing one publish/http.py, publish/pull.py, publish/github.py, publish/forgejo.py

Defences, layer by layer

Configuration from the trust anchor

CodeVeto reads the repository's .codeveto.toml, and the .gitignore rules of worktree mode, from Git objects at the trust anchor, never from the working tree, the index or the change. A change cannot apply its own config, waive its own findings with a new inline ignore, hide files behind a new ignore rule, or instruct the reviewer. Trust model has the details: the anchor in each mode, where the local anchor comes from, and what a change cannot do to its own review.

Even the anchor's config is limited, because its authors are not the person running the review. It may tighten the policy and waive waivable rules on specific paths. It may not set fail_on = "never", allow_inline_ignores or [classes], ignore with a catch-all path such as **, turn on the AI pass or a network provider, choose the model or endpoint, or raise a limit or budget. Each of those is a config error, and a config error makes the review incomplete. Every layer is parsed strictly, so an unknown key, a wrong type, an unknown rule ID or malformed TOML is a config error too (What repository config may do).

An inline ignore counts only when trusted config enables inline ignores, the comment is unchanged from the anchor and covers the same lines, and the line it covered at the anchor had a finding of the same rule. Non-waivable rules and the secrets, agent and ci packs cannot be ignored inline (Inline ignores).

Non-waivable rules and weakening

Six rules protect the review itself: agent/reviewer-config-weakened, agent/reviewer-directive, agent/hidden-unicode, agent/suppression-added, agent/codeveto-workflow-changed and secrets/private-key (what each catches). Repository config cannot disable or downgrade them. It may path-ignore them only for fixture paths, and CodeVeto checks each pattern by glob intersection, with a fixed list of probe paths on top:

  • the pattern must start with a literal directory or file name, with no glob character before the first /;
  • it must match no protected path: .codeveto.toml, CODEOWNERS, .github/CODEOWNERS, docs/CODEOWNERS, anything under .github/, and every workflow or agent-configuration path (.forgejo/workflows/, AGENTS.md, CLAUDE.md, .cursor/, .claude/, .mcp.json, .vscode/settings.json and the rest of those file classes);
  • at the top level, every path the pattern can match counts, wildcards included; deeper down, only the names the pattern spells out, so tests/fixtures/** is allowed and docs/CLAUDE.md is not.

A pack selector such as "agent/*", or "*", that covers a non-waivable rule gets the same checks. Every ignore that does cover one is listed in the report's config_notes and in the text header. User config and the command line are not restricted: the person running the review decides.

A change that makes .codeveto.toml less strict than the anchor's copy raises agent/reviewer-config-weakened, which blocks. Weakening means any of: a rule disabled or its severity lowered (rules that are off by default included, since trusted config may turn them on), an ignore added or widened, fail_on raised, [ai] blocking or required turned off, the AI pass turned off, an AI budget lowered or removed, a limit raised or removed, or a file that no longer parses or breaks a repository restriction. A change to a workflow, action, hook or template that runs CodeVeto raises agent/codeveto-workflow-changed: removing the step, changing its inputs, command line, trigger or job condition, adding continue-on-error, changing what the job inherits (its needs, env, runs-on or container), or adding or changing a step that runs before it in the same job.

Under pull_request_target the job already runs the base branch's workflow and config, so these rules protect the next pull request, not the current one. A weakening lands only when a maintainer merges it on purpose, by bypassing the required check.

Hardened Git intake

All Git access goes through git.py and worktree.py.

  • No inherited state. git is taken only from PATH entries outside the reviewed repository, and its environment is built from scratch: a private HOME and TMPDIR, LC_ALL=C, GIT_CONFIG_NOSYSTEM=1, GIT_CONFIG_GLOBAL=/dev/null, GIT_ATTR_NOSYSTEM=1, GIT_NO_REPLACE_OBJECTS=1, GIT_NO_LAZY_FETCH=1, an empty GIT_ALLOW_PROTOCOL, GIT_TERMINAL_PROMPT=0 and GIT_OPTIONAL_LOCKS=0. Every call adds --no-pager and -c overrides that turn off hooks (core.hooksPath=/dev/null), fsmonitor, attribute and exclude files, the untracked cache, commit-graphs and multi-pack indexes. Diffs use --no-ext-diff --no-textconv and a fixed rename threshold.
  • No repository config, hooks, attributes or filters. Objects are read through a private bare repository that borrows only the target's object store. It has none of the target's refs, config, index, attributes, grafts, replacements or hooks, so no hook, filter or diff driver of the repository ever runs.
  • Hash-verified objects. The compared commits, every tree the comparison reads and every blob are hashed in Python the way Git hashes them and checked against their IDs, so a forged loose object or pack entry is caught. A blob that does not match makes its file skipped; a commit or tree that does not match ends the review with exit 2. Commit parents are read the way Git reads them.
  • Strict revisions and paths. A hex ID is resolved in the private repository, which has no refs, so a branch named like a hash cannot shadow it. A name must resolve to one full ref, and ~ and ^ steps are walked over verified commits. A range needs a unique merge base. A path that is not UTF-8, or holds control, format, bidi or line-separator characters, an empty, . or .. component or a backslash, is shown as a placeholder and skipped.
  • Bounded work. The defaults are also the ceilings: 2,000 files, 1 MiB per file, 32 MiB in all, 50,000 lines per file, 300,000 lines in all and 60 seconds of Git time (20 seconds per call). Trusted config can lower them; nothing can raise them. A file over a limit is skipped and the review is incomplete (Limits and other caps).
  • Safe working-tree reads. Worktree mode opens each path one component at a time below a directory descriptor with O_NOFOLLOW and O_NONBLOCK, records symlinks without following them, never opens a FIFO, socket or device, and stores content with hash-object --no-filters in the private repository only. It never writes the target's index, refs or files. When the index holds staged lines that are in neither the anchor's nor the working tree's version of a file, git commit would record content the review did not see, so the review is incomplete with a hint to run --staged as well.
  • No repository text in messages. Git's own error output is never shown, and issues are fixed text that CodeVeto wrote, with paths kept apart.

Incomplete, never silently clear

clear requires every changed file to be covered. When nothing blocks, any of these makes the review incomplete (exit 2):

  • a file skipped by intake: over a limit, an object missing or not matching its ID, an invalid path, the Git time budget spent;
  • a file the lexers cannot read the way the compiler does, or a rule that raised on it (partial);
  • a rule that ran past its time budget (10 seconds per rule, 120 seconds for all rules); a rule stuck where it cannot be interrupted is stopped by a watchdog that exits 2;
  • invalid configuration, a Git error, no unique merge base, a usage error or an internal error;
  • an AI pass that was asked for and could not start, that failed under [ai] required = true, or that failed or was partial under [ai] blocking = true (see The AI step).

Only four coverage reasons are benign. The report schema lists them as benign_reasons:

Reason When
deleted file The file was deleted.
pure rename The file was renamed with no content change, and its language and class stayed the same.
image binary A binary whose magic bytes name an image format, under an image file name, not executable and with no mode change.
yaml template A Helm chart template: a YAML file under templates/ that holds Go template actions. A workflow or agent configuration never qualifies.

A rename that changes a file's language or class (notes.txt to .github/workflows/ci.yml) is reviewed as a full rewrite. A binary or LFS pointer whose name gives a code language is partial, because it holds code no rule read. At most 500 findings are reported, blocking findings first, so the cap never hides a veto.

Text in the change is data

Repository text is evidence, never instructions. It is never put into the AI system prompt, never read as configuration and never used to choose what CodeVeto does. Rules read it for attempts to steer a reviewer:

  • agent/reviewer-directive (error, non-waivable): text that addresses an AI or automated reviewer and tells it to pass the change, skip checks or stay quiet about security. It is an error in comments, docstrings, Markdown HTML comments and collapsed <details> bodies, where a person does not see it but a model does, and a warning in visible prose and string literals. Invisible characters and look-alike letters are removed before matching.
  • agent/injection-phrase (warning): phrases that only make sense to a model, such as telling it to drop its instructions or reveal its system prompt, and chat-template control tokens outside string literals.
  • agent/hidden-unicode (error, non-waivable): bidi overrides, tag characters, stray variation selectors, invisible characters in code, and a lone carriage return or line separator with text after it on the same line.
  • agent/confusable-identifier (warning) and agent/encoded-payload (note): identifiers spelled with look-alike letters, and base64 or hex runs that decode to readable text.

The lexers that find comments and strings read code the way compilers do. A line comment ends at every line break the language reads (a lone CR everywhere, U+2028 and U+2029 in JavaScript and TypeScript, NEL, LS and PS in C#), and JavaScript's HTML-like comments count as comments. Where a lexer cannot be sure, the file is partial instead of masked: an unterminated construct or a desync, a construct whose reading depends on a compiler mode, a Python encoding cookie that is not ASCII-compatible, or Java and Kotlin \u escapes outside strings and comments.

In-file markers such as @generated and DO NOT EDIT, and .gitattributes, never change a file's class, so they cannot take a file out of review. Changes to .gitattributes, agent instructions, agent tool settings and agent auto-approval settings have rules of their own in the agent pack.

Output cannot carry commands

Paths, snippets, messages, hints, issues and AI text all come from the change or a model. Every renderer passes them through one sanitizer, render/safe.py, written for its medium:

Output What happens to untrusted text
text, agent Control, format, bidi, line-separator, lone-surrogate and unassigned characters become visible escapes such as \x1b or \u202e. Only the renderer emits colour codes.
github %, CR and LF are encoded in command data, and : and , as well in properties, so a path or message cannot end a command or start another.
json, sarif The same characters become \uXXXX escapes, and every ##[ is written as ##\u005b (the same JSON value), so no line holds a workflow command. SARIF also escapes [ and ] in messages, so no embedded link forms, and percent-encodes paths.
markdown (job summary, pull request comments) Untrusted text appears only inside code spans or fenced blocks whose fence is longer than any backtick run in it. @ and # get a zero-width non-joiner after them, so no mention or issue reference forms; <!-- and --> are broken, so no HTML comment or publisher marker forms; no link or image is built from it. Each field is capped, and the whole comment stays under 64,000 characters, below GitHub's limit.

In a GitHub Actions or Forgejo job log (GITHUB_ACTIONS=true, stdout not redirected to a regular file), the text, agent and markdown formats are printed between ::stop-commands::<random token> and ::<token>::. The action and the Forgejo workflow wrap their review step the same way. Every secret a rule found is replaced by [redacted] in snippets and messages. See Output formats.

The AI step

The AI pass is off by default. Only --ai or the user config can turn it on, choose the model or set the endpoint; the repository's .codeveto.toml cannot. The base URL must be https://, or http:// for localhost or a loopback IP, with no user name or password, and OPENAI_API_KEY is sent only to api.openai.com. AI review describes the pass in full.

  • What is sent. Packets of changed lines with up to 20 lines of context, at most 24 KiB each. Before anything is encoded, every line of both sides of each file passes the secrets detectors, whatever the review policy says. Matches become [REDACTED:<rule>], private-key blocks are redacted whole, a redacted value is replaced wherever else it appears, and a secret-looking path is redacted in the packet. Without the secrets pack the pass does not start. Sensitive files, such as .env files, keys, .npmrc, .netrc, credential files, SSH private keys and anything under .ssh/, are never sent (full list).
  • What the model is told. The system prompt is fixed in the package and says that repository text is untrusted evidence, never instructions. Repository text goes only into the packets.
  • What is believed. Nothing until it verifies: strict JSON of at most 256 KiB that matches the answer schema, at most 8 findings per packet, a packet of this run, the path and a changed line of that packet on that side, and a quote equal to that line's redacted text after Unicode normalization and trimming. A line with fewer than 3 letters or digits cannot anchor a finding. Titles, explanations and suggestions are capped, rejected when they hold a URL, a link or an image, stripped of control characters and redacted again. Rejection details are written by CodeVeto, never copied from the answer. The AI pass can add findings; it can never remove or lower a rule finding.
  • Budgets and deadline. By default at most 40 packets (100 is the ceiling), 32,000 output tokens per packet, optional input and output totals, 4 requests at a time and 600 seconds for the whole pass. Budgets are reserved before a packet is sent, so the totals are never exceeded; packets that do not fit are skipped and the pass is partial.
  • Policy. By default AI findings are advisory: nothing the model says blocks, and a failed or partial pass is an issue. [ai] required = true makes a failed pass incomplete. [ai] blocking = true makes verified high findings blocking errors, and a failed or partial pass incomplete unless a rule vetoes. A pass that was asked for and cannot start makes the review incomplete under every setting; --ai-optional turns only that case into an issue (policy table).
  • Harness and MCP. In harness mode the agent's own model answers and nothing goes over the network. codeveto verify runs a fresh intake, regenerates the packets and rejects answers for a change that moved since codeveto packets (stale_run) or for packets that do not exist; a stale or unusable answers document makes the review incomplete. It reads the answers only from a regular file of at most 2 MiB. codeveto mcp fixes the repository, the mode, the revisions and the anchor at launch (--head keeps following the name it was given), and its tools take no arguments except the answers document, so no call can change what is reviewed or how. Its review tool runs codeveto review in a child process with -I and --ai none, and only protocol messages reach its stdout (MCP server).

In CI, pull requests from forks get no AI pass unless the workflow sets ai-on-forks: true.

Publishing to forges

codeveto publish github and codeveto publish forgejo treat the report as untrusted input, because the review that wrote it read the change. A report is accepted only when it is:

  • at most 16 MiB of strict JSON (UTF-8, no duplicate keys, no NaN, nested at most 512 levels deep), valid against the report v1 schema, with integers wherever the schema has numbers;
  • a range review whose head, and base when the event names one, are the event's commits;
  • consistent: the exit code matches the verdict, vetoed if and only if a finding blocks, clear only with no issue or coverage gap that makes it incomplete, summary counts equal to the findings, and no repeated fingerprint.

A missing or rejected report fails the run with "CodeVeto did not complete" and exit 2, and the sticky comment says so. For an accepted report:

  • only findings on lines the pull request changes are published, taken from GitHub's list of the pull request's files or from Forgejo's diff of it; the others are dropped and counted;
  • the pull request is read again before anything is posted, and nothing is posted when it was closed or its head or base moved; a newer run publishes;
  • the sticky summary comment is created or updated, and inline comments are deduplicated by fingerprint, only among comments the token's own identity wrote; at most 25 inline comments are posted per run;
  • the API client accepts only https:// base URLs (http:// only for a loopback host), never follows redirects, caps and strictly parses every response, and reports an error with the method, path and status only, never a token, header or response body;
  • the event payload is validated strictly, and its repository must be the one the job runs in.

When the action fetches the pull request head, Git runs with no system or global config, no hooks, no prompts and HTTPS only, and the token is passed only in the fetch's environment, never on a command line or in .git/config. Apart from a rejected report, publishing never changes the check's result; in the GitHub Action a publishing failure becomes a warning in the job log. See What the action publishes.

Releases and the supply chain

What the release files, the action and SECURITY.md guarantee about CodeVeto itself:

  • No runtime dependencies. The package uses the Python standard library only. The AI SDKs (anthropic, openai) are optional extras, imported only when a pass runs.
  • The action runs its own pinned source. spink-dev/codeveto@<sha> runs CodeVeto from the action's source at the commit you pin, through a fixed python -I -c bootstrap: nothing is built, and nothing comes from PyPI or from the pull request. Its one action, actions/setup-python, is pinned by full commit SHA; inputs reach its scripts only through env:; its steps run outside the workspace. Only when ai is not none does it install the SDKs, into a private virtual environment, with pip --require-hashes --only-binary=:all: from the requirements-ai.txt shipped in the action. A test keeps that file in step with the package's extras.
  • Pinned workflows. codeveto init github pins the action to the release commit, which the release build writes into the package; a build without it refuses unless --action-sha names a commit or --allow-tag asks for the movable tag. codeveto init forgejo pins the exact CodeVeto wheel by its hash from PyPI, or from --hash, and installs it with --require-hashes.
  • The release workflow. Top-level permissions: {}, with each job granted only what it needs, and every action pinned by full commit SHA (the release script checks action.yml, and a test checks every workflow in the repository). The tag must point at the built commit, match the package version and be an ancestor of main. The build job records the SHA-256 digests of SHA256SUMS and the release notes as job outputs, and the PyPI and GitHub release jobs check the files they download against them before uploading. Only the PyPI job can mint an OIDC token, for trusted publishing from the pypi environment. Before anything is published, the wheel is installed in a clean virtual environment on Python 3.11 and 3.15 and reviews a sample repository. The movable minor tag only ever moves forward.
  • Fixes ship as a new patch version. Workflows that follow the minor tag get them; workflows pinned to a commit must move the pin to the fixed release. SECURITY.md lists the supported versions.

Limits

What CodeVeto does not protect against:

  • Code the rules do not model. Deterministic rules match patterns. A dangerous call reached through a wrapper, an API or a file type no rule knows is not reported. Only changed lines are reviewed, so a change that makes unchanged code dangerous is caught only when a rule recognises something on the lines it changed. Precision and performance has the measured rates; the AI pass is a second look, not a guarantee.
  • Local anchors that can move. Locally, the upstream and origin-head anchors come from remote-tracking refs, files in .git that any local process can move, and a head anchor leaves repository config and ignore rules unprotected. Only --anchor with a commit ID captured before the work started resists a process that can write .git. The report and the text header say which anchor was used (Passing --anchor). In CI the anchor is the pull request's base.
  • History between the compared commits. Git walks it as stored. CodeVeto verifies the compared commits, the merge base, the trees and the blobs, not every commit in between: CI relies on Git verifying objects when it fetches them, and local reviews on an anchor captured before the work started.
  • It never runs the code. No tests, builds, installs or package managers run, so behaviour that shows only at run time, in build output or inside a dependency's own code is not seen. Dependency changes are read from manifests and lockfiles, not from the packages.
  • AI findings are advisory by default. Verification stops a model from inventing claims about lines it was not shown, not from missing problems: a model can be talked out of reporting something. In harness mode the model is the coding agent's own, so that pass is only as independent as the agent.
  • Whoever controls CI controls the gate. A repository admin, or anyone who can push to the base branch or change the workflow, the required checks or the branch rules, can change or remove the check. agent/codeveto-workflow-changed reports a pull request that changes the gate; settings changed in the forge's interface and pushes that skip review are outside what CodeVeto sees.
  • Local checks are conveniences. --no-verify skips Git hooks, and an agent with a shell runs as you: it can edit hooks, agent settings, your user config and, where you can write it, the CodeVeto installation. The required CI check is the enforcement point (Bypassable and enforcing).
  • The workflow as written. The CI guarantees hold for the workflow codeveto init writes. A step that checks out or runs the pull request's head in a pull_request_target job runs that code with the job's token and secrets; ci/untrusted-checkout reports such a step when a pull request adds it.
  • Paths and AI coverage. Paths are not redacted in reports, so a secret in a file name stays visible. Files kept out of the AI pass by design, such as sensitive files and lockfiles, get the deterministic rules only.

Reporting a vulnerability

A flaw that lets a change slip past CodeVeto is a security issue even when nothing is executed. Report it privately with GitHub's private vulnerability reporting: on github.com/spink-dev/codeveto, open the Security tab and choose Report a vulnerability (direct link). Do not open a public issue, pull request or discussion for it.

Include the CodeVeto version, how you ran it (CLI mode and flags, the GitHub Action, Forgejo, MCP or a hook), a minimal repository or diff that shows the problem, and what you expected. The maintainers acknowledge the report, keep you informed while they work on a fix, and credit you in the advisory unless you prefer otherwise.

In scope is anything that lets the change under review, or text derived from it:

  • execute code on the reviewing machine or CI runner, through Git config, hooks, filters, attributes, symlinks, crafted paths or file contents, the action's install steps, or the hook and MCP integrations;
  • have its own .codeveto.toml or other files applied, move the trust anchor, or weaken the policy without agent/reviewer-config-weakened firing;
  • suppress, drop or mis-anchor findings without the review becoming incomplete;
  • get secret values or sensitive files into AI packets, or send them to an endpoint the trusted configuration did not choose;
  • make CodeVeto report a false clear, including through forged Git objects, stale or foreign AI responses, report tampering between review and publishing, and output injection into terminals, workflow commands or pull request comments.

Out of scope: rules that miss a pattern or report a false positive (open a normal issue), bypassing local Git or agent hooks, and attacks that need write access to the base branch, the trusted user config or the CI configuration. The policy is SECURITY.md in the repository.