Skip to content

fix: bound what the hook classifies, and ask in block mode on what it skipped - #349

Merged
blitzcrieg1 merged 2 commits into
masterfrom
fix/fail-closed-partial-classification
Oct 31, 2026
Merged

blitzcrieg1 merged 2 commits into
masterfrom
fix/fail-closed-partial-classification

Conversation

@blitzcrieg1

Copy link
Copy Markdown
Owner

Closes #348. Also fixes a hook stall that 0.10.3's 64 KiB classification bound made reachable, found while testing it.

The hook stalled on contrived input

Several patterns in the frozen files are quadratic, and the classifier runs before the tool does:

  • ENV_FILE and PRIVATE_KEY_PATH open with an unanchored [\w.~$-]*[/\\]: one long token with no slash took 0.3 s at 4 KiB and 4.7 s at 16 KiB, per pass.
  • Keyword-led alternatives such as PIPE_TO_SHELL's \bcurl\b[^|;&]*[|] scan from every keyword to the end when no separator follows: printenv repeated to 64 KiB took 34 s.
  • ENV_FILE's ^\s*\.env is quadratic on a long run of blank lines.
  • Structured arguments with no command or path key reached the ATT&CK mapper with no bound at all, in every earlier release.

The hook posts its event only after classifying, so an agent that times the hook out runs the call with nothing recorded and nothing blocked.

The frozen files are untouched (fingerprint 15846a0915769d4a). In hooks/ingest.py:

  • CLASSIFY_MAX_LEN goes from 64 KiB to 8 KiB; past it the head and tail 4 KiB are read, so the PUB-01 case (payload at the end of a long script) is still caught. The worst shape found takes about 0.55 s at 8 KiB, under 0.10.2's worst case.
  • Any [\w.~$-] run over 128 characters keeps its two ends.
  • Whitespace runs over 128 characters keep their line breaks and last indent.
  • Structured arguments share one 8 KiB budget before the ATT&CK mapper sees them.

Worst case for traits plus ATT&CK, printenv repeated:

bound time
4 KiB 0.14 s
8 KiB 0.55 s
16 KiB 2.1 s
32 KiB 8.3 s
64 KiB about 34 s

Re-swept 60 shapes at 1 MiB through _hash_tool_args: the slowest is 0.47 s.

Block mode asks on what it could not read (#348)

  • Every event whose input was shortened in a way that drops content carries tool.classification: "partial", in any mode, so an empty trait list is not read as a clean command.
  • In block mode, on a pre-execution hook, a partial call gets ask (reason tool_policy:classification_partial), or deny where the agent is not known to honour an ask, using the same capability matrix as ask rules.
  • An allow rule does not waive it; a deny rule or a DLP block still wins. Log mode and after-hooks only record.

DLP

DLP scans the whole argument JSON with no bound. Two shipped rules were not linear: image_proxy_exfil_host (10 s on 64 KiB of http://) and markdown_image_exfil (3.3 s on 64 KiB of ![a](http://, and cubic once a ? appears). Both are rewritten so that no two runs can trade characters. On 1 MiB of every slow shape, no DLP rule takes more than 0.2 s. The existing positive and benign DLP tests pass unchanged. The markdown rule no longer reads an IPv6 literal host.

Not fixed here

The quadratic patterns themselves. They are in the frozen files, so anchoring them belongs to the next ruleset change (with #55, #345, #346), after which the bound can grow again.

Openers doc

docs/commercial/outreach-openers.md: opener 5 said 5 of 178 ATLAS techniques; ATLAS 2026.10 lists 221 and the five emitted ids are unchanged, so it now says 5 of 221, about 2%. Opener 2 is brought in line with the code (the tools/list fingerprint is taken at the MCP proxy, not per session) and with what the postmark-mcp post actually says.

Checks

  • Ruleset fingerprint unchanged: 15846a0915769d4a
  • ruff check agentmetry tests: clean
  • agentmetry benchmark: 26 of 26 detected, 0 missed, 0 false positives
  • New tests/test_fail_closed_partial.py (29 tests); full suite locally 2062 passed, 6 skipped, 3 failed, the three being the dogfood machine's documented cases: the OTel and trail tests pass with .env moved aside, and the README count (updated to 2069) is 2 high locally from gitignored launch entries

🤖 Generated with Claude Code

blitzcrieg1 and others added 2 commits October 31, 2026 12:29
… skipped

0.10.3 raised the classification bound from 4 KiB to 64 KiB. Several
frozen patterns are quadratic on contrived input, and the classifier runs
before the tool does: one long token with no slash held the hook for
minutes, and `printenv ` repeated to 64 KiB took 34 s. The hook posts only
after classifying, so an agent that timed it out ran the call with nothing
recorded and nothing blocked. Arguments with no command or path key reached
the same patterns with no bound at all, in every earlier release.

The hook now classifies 8 KiB, and past that the first and last 4 KiB. Runs
of path-like characters over 128 keep their two ends, whitespace runs keep
their line breaks, and structured arguments share one 8 KiB budget. The
worst shape found takes about 0.55 s at 8 KiB; 60 shapes at 1 MiB finish
under 0.5 s. The frozen files are untouched (fingerprint 15846a0915769d4a).

Anything shortened in a way that drops content now carries
tool.classification "partial", and with tool_policy_mode block a partial
call asks on a pre-execution hook, or is denied where the agent ignores an
ask (#348). A deny rule or a DLP block still wins; log mode only records.

Two DLP rules on unbounded input were not linear either:
image_proxy_exfil_host took 10 s on 64 KiB of `http://`, and
markdown_image_exfil backtracked cubically. Both rewritten; no DLP rule
takes more than 0.2 s on 1 MiB of any shape that was slow.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…S release

Opener 5 said 5 of 178 ATLAS techniques. ATLAS 2026.10 lists 221, and the
five ids emitted are unchanged in it, so the line now says 5 of 221, about
2%, and names the release. Opener 2 still credited a post with "fifteen
clean releases" and a 1.0.16 one-line change, which the private queue
corrected on 2026-10-23, and said the tools/list fingerprint is taken per
session when it is taken as the listing passes through the MCP proxy.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@blitzcrieg1
blitzcrieg1 merged commit 0424330 into master Oct 31, 2026
11 checks passed
@github-actions github-actions Bot locked and limited conversation to collaborators Oct 31, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Block mode should ask on input too large or opaque to classify

1 participant