T09 · Insecure Skill Coding Practices
- Location
handling-attachments/rules/receive-attachment.md:29- Finding
Arbitrary File Overwrite Through Untrusted Attachment Filename
- Content
View full analysis
{ const attachment = await downloadRemoteAttachment( ctx.message.content, agent ); fs.writeFileSync(`./downloads/${attachment.filename}`, attachment.data); await ctx.conversation.sendText(`Saved: ${attachment.filename}`); }); ``` ### Technical Analysis The filename obtained from the received attachment is untrusted, sender-controlled metadata. It is interpolated directly into a filesystem path without sanitization or containment validation. A filename containing path traversal components, such as `../../config.json`, may escape the intended `./downloads` directory. Depending on platform path semantics, absolute paths, alternate separators, and encoded or normalized traversal components may create similar risks. The use of `writeFileSync` overwrites an existing destination by default. Consequently, the example can cause an implementing agent to write attacker-supplied decrypted content to any location writable by the agent process. ### Attack Path 1. An attacker sends an XMTP remote attachment to the agent. 2. The attachment metadata contains a crafted filename such as `../../app/config.json`. 3. `downloadRemoteAttachment` returns the decrypted attachment and its filename. 4. The handler concatenates the filename with `./downloads/`. 5. The filesystem normalizes the resulting traversal path. 6. `writeFileSync` writes attacker-controlled attachment data outside the intended download directory. 7. If the overwritten file is configuration, application code, or another security-relevant resource, subsequent application behavior may be altered. ### Impact Assessment Exploitation allows arbitrary file creation or overwrite within the operating-system p ...[truncated 580 chars]- Remediation
View remediation
