Skip to content

fix(policy): guard remote Git ref deletion - #294

Merged
LoopGlitch26 merged 4 commits into
Cygnux-Labs:mainfrom
TomatoYoung:agent/issue-258
Oct 18, 2026
Merged

LoopGlitch26 merged 4 commits into
Cygnux-Labs:mainfrom
TomatoYoung:agent/issue-258

Conversation

@TomatoYoung

Copy link
Copy Markdown
Contributor

What and why

The default coding policy pack currently flags git push as 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 --delete
  • git push -d
  • deletion refspecs such as git push origin :refs/heads/obsolete

The rule intentionally allows --dry-run / -n invocations 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 — passed
  • python -m pytest -q tests/test_signer_policy.py — 37 passed, 232 subtests passed
  • E17 policy corpus — 503/503 harmful cases caught; 1/694 existing benign false positive
  • git diff --check — passed

Full make check is pending Linux CI because the local Windows environment cannot run the POSIX-specific evaluation suites.

Closes #258

Checklist

  • make check passes (lint, tests, build); make test-ts too if sdk/typescript/ changed
  • a regression test covers the change
  • user-visible changes are described above (release notes are written at release time; don't edit CHANGELOG.md)
  • docs updated if behaviour or a security claim changed (docs/threat-model-laptop.md,
    docs/threat-model-server.md)
  • every commit is signed off (git commit -s, see CONTRIBUTING.md)

Security invariants

  • the agent still never holds a signing key or assigns sequence numbers
  • nothing an agent-controlled process supplies (isolation level, fail mode, gap/tamper records,
    approval identity) is newly trusted by the signer or verifier
  • gaps are still signed, never silent; a check that cannot run warns instead of passing
  • no verification code is shipped inside a bundle

Evidence format

  • this change does not touch the frozen formats: v1 (core.sig_message, ledger.make_record, the v1 schema, how
    the verifier treats existing bundles) or the published v2 format
  • or, if it does: the issue explicitly asks for it, existing bundles (including docs/sample/ and
    tests/fixtures/) still verify, and the change is called out above

Signed-off-by: Yang Jianing <jntomato@qq.com>

@LoopGlitch26 LoopGlitch26 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:

  1. The dry-run exemption can be used to delete for real. -o/--push-option takes the next word as its value, so in

    git push -d origin main -o --dry-run
    git push -d origin main -o -n
    

    git deletes main and passes --dry-run (or -n) to the server as a push option, but the unless sees --dry-run / -n and lets the call through (I checked: both come out flag, not ask). I'd drop the unless altogether: 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 case git push --dry-run origin --delete old-branch should move to the deny file with "expect": "ask" (or go).

  2. git push --prune also 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.

LoopGlitch26 and others added 2 commits October 18, 2026 23:12
`-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
@LoopGlitch26

Copy link
Copy Markdown
Member

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):

  • dropped the dry-run unless, so git push -d origin main -o --dry-run / -o -n are held
  • added --prune( |$)
  • deny cases for both -o forms, --prune, and the dry run (moved over from benign); E17 is now 507 of 507 held, still 1 false alarm in 693
  • merged main, which fixes the release-dry-run failure (your branch predated a lockfile fix; nothing to do with your change)

If you have local commits on the branch, git pull first. I'll merge once CI is green.

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.

@LoopGlitch26
LoopGlitch26 marked this pull request as ready for review October 18, 2026 17:47
…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
@LoopGlitch26
LoopGlitch26 merged commit b128350 into Cygnux-Labs:main Oct 18, 2026
30 of 31 checks passed
@LoopGlitch26

Copy link
Copy Markdown
Member

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 (--del, --pru), short-option clusters (-4d) and the all-zero source id, so I added those on top of your commit with cases and a timing test.

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.

@TomatoYoung

Copy link
Copy Markdown
Contributor Author

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!

@LoopGlitch26

Copy link
Copy Markdown
Member

Thanks! You're welcome to contribute more!

@LoopGlitch26

Copy link
Copy Markdown
Member

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?

pip install -U tracekit-ai
tracekit audit --since 7d      # read-only: what it would have held in your last week (Claude Code history)
tracekit init --dev --v2       # then record and guard from now on

After a week, tracekit report --share prints counts only (no commands, paths or content). Post it in #385 with anything that got in your way: a false alarm, a confusing message, something slow. If you find a problem, you're welcome to fix it too: say so on #385 and it's yours.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Policy packs: add a harmful tool call the packs let through

2 participants