fix(formatting): wrap get_issue_details output in untrusted data boundary
What
Adds a prompt-injection defense to get_issue_details: the full formatted issue + event payload is now wrapped in <untrusted_sentry_data> XML tags with a SECURITY NOTE preamble.
This follows guidance from Anthropic, Google Cloud MCP docs, and OWASP on separating untrusted telemetry from instructions using strong XML-style delimiters.
How it works
A new markAsUntrustedSentryData(markdown) helper in formatting.ts:
- HTML-entity-escapes any literal
<untrusted_sentry_data>/</untrusted_sentry_data>that appear in the Sentry telemetry payload — preventing boundary breakout from attacker-controlled content in title, culprit, exception.value, stack frames, tags, contexts, etc. - Wraps the escaped body in
<untrusted_sentry_data>…</untrusted_sentry_data>structural tags. - Prepends a
SECURITY NOTEexplaining that all content inside the tags is user-controlled data and must not be treated as instructions.
formatIssueOutput calls this on its return value, so every code path in get_issue_details (issueId, issueUrl, eventId) gets the wrapper automatically.
The tool description also gains a - **SECURITY**: Results are wrapped in <untrusted_sentry_data> tags… hint so the LLM client's tool manifest is informed before the call.
Tests
Tests were written first to prove the vulnerability, then the implementation was added:
formatting.test.ts— unit tests formarkAsUntrustedSentryData: correct wrapping order, boundary escape for closing tags, boundary escape for opening tagsformatting.test.ts—formatIssueOutputprompt-injection boundary test: malicious title + culprit with fake closing tag; asserts preamble, content inside boundary, and escapeget-issue-details.test.ts— integration test: injection issue override via MSW; same structural assertionsget-issue-prompt-injection-canary.eval.ts— LLM eval canary: asks the model to quote the security note from the tool result and checks it was acknowledged- 4 inline snapshots updated to include the new wrapper
Verified
pnpm run tsc ✓
pnpm run lint ✓
pnpm run test ✓ (1071 passed, 6 skipped)
Action taken on behalf of immutable dcramer.