kontext-cli icon indicating copy to clipboard operation
kontext-cli copied to clipboard

:Independent verification pass at 59ec3b4 — design notes, planted-defect results (7/11 caught), tests included

Open Trenyx opened this issue 3 months ago • 3 comments

Kontext version

v1.2.0 (main @ 59ec3b4)

OS and architecture

Command

kontext hook --agent claude   (PreToolUse, tool_input.command = "rm  -rf /", policy forbids "rm -rf /")

Expected behavior

A forbid on rm -rf / also matches obvious variants of the same command (extra whitespace, quoting), or the docs state plainly that policies match raw input text.

Actual behavior

rm -rf / (two spaces) is allowed: policy evaluation runs on the raw tool_input, and the only normalizer (riskclassifier.NormalizeCommand) feeds the advisory classifier, not the policy path. Reproduction: TestIA4_NoCanonicalizationLayer in https://github.com/blu400codes/trenyx-verify-002-kontext/tree/main/02-independent-tests.


Hi — I run a small verification practice and used this repo as a public sample of the method: an AI-assisted Go codebase (121 of 279 commits Claude co-authored) guarding AI agents, with a serious test suite. No relationship, nothing commissioned. Everything below is reproducible: https://github.com/blu400codes/trenyx-verify-002-kontext (attack plan hashed and posted publicly before I read a line; 27 blind tests; 11 planted defects run against your suite).

First, the headline is good: the decision core is fail-closed by construction and your tests caught 7 of 11 planted semantic defects — including every plant on the Cedar mapper, the breaker, policy metadata validation, forbid-wins, and the observe-mode reason text. That's the strongest suite I've put this method against. The four that escaped: an unknown hook-mode string defaulting to observe (ParseMode's error branch has no test), the Cedar evaluator not refreshing when the deployment identity changes, a silently lost deferred ledger record (no test asserts the failure is logged), and a command truncated before policy evaluation (no long-command policy test).

Design notes, no security impact claimed:

  • Policy matching runs on raw tool input; rm -rf / (two spaces) is not matched by a forbid on rm -rf /. Inherent to Cedar-on-raw-input, but worth a prominent line for policy authors, or normalized context fields (argv-split, whitespace-collapsed).
  • Deferred decision records are best-effort by design (answer first, write later, failures logged and counted, not retried); the README's "records the decision and outcome in an authorization ledger" reads stronger than that. One sentence would align them.
  • Remote-posture outage handling fails closed only while the on-disk policy cache is readable and claims enforce; a missing cache fails open (documented). The guarded agent runs as the user who owns that file. The README correctly defers this to a sandbox — a sentence next to the enforce switch saying the sandbox is load-bearing would help operators.
  • Under static enforce, an expired cache denies everything (enforcement_not_ready) — intended fail-closed, but the offline symptom and maxAge deserve a doc line.

Two enforcement-relevant items went through your private advisory channel per SECURITY.md rather than here. Findings write-up publishes in the repo above after a fix or ~14 days; corrections welcome — tell me what I got wrong.

Relevant logs or screenshots

trenyx_cedareval_test.go:113: variant 'rm  -rf /' (double space) was ALLOWED: raw-input matching, no canonical form

Baseline: go test -count=1 ./...  → 37 packages ok, 0 failures (Go 1.25, commit 59ec3b4)
Planted-defect matrix: 7 / 11 caught — see 03-planted-defects/matrix.md in the linked repo

Trenyx avatar Aug 26 '26 18:08 Trenyx

Thanks for putting this together, and for sending the enforcement findings through private reporting. We reproduced the raw-input behavior at 59ec3b4.

This path does not involve the risk classifier. riskclassifier.NormalizeCommand prepares commands for the advisory SVM and does not collapse whitespace. Cedar evaluates the raw tool_input.

@hasandemirkiran, tagging you because the report mentions the classifier normalizer. @tumberger, tagging you for the Cedar input contract.

The reproduction uses a synthetic exact-string policy. Did you see the same behavior with a Kontext-distributed policy, or only in TestIA4_NoCanonicalizationLayer? We are auditing the policies we currently distribute before deciding the impact.

Either way, we should document that command matching uses raw input and add regression coverage. We will separately decide whether policies need a derived command representation.

Thanks again- the test repository made this easy to verify.

michiosw avatar Aug 27 '26 09:08 michiosw

Thanks, and agreed on all of it.

To your question directly: only in TestIA4_NoCanonicalizationLayer, against a synthetic exact-string policy (forbid ... when context.command == "rm -rf /"). I used string equality deliberately because it's the strictest case and isolates the mechanism — I didn't have your distributed policies, so I can't speak to their exposure. If those match on tool name plus structured fields, or use like/contains rather than == on the raw command, the whitespace case may not reach them at all. That's exactly the audit you're doing, and sizing the impact from the distributed set before acting is the right call.

You're right about NormalizeCommand — it rewrites URLs/IPs/base64 for the SVM and never touches whitespace, so it wouldn't help the policy path even if it were wired in. The "normalized context fields" note was a suggestion for a new derived representation, not a claim that the existing normalizer does it; whether an argv-split / whitespace-collapsed command view is worth the contract change is a call only you can make.

Documenting raw-input matching plus regression coverage sounds right regardless of how the distributed-policy audit lands. When the public write-up goes up (after the enforcement items' window) I'll note that the repro is synthetic-policy-only and that real impact depends on distributed-policy shape.

Thanks for the fast, precise triage.

Trenyx avatar Aug 27 '26 17:08 Trenyx