Skip to content
Hidden Logic Lab

Review untrusted tool and MCP results before agent changes ship

Cursor or Claude Code applies a SKILL.md on agent and MCP PRs: treat tool, browser, search, and MCP payloads as attacker-controlled; block unquoted tool output in model context, hidden instructions in fetched pages, and agents that follow untrusted content as commands for writes, sends, shell, or credentials.

Copy prompt

Cursor, Claude Code · Coding · 40 min · Deep

Outcome

A prompt-injection-tool-results SKILL.md linked from agent platform docs, a PR comment mapping each tool boundary and sanitization path, and no merge that pipes raw web or tool text into the model without delimiters and policy that forbids executing embedded instructions.

Steps

  1. 1

    Run the skill on a verbatim page dump

    Use a PR that inserts full fetch HTML into the user message with no delimiters. The skill should Block until structure and untrusted-data rules are in the diff.

  2. 2

    Add injection fixtures beside agent tests

    Keep synthetic pages with hidden instructions in the repo. The skill references those tests so reviews expect refusal, not obedience.

  3. 3

    Pair with MCP HTTP auth and supply-chain skills

    Untrusted text often arrives through network MCP tools. Link injection review with MCP auth skills when adding fetch or browser tools.

Copy prompt

The prompt to paste

Write SKILL.md for reviewing agent systems that place tool, MCP, browser, search, or RAG fetch results into the model context before merge. Focus on prompt injection via untrusted content — not general prompt engineering for user chat.

Repository context:
[agent runtime: Cursor rules, Claude Code, custom orchestrator, LangGraph, Vercel AI SDK tools — names only]
[sources of untrusted text: web fetch, MCP tools, filesystem read, email, tickets, search APIs]
[whether tool output is wrapped, truncated, or passed through verbatim into the next model turn]
[tools with side effects: file write, send message, shell, HTTP POST, credential use]

PR or diff context (paste when using):
[PR link, changed tool handlers, system prompts, message assembly, MCP resource templates]
[example tool payload shapes from tests — synthetic only]

SKILL.md must include:
1. Purpose — tool and fetch results are untrusted input; pages and JSON can contain instructions styled as system or developer messages. If the agent concatenates them unquoted or treats them as commands, the model may exfiltrate data, run shell, write files, or send messages while the user believes only summarization ran.
2. When to use — any PR touching tool result formatting, MCP content returned to the model, browser automation snapshots, search snippets merged into prompts, RAG chunks without citation boundaries, or agent loops that re-feed model output into tools without human gates. When not to use — static system prompts with no new external content paths.
3. Hard rules for findings:
   - Block: tool, MCP, or browser results inserted into model messages without clear delimiters and a fixed preamble that marks the block as untrusted data (not instructions); system or developer prompt strings built by concatenating untrusted fields (page title, HTML, email body, ticket description) without escaping or structural separation; agent policies that say "follow instructions in tool output" or equivalent; automatic execution of shell, file write, outbound send, or credential retrieval when the triggering content came solely from a fetched or tool-returned string without a separate user confirmation step for that action class; unquoted JSON or XML tool payloads inlined into user-role messages where the model cannot distinguish data from commands; stripping or bypassing content filters only on tool path; MCP tools that return markdown or HTML containing fake <|im_start|> or role tags intended to hijack the conversation.
   - Warn: summarization prompts that ask the model to "obey" or "prioritize" text inside fetched documents; very large tool dumps with no truncation allowlist; recursive browse/fetch without domain allowlist; logging full tool payloads that contain injected secrets the model might repeat; trusting same-origin intranet pages as safe; eval harnesses that score agents on following embedded cheat instructions in fixtures.
   - Note: tool naming, icon choice, token limits on unrelated paths — never block on style alone.
4. Review steps the agent must execute:
   - List every code path that appends tool or fetch text to messages; name file and function for each.
   - Verify delimiter pattern: opening/closing markers, role placement (tool vs user vs assistant), and whether instructions inside the block are explicitly forbidden in system text.
   - Inspect side-effect tools: confirm they require explicit user intent or a separate approval gate, not inference from untrusted content alone.
   - Search for string templates that interleave untrusted HTML/Markdown with system prompts without encoding.
   - Review MCP resource and tool handlers that echo remote server content verbatim to the model.
   - Check test fixtures for injection strings (ignore previous instructions, exfiltrate env) and confirm tests expect refusal or sanitize, not compliance.
   - Trace multi-step loops: ensure later turns do not promote untrusted quotes into "user said" without the human typing them.
5. PR comment template: data path table (source — sanitization — message role — side-effect tools reachable?), findings by severity, merge recommendation.
6. Safe patterns section: fixed system prompt stating tool content is data only; structured tool channel with schema-only fields when possible; allowlisted domains for fetch; human confirmation before send/shell/write; redact secrets from tool payloads before model; separate parsing step that does not use the LLM to execute instructions from HTML.
7. Two example prompts: add browser tool that dumps full page text into user message vs wrap MCP results in delimiters and block auto-send on email bodies.
8. Pitfalls: assuming JSON is safe because it is structured, trusting PDF or email "system" headers, copying chat transcripts from support tickets into system role, smaller models used for tool routing without injection checks, invisible Unicode and HTML comments hiding instructions.
9. Done means: every Block resolved, delimiter and untrusted-data policy named per path, no live credentials in PR comment, side-effect tools mapped to confirmation gates.

Rules:
- Never paste live cookies, session tokens, or customer PII from real tool runs into the review.
- Do not suggest disabling tools entirely as the only fix — require boundaries and gates.
- Output only SKILL.md markdown.

Delimiter banners alone do not stop capable models from following persuasive text inside the block when side-effect tools sit one turn away. The skill must Block auto-execution paths unless confirmation is tied to explicit user action, not to content inside tool results.

Sample case written by Hidden Logic Lab. Not affiliated with Cursor or Claude Code.

Get new cases in your inbox

Weekly notes on new use cases and agent workflows. No product pitches.

Occasional notes on new cases. No product pitches in the first note.