S08-09 - Flagging Risky Changes
Purpose: The changed paths that wb diff and the session summary flag,
because the host or CI may run them (SEC03-no-host-execSEC03-no-host-exec: No host code execution via returned workNothing the agent produces executes on the host without an explicit user action; returned changes to files the host may later execute are flagged.).
Design
Section titled “Design”What is flagged
Section titled “What is flagged”wb diff and the end-of-session summary flag changed paths that the
host or CI may execute or that change how git behaves. Each flag names
its rule (NFR06-explained-refusalsNFR06-explained-refusals: OperabilityEvery refusal names the rule that caused it and how to change it.). A flag informs the user, and no
land waits on one. The flagger is internal/riskpath, and I697I697 (open): wb diff and wb land: the landing checks, the checked fetch, the scratch repository, and the returned-work record in wb-hostdPackage M4.5 of docs/implementation-plan.md, part 2 of 3 (M4.5b). adds it to wb diff.
A name with a slash matches the last components of a path at any
depth, a directory matches itself and every path below it at any
depth, and * matches within one name.
| Rule | Named files and directories |
|---|---|
hooks |
.husky/, .githooks/, .git-hooks/, .hooks/, .lefthook/, lefthook.yml, lefthook.yaml, .lefthook.yml, .lefthook.yaml, lefthook-local.yml, .pre-commit-config.yaml, .pre-commit-hooks.yaml, .overcommit.yml |
shell-env |
.envrc, .env, .env.*, .profile, .bashrc, .bash_profile, .zshrc, .zshenv, .zprofile, flake.nix, shell.nix |
build-entry |
Makefile, GNUmakefile, *.mk, Justfile, .justfile, Taskfile.yml, Taskfile.yaml, Rakefile, Gemfile, build.gradle, build.gradle.kts, settings.gradle, settings.gradle.kts, CMakeLists.txt, meson.build, setup.py, setup.cfg, pyproject.toml, noxfile.py, tox.ini, conftest.py, build.rs, Package.swift, Cargo.toml, BUILD, BUILD.bazel, WORKSPACE, MODULE.bazel, .bazelrc, Dockerfile, docker-compose.yml, docker-compose.yaml, compose.yml, compose.yaml, Vagrantfile, Brewfile, go.work, .npmrc, .yarnrc, .yarnrc.yml, .pnpmfile.cjs, bunfig.toml, .cargo/config, .cargo/config.toml |
toolchain |
.tool-versions, mise.toml, .mise.toml, mise.local.toml, .mise.local.toml, mise.*.toml, .mise.*.toml, .mise/, .config/mise/, .config/mise.toml, .nvmrc, .node-version, .python-version, .ruby-version, .go-version, rust-toolchain, rust-toolchain.toml, .sdkmanrc, .bun-version, mise/config.toml, and the go and toolchain lines of go.mod |
package-scripts |
the scripts and bin of package.json |
agent-config |
.vscode/, .idea/, .claude/, .cursor/, .devcontainer/, .zed/, .gemini/, .codex/, AGENTS.md, CLAUDE.md, CLAUDE.local.md, GEMINI.md, .mcp.json, .cursorrules, copilot-instructions.md, .devcontainer.json, .dir-locals.el, .nvim.lua, .exrc |
wraithbox-config |
.wraithbox/, Wraith Box’s own repository configuration (S09-policy-credentials-auditS09-policy-credentials-audit: Policy, Credentials, Certificates and AuditWhere policy comes from, how secrets are held, how TLS inspection is trusted, and what is recorded.) |
ci |
.github/workflows/, .github/actions/, .circleci/, .buildkite/, .gitlab/, .azure-pipelines/, .woodpecker/, .forgejo/, .gitea/, .gitlab-ci.yml, Jenkinsfile, azure-pipelines.yml, .travis.yml, codefresh.yml, bitbucket-pipelines.yml, cloudbuild.yaml, action.yml, action.yaml, .github/dependabot.yml, CODEOWNERS |
git-behavior |
.gitattributes, .gitmodules (so submodule URL changes), .lfsconfig, and .git/ and git~1/ should one arrive |
lockfile |
package-lock.json, npm-shrinkwrap.json, yarn.lock, pnpm-lock.yaml, bun.lock, bun.lockb, go.sum, go.work.sum, Cargo.lock, Gemfile.lock, poetry.lock, uv.lock, Pipfile.lock, Package.resolved, composer.lock, mise.lock, flake.lock, pubspec.lock, mix.lock |
These rules come from the git file modes, the link targets, and the tree:
| Rule | What it flags |
|---|---|
executable |
a new executable, and an executable bit set or cleared |
submodule |
a new or changed gitlink. Its object ID is shown whole and escaped. Only the cap on a detail cuts one (below), and that cap is longer than any git object ID |
link-target |
a symbolic link whose target leaves the repository or can’t be resolved, changed or not (below) |
collision |
a path that is the same file as another path of the tree on the host (below) |
mode |
a file mode git doesn’t write |
unparseable-path |
a path that git can’t store in a tree: empty, not UTF-8, with a NUL byte, or with an empty, . or .. component. Also a name that Windows reads as another name: one with a backslash, a colon, or a tilde before a digit, as in GITMOD~1. Also a name longer than any host opens (below) |
unchecked |
the links or the collisions when a limit or a budget dropped them, a path over a limit, and a check without the tip’s tree (below) |
How paths are matched
Section titled “How paths are matched”Paths are guest bytes. No rule trusts their form. The flagger
compares a path in a form at least as broad as the name comparison of
APFS, HFS+ and NTFS, so a name that the host opens as a flagged file
gets that file’s rule. MAKEFILE and .Github/workflows/x.yml are
flagged as Makefile and .github/workflows/x.yml. The form:
- is fully case folded, as APFS compares names, so
Makefilewith the ligaturefiisMakefileandßisss; - is NFC after case folding, so the NFC and NFD forms of a name match;
- drops the code points HFS+ ignores in names, as git does;
- drops trailing dots and spaces of each name, as Windows does;
- replaces invalid UTF-8 with U+FFFD, so the rest of the path still matches.
The form doesn’t map the names NTFS reads as other names, such as the
8.3 short name GITMOD~1 or the stream Makefile::$DATA. Those are
flagged unparseable-path instead.
A path the flagger can’t parse is flagged unparseable-path and still
matched against the other rules. The flagger fails closed. It
flags a link target or file it can’t read, and never takes one as
harmless.
Symbolic links
Section titled “Symbolic links”The flagger takes the tree’s links into account. With .claude a link
to cfg/:
- the link itself is flagged, by the rule of the directory at its name;
- a change below its target,
cfg/settings.json, is flagged by the same rule, whether the link changed or not, and through a chain of links; - a changed link whose target matches a rule is flagged by that rule,
and so is a changed link to
package.jsonorgo.mod; - a changed link at
package.jsonorgo.modgets the manifest’s rule, and a file that a link makes visible at one of those names has its content read as that manifest; - a changed link at the first part of a name of two parts, such as
.github,.cargo,.configormise, gets that name’s rule, because its target supplies the rest of the name; - a link that the target of another link passes through is flagged by
the rules of that other link’s name when the guest adds it, deletes
it, or gives it another target. With
.claudea link tox/cfg, a new target for the linkxis flaggedagent-config.
The flagger doesn’t look below the target of a changed link for the
names of rules. When the link tools is retargeted from v1 to v2,
tools/Makefile shows v2/Makefile, and the flagger doesn’t flag
tools for it (I989).
A link’s target is resolved by its text. A target that is absolute,
names a Windows drive or separator, climbs out of the repository with
.., or uses .. after a name (that name may itself be a link that
leads elsewhere) gets link-target. So does a link reached on the way
to such a target, and a loop of links. A link of the tree whose
target can’t be resolved, or can’t be read, gets link-target even
when it didn’t change, because a change below its target would be
visible at its name unseen.
Collisions
Section titled “Collisions”Paths of one tree that compare equal in the form above are one file
on APFS and NTFS. A changed path, or one of its directories,
that collides with another path of the tree is flagged collision,
once, at the first part that collides. The detail names at most
eight of the other spellings of that part and counts the rest. It
doesn’t repeat the directory they are in.
What can’t arrive
Section titled “What can’t arrive”Git itself never transfers .git/hooks or repository configuration, so
those cannot arrive this way. The object checks on push refuse a tree
that tries (.git, .GIT, git~1). They also refuse a symlinked
.gitmodules or .gitattributes.
How the flagger reads a change
Section titled “How the flagger reads a change”The flagger takes executables, links, and submodules from the git file mode. Its input is the list of changes, each with its path, its old and new mode, and its old and new object ID, the paths of the tip’s tree, and a reader of blob content with a size cap. It reads the content where the path alone doesn’t say enough:
- link targets;
package.jsonscriptsandbin, by their exact keys, naming the changed keys only;- the
goandtoolchainlines ofgo.mod.
A blob over its cap, unreadable, or not in the expected form is flagged as changed. The flagger returns paths and details as the guest wrote them, and the caller escapes them with its terminal filter.
Limits
Section titled “Limits”Every input is guest bytes. The flagger bounds its work, its memory,
and its output by construction (SEC13-bounded-resourcesSEC13-bounded-resources: Bounded resourcesCPU, memory and disk of each VM are capped.). It counts
work in steps. A step is one byte folded, hashed, compared, copied or
read, and work that isn’t a byte has a fixed cost in steps. Each limit
is a constant of internal/riskpath, and the code has the values.
A limit may cost the guest’s own files their checks. It never costs another file its flag. So a limit takes work away in a fixed order, and each line below has a test with the inputs that the reviews of PR966PR966 (open): feat(go): add the risky-path flagger with its S08-09 matching rulesReturned work can change files that the host or CI runs on its own, so wb diff and the session summary will flag those paths for the user to read first. used against it.
What no limit takes away
Section titled “What no limit takes away”The flagger checks every change by its path and its modes alone: the problems of its path, the mode rules, the name rules, and the manifest rule at its own name. This has no budget and needs none. It reads each byte of the changed paths a fixed number of times, so its cost is linear in the size of the changes. The caller caps the size of the changes it reads into a check, as part of I697I697 (open): wb diff and wb land: the landing checks, the checked fetch, the scratch repository, and the returned-work record in wb-hostdPackage M4.5 of docs/implementation-plan.md, part 2 of 3 (M4.5b)..
Matching a name against the rules doesn’t fold it. Every name of a rule is ASCII, so one pass over a name decides whether it folds to ASCII, and gives that form when it does. A fuzz property holds this match to the result that the fully folded path gives.
A name longer than MaxName UTF-16 units can’t be opened on any host.
The flagger never folds one. A changed path with such a name is
flagged unparseable-path. The unchanged paths with one that the
collision check comes across are counted in one unchecked flag.
Following links has the budget MaxLinkSteps and the count limit
MaxLinks. A link that is both a change and a tree entry counts once.
Only the links spend this budget, and a changed path where a link leads
to it. A tree entry that isn’t a link spends none of it. Neither does a
change that the links don’t lead to.
Over the budget or the count limit, the flagger follows none of the
links. The check then returns one unchecked flag with no path that
names the limit, and:
- each changed link is flagged
link-target, since nothing looked at its target; - each link of the tree at a name of a rule, at the first part of such a name, or at the name of a manifest is flagged by that rule as not followed. A change below its target wasn’t matched there.
Within the limits:
- a changed path longer than
MaxPathbytes or with more thanMaxDepthparts is flaggedunchecked, keeps the flags of its own path and modes, and is left out of the links and the collisions; - a link of the tree over one of those limits, or with a name over
MaxName, is flaggeduncheckedand by the rules of its own name, and isn’t followed; - a path that following links would build obeys the same limits. The
flagger doesn’t build a longer one, and flags the change or the link
link-target; - a change is matched at a capped number of paths through links. One
that is visible at more is flagged
link-target, and also by each rule that a link of the tree is at a name of, so links that sort first can’t take a rule away; - links with the same name in the matching form, the same target and the same problem are followed as one, so they cost one link;
- each link target blob is read once, even when many links share it.
Collisions
Section titled “Collisions”Collisions are checked after the links. They have the budget
MaxCollisionSteps and the count limits MaxChanges and MaxTree.
Over one of them, the collisions aren’t checked, and one unchecked
flag with no path names the limit. Every other flag stays.
The flagger folds a name once in a check, and an unchanged path only up
to its first part that the changed paths don’t share. A large tree of
unchanged files is checked in full.
Manifests and output
Section titled “Manifests and output”Each distinct pair of old and new package.json or
go.mod blobs is read and compared once, even when many changes share
it. A deleted manifest is compared with no content. The reads have the
budget MaxManifestSteps, which they overrun by less than two blobs of
the size cap MaxManifest and two reads. Over it, no comparison is
kept: every manifest is flagged by its rule as not compared, and one
unchecked flag says why.
The number of flags is at most a fixed number for each change and each
link of the tree, plus a fixed number for the check. A flag’s detail
is at most MaxDetail bytes. The flagger cuts a longer one at a code
point and ends it with the number of bytes left out, and it ends a list
with the number of names left out.
In the links and the collisions, each step is paid for before the work it counts, and both stop within their budget. One test counts the bytes that were folded against the steps paid for them. The result is the same for any order of the input, also when a budget runs out.
A check without the tip’s tree is flagged unchecked too, because it
can’t see the links and collisions of the unchanged paths.
The package’s tests hold a check to these bounds by counting steps, flags, and detail bytes, never time. A fuzz property checks the bounds with the limits of a check and with small ones.
Another fuzz property compares the result with a slow model. The model resolves the links of the tree before and after the changes as a case-insensitive host does. A path that a rule names and that shows another file after the changes must have a flag of that rule.
The summary groups flags by rule. A project that often changes its CI or agent configuration gets many (X07-git-round-tripX07-git-round-trip: Git round tripRemote helper over vsock, read-only upload-pack, restricted receive-pack into the landing repository, flagging of risky paths.).
Status: Draft