Repository navigation
Tag the stored-memory fence so recalled text cannot close it - #7
Merged
Merged
Conversation
The fence markers were fixed strings. Memory text is extracted from content an attacker can influence, so a memory containing "--- END STORED MEMORY ---" closed the fence early and whatever followed read as the server's own words. Each reply now uses a fresh random tag on both markers. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Merged
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.
Problem
Recalled memories are wrapped in fixed markers:
Memory text is LLM-extracted from conversations, which can include content an attacker controls (web pages, tool output). A memory that contains
--- END STORED MEMORY ---followed by instructions closes the fence early, and everything after it reads as server-authored text.Change
_data()puts a fresh random tag (secrets.token_hex(4)) on both markers per reply, and instruction 6 now says the data runs to the END marker with the same tag. Stored text can't predict the tag, so it can't forge the closing marker.Tests
New
test_stored_text_cannot_close_the_fence: a memory containing a forged END marker plus an injected instruction stays inside the real fence, and the tag changes between replies. 92 passed.The hosted Go server (
pkg/tools/format.go) has the same fixed fence; this PR is the reference for porting it.🤖 Generated with Claude Code