Bounded retrieval for an active workflow
Read the expected current code or status when scope and filters are already established.
Transport checks can confirm where a message came from. They cannot make instructions inside the message safe, relevant, or authorized for the current workflow.
Defend against email prompt injection by separating message transport from workflow authority. Give the agent a dedicated scoped inbox, select messages with trusted application state, retrieve only the fields needed for the current step, label all email content as untrusted data, validate links and attachments outside the model, and require policy or human approval before sending, changing credentials, making purchases, deleting data, or taking unrelated external actions. Log the decision path with redacted identifiers, and provide a fast mailbox pause and key-revocation path.
Each gate answers a different security question. Passing one does not bypass the next.
Verify the mailbox route, event source, and delivery integrity.
Match mailbox, workflow, sender context, recipient, and time.
Extract and validate the minimal code, link, text field, or file.
Check application policy and approval before acting externally.
An attacker may send a message that asks the agent to ignore policy, reveal secrets, open an unrelated link, upload a file, forward private mail, change account recovery, or contact another person. The instruction can appear in plain text, HTML, quoted history, a calendar-like block, an attachment, or a page reached through a link.
The message may also come from a legitimate account that was compromised or from a familiar service whose content includes user-controlled fields. SPF, DKIM, DMARC, webhook signatures, and provider authentication help establish transport and domain evidence. They do not prove that every sentence is safe or that the requested action is authorized.
The security objective is not to make the model perfectly classify malicious prose. It is to make untrusted prose unable to grant new authority or escape the workflow boundary.
| Signal | What it can establish | What it cannot establish |
|---|---|---|
| Webhook signature | Expected service delivered the event | Message instructions are safe |
| DKIM or domain alignment | Domain-level authentication evidence | The sender account or content is benign |
| Known display name | A familiar string is visible | Identity or authorization |
| Thread relationship | The message belongs to a conversation | Every new request is approved |
Start from trusted workflow state: the mailbox identifier, expected direction, trigger time, sender or domain context, and required result type. Query message metadata first. If the task only needs a six-digit code, return the candidate code with message ID and timestamp rather than the full HTML body and entire conversation.
For a confirmation link, parse the URL in trusted code, require HTTPS and an allowed host, reject embedded credentials and unexpected redirects, and return a normalized target. For attachments, inspect size, type, filename, and content in an isolated parser. The model should receive a summary or extracted fields only after policy checks pass.
This is both a security and quality improvement. Smaller context reduces the chance that quoted text, signatures, tracking markup, and unrelated thread history distract the agent or override the current task.
Start with mailbox, workflow, recipient, time, and expected sender context.
Select one current candidate without exposing the full payload.
Validate code shape, URL host, attachment type, or structured field.
Tell the model it is untrusted data and constrain how it may be used.
A tool named read_any_email_and_act hides too much authority. Prefer separate operations for list metadata, get one message, wait for a current code, retrieve an approved attachment, draft a reply, request send approval, and send an approved message. Give each operation the smallest credential and result schema it needs.
MCP servers and local agent tools should keep secrets in the tool process, not return them in model-visible output. Tool descriptions should state that message content is untrusted and should not be treated as instructions. The host application remains responsible for user consent, tool enablement, and confirmation behavior.
Record which message and extracted field informed each action, using restricted identifiers rather than copying sensitive bodies into general logs. Preserve approval evidence, tool calls, external request identifiers, and final state. This lets the team reconstruct the decision without retaining every mailbox payload indefinitely.
The immediate response should be narrow: pause the affected mailbox or tool, rotate its credential, stop pending outbound actions, and inspect downstream transitions. Search for the same sender, link host, attachment hash, or content pattern across authorized scope. Restore service only after the policy or parser gap is understood.
| Incident step | Action | Evidence |
|---|---|---|
| Contain | Pause mailbox or disable risky tool | Scope and effective time |
| Revoke | Rotate credential and invalidate sessions | Key identifier and callers |
| Trace | Map message to tool calls and external actions | Message, workflow, and request IDs |
| Repair | Tighten filter, parser, policy, or approval | Regression test and deployment proof |
Models can help classify and summarize, but they should operate inside a system that already limits identity, data, tools, and authority. The durable defense is a sequence of trusted gates, a narrow tool surface, and an operator who can stop and investigate one mailbox without disabling the entire product.
Product behavior is verified against the mails0 source and documentation. External comparisons link to official vendor documentation checked on 2026-08-15.
No. DKIM can provide domain-level authentication evidence. It does not make the message body, link, attachment, or requested action safe.
Only when the task needs that context. Prefer metadata selection and bounded extraction so quoted history and unrelated instructions do not enter the model context.
A prompt can clarify behavior but should not be the only control. Enforce scope, extraction, link and file validation, action policy, approval, and revocation in trusted application code.
Start with one scoped inbox and one expected message. Add durable identity, sending, and operational complexity only when the first loop works.