fix(addie): sanitize step.error / validation.error / narrative in MCP output#3233
Merged
Merged
Conversation
… output Closes #3219. The hint fix-plan formatter (adcp#3084, #3220) carefully sanitized every seller-controlled field at its boundary. But sibling renders on the same StoryboardStepResult — `step.error`, `validation.error`, `result.next.narrative` — and adjacent tools (`evaluate_agent_quality`, `compare_media_kit`, `test_io_execution`, `get_storyboard_detail`) emitted runner/agent strings raw, letting a hostile seller bypass the formatter's prompt-injection protection through a sibling field on the same Claude-bound output. This pass routes every such site through `sanitizeAgentField`. Adds a new `RUNNER_ERROR_MAX_LEN` constant (400) with a docstring framing it explicitly as a prompt-injection budget — not a UX choice — so future contributors don't raise it without thinking about blast radius. Sites covered (per triage on #3219): - `evaluate_agent_quality` per-step error rendering (line 3399) - `run_storyboard` step.error + per-validation error (lines 3746, 3749) - `run_storyboard_step` per-validation + result error (lines 3857, 3861) - `run_storyboard_step` next.narrative preview (line 3892) - `compare_media_kit` per-brief error (line 4113) - `test_io_execution` failure message (line 4720) - `get_storyboard_detail` storyboard / phase / step narratives — added for consistency since they render onto the same LLM-bound output path through the same trust model. CODE_VERSION bumped 2026.04.4 → 2026.04.5 (MCP tool output behavior change, per playbook). Reviews on #3219 (already complete in the triage comment): - security-reviewer: fix is correct; flagged the same additional sites the triage scoped in - prompt-engineer: 400-char cap should be documented as injection budget — done via the `RUNNER_ERROR_MAX_LEN` docstring Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #3219.
The hint fix-plan formatter (adcp#3084 / #3220) sanitized every seller-controlled field at its boundary. But sibling renders on the same `StoryboardStepResult` (`step.error`, `validation.error`, `result.next.narrative`) and adjacent tools (`evaluate_agent_quality`, `compare_media_kit`, `test_io_execution`, `get_storyboard_detail`) emitted runner/agent strings raw, letting a hostile or compromised seller bypass the formatter's prompt-injection protection through a sibling field on the same Claude-bound output.
This pass routes every such site through `sanitizeAgentField`. Defense in depth; no current attack.
Sites covered
Per the triage on #3219 (eight original sites + three additional narrative renders for consistency, since they're on the same trust path and same LLM-bound output):
New constant
`RUNNER_ERROR_MAX_LEN = 400` with a docstring explicitly framing the cap as a prompt-injection budget — not a UX choice. Mirrors the per-cap rationale in `storyboard-fix-plan.ts` (`MAX_VALUE_LEN`, `MAX_REQUEST_FIELD_LEN`, etc.). 400 chars covers legitimate AdCP error envelopes (`code` + `message` + a short `details` reference) with margin; legitimate storyboard step narratives are typically under 200.
Reviews from triage
Test plan
Note on test coverage — the changes are mechanical `${value}` → `${sanitizeAgentField(value, RUNNER_ERROR_MAX_LEN)}` wraps at 11 enumerated sites. The sanitizer regex is shared with `sanitizeAgentString` in `storyboard-fix-plan.ts`, which has a dedicated injection-regression test covering U+2028 / U+2029 / NEL / backtick / control-char stripping.
CODE_VERSION bumped 2026.04.4 → 2026.04.5 (MCP tool output behavior change, per playbook).
🤖 Generated with Claude Code