T09 · Insecure Skill Coding Practices
Warning
- Location
- safe_memory.py:59
- Finding
- Unsanitized Author Field Bypasses Memory Injection Protection## Vulnerability Details **File Location**: `safe_memory.py`, lines 59–70 **Vulnerability Type**: Incomplete input sanitization **Risk Level**: Medium ```python def append_memory(self, filename, content, author="Agent"): """Safely appends to a memory file with auto-sanitization.""" if not self.verified: # Note: For public skills, a missing manifest is expected unless anchored. pass safe_filename = "".join([c for c in filename if c.isalpha() or c.isdigit() or c in ('-', '_', '.')]).rstrip() file_path = os.path.join(self.memory_dir, safe_filename) sanitized_content = self.sanitize_content(content) entry = f"\n[{datetime.now().isoformat()}] {author}: {sanitized_content}\n" ``` ### Technical Analysis The `append_memory` method sanitizes the `content` parameter but interpolates the `author` parameter directly into the persistent memory entry. If `author` can contain untrusted input, it becomes an alternative channel through which prompt-like instructions can be written without passing through `sanitize_content`. This violates the method's declared security boundary: all attacker-controlled fields written to Agent memory must be handled consistently. The vulnerability does not provide operating-system command execution because the stored value is only written as text. However, a consuming Agent may later interpret the unsanitized author value as instructions rather than data. ### Attack Path 1. An attacker reaches an integration that maps an untrusted identity, display name, or supplied author value to the `author` argument. 2. The attacker places persistent instructions in that value. 3. `append_memory` sanitizes only `content`. 4. The malicious `author` value is written verbatim to the selected memory file. 5. A later `read_memory` call returns the stored entry. 6. If the calling Agent inserts that result into its context without a strict data boundary, th ...[truncated 611 chars]
- Remediation
- ## Remediation Suggestions - Treat `author` as untrusted and apply validation or sanitization before storage. - Prefer a strict allowlist for author identifiers, including a conservative length limit and an explicitly permitted character set. - Store memory entries in a structured format such as JSON rather than concatenating fields into prose. - Escape or encode line breaks and control characters in every metadata field. - Preserve an explicit trust label for each entry and ensure consuming Agents are instructed to treat retrieved fields as data, not executable instructions. - Add tests proving that injection-like content supplied through `author`, `content`, and any future metadata fields cannot cross the intended trust boundary.
