Skip to content

feat(guardrails): inspect oversized content instead of skipping (#172) - #179

Merged
JAORMX merged 1 commit into
mainfrom
fix/guardrails-oversized-content-172
Jun 24, 2026
Merged

JAORMX merged 1 commit into
mainfrom
fix/guardrails-oversized-content-172

Conversation

@JAORMX

@JAORMX JAORMX commented Jun 24, 2026

Copy link
Copy Markdown
Contributor

What

Removes the maxContentBytes (256 KiB) skip-inspection behavior from guardrails. The checker now inspects tool content regardless of size; a checker timeout/error on huge input flows through the existing onCheckerError fail-open/closed path (the 30s guardrailCheckTimeout bounds the failure mode).

Why

"Too big to check" is not an acceptable terminal state for a security control. The bound was a gap on both sides: an attacker could pad a payload past 256 KiB to skip inspection, and benign large content was never judged on its merits. The 30s checker timeout + fail-open/closed already bound the failure mode.

Same class of decision as #168 / ADR 0049 (remove maxChecks): a cost guard whose skip behavior is a security downgrade for a control the operator explicitly opted into.

Changes

  • internal/adapter/modelhook/modelhook.go — deleted maxContentBytes const, onContentTooLarge method, and the early-return arm in check(). minContentBytes, maxSanitizedBytes, and failureStreak untouched.
  • Tests — deleted TestOversizedContentEnforceDoesNotSilentlyPass; added TestOversizedContentIsInspected + TestOversizedContentCheckerTimeoutFailClosed.
  • ADR 0050 (new) — supersedes the maxContentBytes clause of ADR 0021. Acknowledges the N× concurrent checker-cost amplification as an accepted trade-off.
  • Docs — usage.md, IMPLEMENTATION-NOTES, PRODUCTION-READINESS, ADR README updated. Frozen ADRs 0021/0049 not edited.

Follow-up

Closes #172.

The maxContentBytes (256 KiB) skip-inspection behavior was a security
gap: an attacker could pad a payload past the bound to skip inspection,
and benign large content was never judged on its merits. 'Too big to
check' is not an acceptable terminal state for a security control.

Removes the maxContentBytes const, the onContentTooLarge method, and the
early-return arm in check(). The checker now inspects content regardless
of size; a checker timeout/error on huge input flows through the existing
onCheckerError fail-open/closed path (the 30s guardrailCheckTimeout
bounds the failure mode). minContentBytes (Post-only cost gate),
maxSanitizedBytes (sanitize-laundering defense), and failureStreak are
left untouched.

Tests: deleted TestOversizedContentEnforceDoesNotSilentlyPass (asserted
the skip); added TestOversizedContentIsInspected (proves the checker IS
called on oversized content) + TestOversizedContentCheckerTimeoutFailClosed
(proves a checker error on huge input flows through onCheckerError).

Decision recorded in ADR 0050 (supersedes the maxContentBytes clause of
ADR 0021). The ADR acknowledges the N× concurrent checker-cost
amplification under the read-parallel fan-out as an accepted trade-off.

Follow-up: #178 (MCP tool results are not truncated to MaxOutputBytes).

Closes #172.
@JAORMX
JAORMX merged commit 8f3177a into main Jun 24, 2026
12 of 13 checks passed
@JAORMX
JAORMX deleted the fix/guardrails-oversized-content-172 branch June 24, 2026 19:01
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.

guardrails: oversized content is skipped from inspection (maxContentBytes) — should compact-and-check or check in full

1 participant