Skip to content

fix(platform): treat email content as untrusted - #3082

Merged
Israeltheminer merged 1 commit into
mainfrom
fix/email-content-untrusted
Aug 26, 2026
Merged

Israeltheminer merged 1 commit into
mainfrom
fix/email-content-untrusted

Conversation

@Israeltheminer

Copy link
Copy Markdown
Contributor

Text that arrived by email now reaches the model as untrusted content. Before this, anyone who could email the organization could put instructions in front of its assistant.

Closes #3081.

Why

Both defences already existed and neither was applied to mail. wrapUntrusted quarantines long content in <untrusted_source> tags with a system-prompt contract; sanitizeUntrustedField strips control characters, zero-width and bidi-override marks, and clamps length on short text. Video transcripts and video titles used them. Email used neither.

What changed

Content is wrapped by provenance. hit.source.conversationId is set on exactly the hits that arrived by mail, so rag_search snippets and rag_fetch content are wrapped when it is present. Wrapping the whole passage also covers the mail's subject and correspondent, which #3014 bakes into the chunk and which therefore cannot be stripped at read time.

fetchDocumentByFileId already read conversation_id to decide its scope branch; it now returns it, so the fetch path can tell mail from a hub document without a second read.

Four short attacker-controlled fields are sanitized where they enter a result: the corpus title, an attachment's filename, a conversation's subject, and a contact's name. Each is chosen by a correspondent.

The trust contract names email. UNTRUSTED_CONTENT_SYSTEM_PROMPT enumerated what counts as untrusted and email was absent, so the model was told to distrust a set and then handed something outside it. It now names a message, its subject, its sender, and an attachment's contents and filename.

Risk

A hub document stays unwrapped, deliberately. Wrapping everything would make the marker meaningless. Two tests pin that a hub document is not wrapped on either path.

Sanitizing is not removal. The text survives inside the wrapper, and a sanitized title keeps its words — only control characters, invisible marks and excess length go. A test asserts the injected words are still present, because quarantine is the goal and silent deletion would hide what arrived.

Wrapping is keyed on provenance, not on content. Nothing here tries to detect an injection attempt. That is on purpose: a detector is a guess, while provenance is a fact the corpus already records.

Tests

Nine cases: a wrapped mail snippet, an unwrapped hub snippet, a wrapped mail fetch, an unwrapped hub fetch, a sanitized corpus title, a sanitized fetch filename, and one each for the attachment filename, conversation subject and contact name.

Seven deliberate breakages, all caught. Three of them survived the first round — the attachment filename, conversation subject and contact name had no test at all, which is how I found out. The cases above were written for exactly those three and then re-run against the same mutations.

Scope

Independent of whether inbound mail should be indexed at all. PII handling protects the person who sent the data; this protects the organization from the sender.

Gate: typecheck (repo-wide), oxlint --type-aware, oxfmt, knip, SAST 0 findings, platform suite 75,795 passing.

@Israeltheminer
Israeltheminer merged commit cb193cc into main Aug 26, 2026
19 checks passed
@Israeltheminer
Israeltheminer deleted the fix/email-content-untrusted branch August 26, 2026 15:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: email content reaches the model as trusted

1 participant