Repository navigation
fix(policy): guard remote Git ref deletion - #294
Conversation
Signed-off-by: Yang Jianing <jntomato@qq.com>
LoopGlitch26
left a comment
There was a problem hiding this comment.
Thanks for this, it's a careful first PR: tight scope, cases on both sides, docs and the E17 numbers updated, pack version bumped, and both engines agree on every case. Normal pushes (git push origin feature, -u, HEAD:refs/heads/x, --tags) stay unheld, which is exactly right.
Two changes before it can go in, both small:
-
The dry-run exemption can be used to delete for real.
-o/--push-optiontakes the next word as its value, so ingit push -d origin main -o --dry-run git push -d origin main -o -ngit deletes
mainand passes--dry-run(or-n) to the server as a push option, but theunlesssees--dry-run/-nand lets the call through (I checked: both come outflag, notask). I'd drop theunlessaltogether: holding a real dry run for a person is a harmless false positive, letting a real deletion through isn't. That also means the benign casegit push --dry-run origin --delete old-branchshould move to the deny file with"expect": "ask"(or go). -
git push --prunealso deletes remote refs (every remote branch with no local counterpart under the refspec). Adding--prune( |$)to the alternatives covers it.
Please add deny cases for both -o forms and for --prune so they stay caught. With those two changes I ran your rule against all of the above plus the normal pushes, on re2 and the regex fallback, and it holds every deletion and nothing else.
One note, no action needed: on a 60 KB adversarial git push -q -q … the regex fallback goes from ~205 ms to ~345 ms with the new rule (re2 is unchanged at ~38 ms). That's inside the 1 s decision budget, so it's fine as is.
I'll approve as soon as those are in.
`-o`/`--push-option` takes the next word as its value, so a delete with `-o --dry-run` (or `-o -n`) at the end deleted the ref while the unless saw ` --dry-run`. Drop the unless (a held dry run is a harmless false positive) and hold `--prune`, which deletes remote refs too. Deny cases for both -o forms, --prune and the dry run; E17 507/507, 1 false alarm in 693. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01X1CADwCNvfpwqvpJc3Y4xh
|
Thanks again @TomatoYoung! To get this in today I pushed the two changes from my review on top of your commit (your commit and authorship are unchanged):
If you have local commits on the branch, I'll reopen #258 after the merge: it's meant to stay open for more harmful calls the packs let through, if you'd like another one. #259 / #266 / #267 are open too. |
…Cygnux-Labs#258) Review findings: `-4d`/`-6d` and `-d` with `-o`'s value glued on (`-doci.skip`) slipped past `-[A-Za-z]*d[A-Za-z]*( |$)`; git takes a unique prefix of a long option (`--del`, `--pru`); an all-zero source object id deletes like an empty one. The old cluster class also backtracked over one long word until the regex fallback ran out of time (deny, nondeterministic); the new class leaves `d` out. Docs list what TK-A002 doesn't see (the forms TK-D003 misses too). E17 512/512, 1 false alarm in 695. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01X1CADwCNvfpwqvpJc3Y4xh
|
Merged, thank you @TomatoYoung! TK-A002 is Tracekit's first rule from an outside contributor, and it'll ship in the next release. A second review pass also found abbreviated options ( If you'd like another: #258 is open again for more harmful calls the packs let through, and #259 (run Tracekit on an open-source agent and report what broke) is a good next one. |
|
Thank you for the detailed review and for carrying the additional edge cases through. I learned a lot from the push-option bypass, abbreviated options, and regex performance considerations. For transparency, I used OpenAI Codex as a coding assistant on the initial implementation and validation. I'm very glad TK-A002 will ship in the next release! |
|
Thanks! You're welcome to contribute more! |
|
Thanks again for contributing to Tracekit. A request: if you use a coding agent (Claude Code, Codex, Cursor, Gemini CLI or OpenCode), would you run Tracekit on it for a week and tell us how it went? After a week, |
What and why
The default coding policy pack currently flags
git pushas a remote side effect, but still allows destructive remote-ref deletion to execute without explicit confirmation.This change adds
TK-A002, which asks for human confirmation before:git push --deletegit push -dgit push origin :refs/heads/obsoleteThe rule intentionally allows
--dry-run/-ninvocations and ordinary non-deleting refspecs to avoid unnecessary false positives.The policy corpus now includes three harmful cases and two benign boundary cases. The coding policy documentation and E17 evaluation result are updated accordingly.
Local validation:
tracekit policy lint tracekit/policy2/packs/coding.yaml— passedpython -m pytest -q tests/test_signer_policy.py— 37 passed, 232 subtests passedgit diff --check— passedFull
make checkis pending Linux CI because the local Windows environment cannot run the POSIX-specific evaluation suites.Closes #258
Checklist
make checkpasses (lint, tests, build);make test-tstoo ifsdk/typescript/changedCHANGELOG.md)docs/threat-model-laptop.md,docs/threat-model-server.md)git commit -s, seeCONTRIBUTING.md)Security invariants
approval identity) is newly trusted by the signer or verifier
Evidence format
core.sig_message,ledger.make_record, the v1 schema, howthe verifier treats existing bundles) or the published v2 format
docs/sample/andtests/fixtures/) still verify, and the change is called out above