fix(rag): close prompt-neutralizer bypass for cross-document titles#406
Merged
Merged
Conversation
docs/rag-injection-threat-model.md (Vectors B/C) flagged that a document title/file_name is a viable injection channel and must never reach the model raw. buildRagSourceBlock's per-result titles are already neutralized, but two cross-document synthesis helpers built their own prompt text directly from document titles without going through neutralizeIdentityField: - buildCrossDocumentSourceGuide (src/lib/cross-document-synthesis.ts) — the per-document title in the "Cross-document synthesis guide:" block. - buildCrossDocumentFusionBrief (same file) — the per-document title in the "Fast fused source brief:" block. - summarizeDocument (src/lib/rag.ts) — document.title interpolated raw into the "Document:" header of the single-document summary prompt, the highest- trust position in that prompt. All three now route through the same neutralizeIdentityField primitive already covered by tests/rag-injection.test.ts. New regression tests added to tests/cross-document-synthesis.test.ts proving an injection idiom carried in a title no longer survives into the generated guide/brief text. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
|
This pull request has been ignored for the connected project Preview Branches by Supabase. |
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
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.
Summary
docs/rag-injection-threat-model.md(Vectors B/C) established that a documenttitle/file_name is a viable injection channel and must never reach the model
raw —
buildRagSourceBlockalready neutralizes per-result titles for thatreason. This PR closes three places that built prompt text directly from
document titles without going through that same
neutralizeIdentityFieldprimitive:
buildCrossDocumentSourceGuide(src/lib/cross-document-synthesis.ts) —the per-document title in the "Cross-document synthesis guide:" block that
feeds into the answer-generation prompt whenever cross-document synthesis
is enabled.
buildCrossDocumentFusionBrief(same file) — the per-document title in the"Fast fused source brief:" block.
summarizeDocument(src/lib/rag.ts) —document.titleinterpolated rawinto the
Document:header of the single-document summary prompt, thehighest-trust position in that prompt.
Why this wasn't already covered
tests/rag-injection.test.tsalready coversneutralizeIdentityFieldandbuildRagSourceBlock's per-result title neutralization thoroughly, but thesethree call sites build their own prompt strings from document titles
outside of
buildRagSourceBlock, so they weren't exercised by that suite.Testing
tests/cross-document-synthesis.test.tsproving a canonical injection idiom carried in a document title no longer
survives into the generated guide/brief text (same idiom pattern used in
tests/rag-injection.test.ts).npx tsc --noEmitclean,npx eslintclean on all three changed files,npx vitest run tests/cross-document-synthesis.test.ts tests/rag-injection.test.ts— 17/17 passing.
schema.sql/ migration changes — no drift-manifest dependency, unlikethe sibling R17/R5 PRs from this session.
🤖 Generated with Claude Code