/** * GHSA-gh63-5vpj-39qp — wire external-content defenses into the live message path. */ import type { Memory } from "../types/memory.js"; import type { IAgentRuntime } from "../types/runtime.js"; export type IncomingMessageSecurityMetadata = { promptInjectionSuspected?: boolean; promptInjectionPatterns?: string[]; externalContentWrapped?: boolean; /** * The user's exact words, retained at the inbound trust boundary BEFORE the * external-content envelope replaces `content.text`. The envelope exists for * prompts (the model must see the untrusted-content warning); every * non-prompt consumer — resolvers, query fallbacks, anything echoed back to * chat — reads this field through `unwrapUserMessageText` and never parses * the armor back out of the prompt text. Persisted with the message content, * so replayed/stored messages keep the trusted payload. Only * `hardenIncomingUserMessage` may stamp it; forged inbound values are * stripped there like the autonomy marker. The pipeline hook applies * `scrubIncomingMessageTextForStorage` to this field exactly as it does to * `content.text` — the retained copy persists and gets echoed by payload * consumers, so an unscrubbed copy would resurrect every secret the text * scrub removed. */ userPayloadText?: string; }; /** * Apply injection detection + external wrapping at the inbound trust boundary, * before compose / LLM. Mutates `message.content` in place (pipeline hook + * optional direct callers). For untrusted sources the user's exact words are * retained in `metadata.userPayloadText` and `content.text` becomes the * security envelope: prompts read the envelope, everything else reads the * retained payload via `unwrapUserMessageText`. */ export declare function hardenIncomingUserMessage(message: Memory): void; /** Redact secret-shaped substrings before persisting user text to memory. */ export declare function scrubIncomingMessageTextForStorage(text: string): string; /** * Canonical accessor for the user's actual words from a message that * `hardenIncomingUserMessage` may have wrapped in the external-content * security envelope. The envelope exists for PROMPTS — the model must see the * untrusted-content warning — but code that treats `content.text` as user * input (query fallbacks, name/target extraction, anything later echoed back * to chat) must operate on the payload, not the armor: an action that quoted * the raw text shipped the entire envelope to Discord (live leak 2026-08-02, * tj-2dc95f75456876), and a resolver that matched on it selected apps by * warning words. * * The resolved candidate (see {@link resolveRetainedCandidate}) is validated * last: a result that still reads as envelope material (partial markers, the * warning sentence, a stamped message whose markers were mangled, unstamped * armor — including a sender who typed marker-shaped text themselves) returns * "" — an empty reference sends resolvers down their ask-the-user path * instead of matching warning words, which is the only safe interpretation of * armor debris **for something that echoes or acts on the text**. * * Do NOT use this for detection/scoring boundaries (injection risk gates, * classifiers) — an attacker can pair a genuine injection with marker-shaped * text specifically to make this return "", which a scorer reading "" as "no * signal" would treat as safe instead of maximally suspicious. Use * {@link unwrapUserMessageTextForDetection} there instead. */ export declare function unwrapUserMessageText(message: Memory): string; /** * Detection-only counterpart to {@link unwrapUserMessageText}: same retained- * payload resolution, but returns the raw candidate even when it still reads * as envelope material, instead of collapsing to "". Only safe for boundaries * that score/classify/block text and never echo or act on it directly — a * scanner seeing an attacker's real injection attempt (even one deliberately * salted with marker-shaped text to defeat {@link unwrapUserMessageText}) is * exactly the detection this exists for. Never use this for resolvers, name/ * target extraction, or anything later shown to a user or another system. */ export declare function unwrapUserMessageTextForDetection(message: Memory): string; export declare function messageHasPromptInjectionFlag(message: Memory): boolean; export declare function registerCoreIncomingMessageSecurityHook(runtime: IAgentRuntime): void;