Skip to content

fix(addie): sanitize step.error / validation.error / narrative in MCP output#3233

Merged
bokelley merged 1 commit into
mainfrom
bokelley/sanitize-storyboard-error-rendering
Apr 25, 2026
Merged

fix(addie): sanitize step.error / validation.error / narrative in MCP output#3233
bokelley merged 1 commit into
mainfrom
bokelley/sanitize-storyboard-error-rendering

Conversation

@bokelley

Copy link
Copy Markdown
Contributor

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):

Site Source Field
line 3399 `evaluate_agent_quality` per-step error `step.error`
line 3746 `run_storyboard` step error `step.error`
line 3749 `run_storyboard` validation error `v.error`
line 3857 `run_storyboard_step` validation error `v.error`
line 3861 `run_storyboard_step` step error `result.error`
line 3892 `run_storyboard_step` next-step preview `result.next.narrative`
line 4113 `compare_media_kit` per-brief `br.error`
line 4720 `test_io_execution` failure `executeResult.error`
line 3675 `get_storyboard_detail` (consistency) `sb.narrative`
line 3680 `get_storyboard_detail` (consistency) `phase.narrative`
line 3688 `get_storyboard_detail` (consistency) `step.narrative`

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

  • security-reviewer: fix is correct for the four named sites; flagged the three additional `.error` interpolations at 3385, 4099, 4706 (now 3399, 4113, 4720 after the constant insertion) — all included in this PR
  • prompt-engineer: `maxLen=400` cap should be documented as an explicit injection-budget decision — done via the `RUNNER_ERROR_MAX_LEN` docstring

Test plan

  • `npm run typecheck` — clean
  • `npm run test:server-unit` — 2249 passed (no regressions; pre-existing DB-init log noise from `addie-router.test.ts` unchanged)
  • Existing `storyboard-fix-plan.test.ts` (which exercises the same sanitizer regex via `sanitizeAgentString`) — 58/58 still green
  • CI passes on this PR

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

… 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>
@bokelley bokelley merged commit ff60659 into main Apr 25, 2026
13 checks passed
@bokelley bokelley deleted the bokelley/sanitize-storyboard-error-rendering branch April 25, 2026 23:43
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.

Addie: sanitize raw step.error / validation.error rendering in run_storyboard output (defense in depth)

1 participant