Repository navigation
Description
The problem
Today, tool content over maxContentBytes (256 KiB, internal/adapter/modelhook/modelhook.go:65) is never inspected by the checker. onContentTooLarge (modelhook.go:266) handles it as:
- Advisory mode: log a WARN ("content exceeds the inspection size bound; NOT inspected") and pass — the content reaches the model unchecked.
- Enforcing mode (block/sanitize): route through
onCheckerError— fail-open WARNs and skips (content unchecked), fail-closed blocks. In no case is the oversized content actually inspected.
The rationale for the bound was the "induced fail-open defense": an attacker could emit a huge tool result to time out / error the checker and slip through. That's a real concern, but the current resolution — don't inspect it at all — means a legitimately large fetched page, a big MCP response, or a large file read that carries an injection payload in its tail is never checked. For a security control, "too big to check" is a gap an attacker can exploit by padding a payload past the bound, and a gap that fires on benign large content too.
Proposed change
Oversized content must still be inspected. Two viable approaches (the issue should pick one, possibly both as a configurable strategy):
Option A — compact, then check
Summarize/compact the content down under the inspection bound, then run the checker over the compacted form. This mirrors the harness's existing compaction discipline (the agent loop already compacts conversation history). Caveats to address in the design:
- A compaction step is itself an LLM call (cost + another failure surface), OR a deterministic truncation (lossy, could drop the payload).
- The checker rubric must be told it's reviewing a compacted artifact, not the verbatim content — otherwise a "safe" verdict on the summary doesn't imply the full content was safe (the dangerous portion could have been summarized out).
- The compaction itself is a trust transfer: the compactor chooses what to keep. If the compactor is attacker-influenced it could drop the payload. A deterministic compactor (head + tail + middle-sampling, or a sliding window) avoids that but is lossy.
Option B — check it in full (raise or remove the bound)
Accept the cost and just send the full content to the checker. The maxContentBytes bound was a defense against a checker timeout on huge input, but the checker already has a 30-second hard timeout (guardrailCheckTimeout, engine/agent/guardrailcheck.go:14) and the fail-open/closed path catches a timeout. Raising the bound substantially (or removing it and relying on the timeout + fail-closed for rules that need it) means real large content gets inspected. The induced-fail-open concern is then handled by the existing fail-closed knob (#169's global toggle) rather than by skipping the check.
Recommendation
Lean toward Option B as the baseline (remove the skip-inspection behavior; the 30s checker timeout + the fail-open/closed posture already bound the failure mode) with Option A (deterministic compaction) as a future enhancement for operators who want to cap checker cost on huge inputs without losing coverage. The key invariant either way: the checker must actually see the content — "too big to check" is not an acceptable terminal state for a security control.
What changes in code
Runner.check(modelhook.go:201): remove or rework thelen(content) > maxContentBytesearly return intoonContentTooLarge.onContentTooLarge(modelhook.go:266): either delete (Option B) or convert to a compaction-then-check path (Option A).- If Option A: a compaction strategy (deterministic truncation preferred initially) + a rubric amendment telling the checker it's reviewing a compacted artifact.
docs/adr/0021-guardrails.md(Cost model & the per-session budget → themaxContentBytesbullet) +docs/architecture.md.- Tests: oversized content is inspected (not skipped); the 30s timeout still bounds a pathological input; fail-closed still blocks on a checker timeout.
Out of scope
- The
maxCheckscall-count cap — removed by guardrails: remove maxChecks per-session call-count cap (security footgun) #168. - The checker-down posture toggle (warn/fail) — guardrails: add global checker-down posture toggle (warn default / fail opt-in) #169; this issue interacts with it (fail-closed on a timeout from huge input is the guardrails: add global checker-down posture toggle (warn default / fail opt-in) #169 toggle's job), but the inspection-skip is a separate defect.
- The
minContentBytesPost skip — that one is a deliberate cost gate for trivially-short results that cannot carry an injection; this issue is about the upper bound.
Activity
feat(guardrails): inspect oversized content instead of skipping (#172) (