sentry-mcp icon indicating copy to clipboard operation
sentry-mcp copied to clipboard

fix(formatting): wrap get_issue_details output in untrusted data boundary

Open sentry-junior[bot] opened this issue 6 months ago • 0 comments

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:

  1. 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.
  2. Wraps the escaped body in <untrusted_sentry_data>…</untrusted_sentry_data> structural tags.
  3. Prepends a SECURITY NOTE explaining 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 for markAsUntrustedSentryData: correct wrapping order, boundary escape for closing tags, boundary escape for opening tags
  • formatting.test.ts — formatIssueOutput prompt-injection boundary test: malicious title + culprit with fake closing tag; asserts preamble, content inside boundary, and escape
  • get-issue-details.test.ts — integration test: injection issue override via MSW; same structural assertions
  • get-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.

View Session in Sentry

sentry-junior[bot] avatar Jun 05 '26 13:06 sentry-junior[bot]