Repository navigation
fix(platform): treat email content as untrusted - #3082
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.
wrapUntrustedquarantines long content in<untrusted_source>tags with a system-prompt contract;sanitizeUntrustedFieldstrips 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.conversationIdis set on exactly the hits that arrived by mail, sorag_searchsnippets andrag_fetchcontent 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.fetchDocumentByFileIdalready readconversation_idto 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_PROMPTenumerated 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.