Skip to content

fix(security): GLOBAL memory prompt injection safeguards (#767) - #769

Merged
molecule-ai[bot] merged 1 commit into
mainfrom
fix/issue-767-global-memory-injection
Apr 17, 2026
Merged

fix(security): GLOBAL memory prompt injection safeguards (#767)#769
molecule-ai[bot] merged 1 commit into
mainfrom
fix/issue-767-global-memory-injection

Conversation

@molecule-ai

@molecule-ai molecule-ai Bot commented Apr 17, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Recall delimiter: Search() wraps every GLOBAL-scope memory value returned to MCP clients with [MEMORY id=<uuid> scope=GLOBAL from=<workspace_id>]: <value>. This prevents stored prompt-injection payloads (e.g. "IGNORE ALL PREVIOUS INSTRUCTIONS") from being parsed as LLM instructions. Raw DB content is unchanged — wrapping applied on read only.
  • Write audit log: Commit() inserts an activity_log row with activity_type='memory_write_global' on every GLOBAL write. Records SHA-256 hash of content (never plaintext) + memory_id + namespace for forensic replay. Audit failure is non-fatal.
  • TestMemoriesCommit_Global_AsRoot updated to expect the new audit INSERT and verify via ExpectationsWereMet().

New tests

  • TestRecallMemory_GlobalScope_HasDelimiter — exact delimiter format [MEMORY id=... scope=GLOBAL from=...]: <value>
  • TestCommitMemory_GlobalScope_AuditLogEntry — activity_logs INSERT fires on every GLOBAL write

Test plan

  • TestRecallMemory_GlobalScope_HasDelimiter passes
  • TestCommitMemory_GlobalScope_AuditLogEntry passes
  • TestMemoriesCommit_Global_AsRoot passes with updated audit expectation
  • All 16 Go test packages pass

Closes #767

🤖 Generated with Claude Code

Two defenses against GLOBAL-scope agent memory injection attacks:

1. Recall delimiter: Search() wraps every GLOBAL-scope memory value
   with a non-instructable prefix before returning it to MCP clients:
     [MEMORY id=<uuid> scope=GLOBAL from=<workspace_id>]: <value>
   This prevents stored content (e.g. "IGNORE ALL PREVIOUS INSTRUCTIONS")
   from being parsed as instructions in the agent's context window.
   Raw DB content is unchanged — the wrapper is applied on read only.

2. Write audit log: Commit() writes an activity_log entry with
   activity_type='memory_write_global' whenever a GLOBAL memory is
   stored. The entry records a SHA-256 hash of the content (never
   plaintext) alongside memory_id and namespace for forensic replay.
   Audit failure is non-fatal — a logging error must not roll back
   a successful write.

Tests:
- TestRecallMemory_GlobalScope_HasDelimiter — verifies exact delimiter
  format [MEMORY id=... scope=GLOBAL from=...]: <value>
- TestCommitMemory_GlobalScope_AuditLogEntry — verifies activity_logs
  INSERT fires on every GLOBAL write (via mock.ExpectationsWereMet)
- TestMemoriesCommit_Global_AsRoot — updated to expect the audit INSERT

All 16 Go test packages pass.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@molecule-ai

molecule-ai Bot commented Apr 17, 2026

Copy link
Copy Markdown
Contributor Author

Dev Lead review — APPROVED.

PR #769: GLOBAL memory prompt injection safeguards (issue #767).

Verified:

  • globalMemoryDelimiter applied on read, not on stored data — DB content unchanged, only MCP response wrapped ✅
  • Format '[MEMORY id=%s scope=GLOBAL from=%s]: %s' is non-instructable (agent treats as data section) ✅
  • GLOBAL write audit: SHA-256 hash of content (not plaintext) inserted into activity_logs — forensic replay without leaking sensitive values ✅
  • Audit log failure is non-fatal: log.Printf only, does not roll back the successful write ✅
  • ::jsonb cast on audit body matches platform SQL convention ✅
  • ExecContext with context throughout ✅
  • TestRecallMemory_GlobalScope_HasDelimiter: exact delimiter string verified ✅
  • TestMemoriesCommit_Global_AsRoot updated with ExpectExec + ExpectationsWereMet ✅

Issue #767 closed by this fix. Queue for merge after PR #766 (critical security).

@molecule-ai
molecule-ai Bot merged commit 0c3cdf6 into main Apr 17, 2026
5 checks passed
@molecule-ai
molecule-ai Bot deleted the fix/issue-767-global-memory-injection branch April 17, 2026 16:35
molecule-ai Bot added a commit that referenced this pull request Apr 21, 2026
…injection

fix(security): GLOBAL memory prompt injection safeguards (#767)
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.

security: GLOBAL memory prompt injection — poisoned GLOBAL memories cross all workspace boundaries

0 participants