T02 · Agent Memory Poisoning
- Location
scripts/memory-cli.js:811- Finding
Unconfirmed User Text Can Be Promoted into Persistent High-Priority Agent Memory
- Content
View full analysis
Vulnerability Details
File Location:
scripts/memory-cli.js:811-813, 1040-1070; persistence sink atscripts/memory-cli.js:640-643
Vulnerability Type: Persistent agent memory poisoning
Risk Level: HighVulnerable Code
js function hasHardRuleSignal(content) { return /\b(always|never|must|only|required|forbidden)\b/i.test(content); }js case "on-correction": { const guard = ensureSessionStarted(args, "on-correction"); const content = firstNonEmpty(args.content, args.summary); if (!content) { throw new Error("--content is required for on-correction command."); } const metadata = parseMetadata(args.metadata); const result = await saveWithVisibility(store, args, { tenantId: args.tenant, eventType: args.type || "correction", domain: args.domain || "general", project: args.project || "global", taskContext: args.task || "", content, resolution: args.resolution || "pending", tags: toTags(args.tags), metadata }); const hardRuleCandidate = args["hard-rule"] === undefined ? hasHardRuleSignal(content) : isAffirmative(args["hard-rule"]); const markdownPromotionDisabled = isAffirmative(args["no-markdown-promotion"]); let localPromotion = { attempted: false, appended: false, reason: hardRuleCandidate ? "disabled-by-flag" : "not-hard-rule" }; if (hardRuleCandidate && !markdownPromotionDisabled) { localPromotion = promoteHardRuleToMarkdown(args, content, result.save.id); }js const promotionText = `${normalizeInlineText(content)} (source: ${sourceEventId})`; const writeResult = appendBulletUnderSection(targetFile, sectionTitle, promotionText);Technical Analysis
The correction handler classifies text as a durable hard rule solely when it contains one of several keywords, including
always,never,must,only,required, orforbidden. It then writes the complete correction into HOT, project, or domain Markdown without ...[truncated 2073 chars]- Remediation
View remediation
Remediation Suggestions
- Remove keyword-only automatic promotion. Treat every first correction as an episodic record, not a confirmed rule.
- Require a separate, explicit confirmation step before writing any behavior-affecting Markdown rule.
- Use a structured promotion workflow with states such as
tentative,pending_confirmation, andconfirmed. - Store normalized preference fields rather than copying raw user sentences verbatim into an instruction-bearing document.
- Reject proposed rules that request:
- safety-policy bypasses;
- secret or credential disclosure;
- privilege escalation;
- unrelated command execution;
- modification of system, developer, or tool instructions.
- Clearly delimit stored content as untrusted data when presenting it to an agent.
- Require promotion confirmation to include the exact target scope: global, project, or domain.
- Add regression tests proving that sentences containing
always,never, ormustare not promoted without explicit confirmation. - Reconcile the implementation with
learning.mdso the documented confirmation requirement is enforced in code rather than left to agent discretion.
