Skip to content

Find the injection and leak paths in a data flow

Trace an application's data flow, mark where untrusted content, authorization or personal data is handled unsafely, and pick the mitigation that removes each risk at its source.

Scenario

You join a team that ships a support assistant for an online furniture shop. It answers "where is my order?" questions, and it works well in the demo.

Before it goes live, your lead asks you to read its data flow and mark every step where an attacker, or simply a careless customer, could make it misbehave or leak data.

Nobody has told you yet what to look for. Try it first.

Explanation

Three kinds of risk show up in almost every Claude data flow. Each has a fix that works at the source, not by asking Claude to be careful.

1. Untrusted content mixed with instructions (prompt injection). Anything a third party can write (emails, web pages, uploaded files, notes, tool output) may contain instructions. The docs' guidance for this indirect injection:

  • Put third-party content only in tool_result blocks, never in the system prompt or in a plain user text block.
  • Say what the content is and where it came from ("inbound email from an unknown sender"), and JSON-encode it so it can't close a tag and break out.
  • State the policy in the system prompt: tool content is data, and never overrides the system prompt or the user's request.
  • Don't put your own instructions inside tool results: Claude treats that content with suspicion. Send them in a following user turn.
  • Limit what a successful injection could do: least privilege, and screening tool output with a small classifier before Claude sees it.

2. Authorization left to the prompt. Claude chooses tool arguments from the conversation, and the conversation can be steered. A rule in the prompt is guidance, not access control. Enforce it in the tool handler, from the authenticated session, and leave out parameters the model doesn't need to choose.

3. Data leakage. Send and store the minimum, above all of personal data (often called PII, personally identifiable information: anything that identifies a person, such as a name, email address, phone number or home address):

  • Don't put data in the prompt that the task doesn't need: secrets and proprietary details can be coaxed back out. The docs on prompt leak advise leaving out what Claude doesn't need and screening output.
  • metadata.user_id should be an opaque id (a UUID or hash). The API reference says not to include a name, email address or phone number.
  • Logs are a data flow too. Logging full prompts copies every piece of personal data in them to wherever the logs go.

How to read a data flow: for each step ask who can write this text?, what can the model do with it? and where does it end up?