Back to skill

Security audit

Simple Email

Security checks for vulnerabilities and agentic risk

Overview

This email skill mostly does what it says, but it needs review because attachment downloads can overwrite local files and the sample configuration allows broad workspace file access.

Install only if you are comfortable giving this skill access to read and send mail from the configured account. Use an app password or authorization code, keep .env private, avoid disabling certificate verification unless you control the server, and set ALLOWED_READ_DIRS and ALLOWED_WRITE_DIRS to narrow dedicated folders rather than the OpenClaw workspace. Review attachment names before downloading because a message sender can choose filenames that may replace existing files in the allowed download folder.

Vulnerability Patterns
  • Insecure Skill Coding PracticesFinds exploitable flaws such as hardcoded secrets or command injection
  • Skill Instruction HijackingAlters the agent's session goals or safety constraints when the skill loads
  • Agent Memory PoisoningWrites attacker-controlled rules into memory that affect later sessions
  • Remote Payload Retrieval and ExecutionFetches external code whose behavior can change after review
  • Embedded Malicious CodeShips malicious scripts inside the skill and executes them locally
Findings (1)

T09 · Insecure Skill Coding Practices

Warning
Location
scripts/imap.js:16
Finding
Attachment Download Can Overwrite Files and Follow Symbolic Links<![CDATA[ ## Vulnerability Details **File Location**: `scripts/imap.js`, lines 16–35 and 322–323 **Vulnerability Type**: Symlink-following path validation and unrestricted file overwrite **Risk Level**: Medium ### Vulnerable Code ```javascript function validateWritePath(dirPath) { const allowedDirsStr = process.env.ALLOWED_WRITE_DIRS; if (!allowedDirsStr) { throw new Error('ALLOWED_WRITE_DIRS not set in .env. Attachment download is disabled.'); } const resolved = path.resolve(dirPath.replace(/^~/, os.homedir())); const allowedDirs = allowedDirsStr.split(',').map(d => path.resolve(d.trim().replace(/^~/, os.homedir())) ); const allowed = allowedDirs.some(dir => resolved === dir || resolved.startsWith(dir + path.sep) ); if (!allowed) { throw new Error(`Access denied: '${dirPath}' is outside allowed write directories`); } return resolved; } ``` ```javascript for (const attachment of parsed.attachments) { // If specificFilename is provided, only download matching attachment if (specificFilename && attachment.filename !== specificFilename) { continue; } if (attachment.content) { const filePath = path.join(resolvedDir, sanitizeFilename(attachment.filename)); fs.writeFileSync(filePath, attachment.content); downloaded.push({ filename: attachment.filename, path: filePath, size: attachment.size, }); } } ``` ### Technical Analysis The output-directory validation uses `path.resolve()`, which only performs lexical path normalization. It does not resolve symbolic links or verify that the actual filesystem destination remains beneath an authorized directory. Although `sanitizeFilename()` removes directory traversal components by retaining the basename, the final destination is passed directly to `fs.writeFileSync()`. This operation: - Follows an existing symbolic link at the destination. - Silently truncates and overwrites an existing file. - Does not use exclusive creation. - Does ...[truncated 2762 chars]
Remediation
<![CDATA[ ## Remediation Suggestions 1. **Canonicalize allowed directories and the destination parent** - Resolve configured directories with `fs.realpathSync()`. - After creating the output directory, resolve it again and verify that its canonical path is equal to or beneath a canonical allowed directory. - Reject output directories containing unexpected symbolic-link components. 2. **Reject symbolic-link destinations** - Call `fs.lstatSync()` when a destination already exists. - Refuse to write if the destination is a symbolic link. - Where supported, open files with `O_NOFOLLOW`. 3. **Prevent silent replacement** - Create attachment files with exclusive mode: ```javascript fs.writeFileSync(filePath, attachment.content, { flag: 'wx', mode: 0o600, }); ``` - If a filename already exists, fail safely or generate a collision-resistant filename. 4. **Use a dedicated download directory** - Do not recommend the Agent workspace as the default writable directory. - Create a private attachment directory that contains no executable code, configuration, instructions, or persistent Agent state. - Apply restrictive directory permissions. 5. **Validate the final destination immediately before writing** - Recheck containment after resolving the parent directory. - Keep validation and file creation in one operation where possible to reduce time-of-check/time-of-use race conditions. 6. **Apply file-size and count limits** - Limit attachment size and the number of attachments written per message to reduce resource-exhaustion risk. ]]>
Vulnerability Patterns
  • Privilege EscalationExcessive Permissions, Sudo/Root Execution, Credential Access
  • MCP Tool PoisoningHidden Instructions, Unicode Deception, Parameter Description Injection
  • Prompt InjectionInstruction Override, Hidden Instructions, Exfiltration Commands
  • Data ExfiltrationExternal Transmission, Env Variable Harvesting, File System Enumeration
  • Supply ChainUnpinned Dependencies, External Script Fetching, Obfuscated Code
Findings (53)

Tp4

High
Category
MCP Tool Poisoning
Confidence
92% confidence
Finding
代码的主要行为与描述大体相关,确实实现了查看未读邮件、搜索邮件、标记已读/未读、下载附件,并兼容标准 IMAP 服务;还额外提供了列出邮箱文件夹功能,这可视为邮件技能的辅助能力,不构成明显越权。核心不匹配在于声明强调 IMAP/SMTP 且支持‘收发邮件’,但提供的代码文件只有 IMAP 客户端逻辑,没有任何 SMTP 连接、认证、发信、草稿或发送命令实现。因此描述高估了能力,属于实质性描述不准确。

Tp4

High
Category
MCP Tool Poisoning
Confidence
98% confidence
Finding
描述将该技能表述为完整的 IMAP/SMTP 邮件工具,覆盖收发和邮箱管理功能;但提供的代码片段是一个 SMTP CLI,只负责发信与连接测试。它会读取本地文件内容作为邮件主题/正文/附件,并通过环境变量配置的 SMTP 服务器发送邮件。代码没有任何 IMAP 连接、收件箱读取、邮件状态修改、附件下载等行为。因此,声明的主要能力明显超出代码实际实现范围,属于描述与行为不一致。

Tp4

High
Category
MCP Tool Poisoning
Confidence
96% confidence
Finding
The code chunk does relate to an IMAP/SMTP email skill, so the broad domain matches. However, the declared description emphasizes end-user email operations such as sending/receiving, unread mail viewing, search, marking read/unread, and attachment download. This specific code instead performs installation/setup tasks: it prompts for credentials, stores them in .env, sets file access whitelist directories, allows disabling certificate validation, and runs IMAP/SMTP connection tests. Those are materially different capabilities not disclosed in the description, especially credential capture/storage and filesystem whitelist configuration. Therefore the description does not accurately represent what this supplied code chunk actually does.

Credential Access

High
Category
Privilege Escalation
Content
复制配置模板并填写你的邮箱信息:

```bash
cp .env.example .env
```

编辑 `.env` 文件,填入你的邮箱配置:
Confidence
89% confidence
Finding
The skill instructs users to place IMAP/SMTP credentials into a local .env file, which creates a concentrated secret store that may be exposed through accidental commits, weak local file permissions, agent file access, or logs. Because these are live mail credentials, compromise could enable mailbox access, email exfiltration, impersonation, and password-reset abuse across other services tied to the mailbox.

Ae1

High
Category
analysis-evasion
Content
node scripts/imap.js check --limit 5
Confidence
100% confidence
Finding
Referenced artifact was not completely inspected

Ae1

High
Category
analysis-evasion
Content
node scripts/imap.js check --limit 5
Confidence
100% confidence
Finding
Referenced artifact was not completely inspected

Ae1

High
Category
analysis-evasion
Content
node scripts/imap.js check --limit 5
Confidence
100% confidence
Finding
Referenced artifact was not completely inspected

Ae1

High
Category
analysis-evasion
Content
node scripts/imap.js check --limit 5
Confidence
100% confidence
Finding
Referenced artifact was not completely inspected

Ae1

High
Category
analysis-evasion
Content
node scripts/imap.js check --limit 5
Confidence
100% confidence
Finding
Referenced artifact was not completely inspected

Ae1

High
Category
analysis-evasion
Content
node scripts/imap.js check --limit 5
Confidence
100% confidence
Finding
Referenced artifact was not completely inspected

Ae1

High
Category
analysis-evasion
Content
node scripts/imap.js check --limit 5
Confidence
100% confidence
Finding
Referenced artifact was not completely inspected

Ae1

High
Category
analysis-evasion
Content
node scripts/imap.js check --limit 5
Confidence
100% confidence
Finding
Referenced artifact was not completely inspected

Ae1

High
Category
analysis-evasion
Content
node scripts/imap.js check --limit 5
Confidence
100% confidence
Finding
Referenced artifact was not completely inspected

Ae1

High
Category
analysis-evasion
Content
node scripts/imap.js check --limit 5
Confidence
100% confidence
Finding
Referenced artifact was not completely inspected

Ae1

High
Category
analysis-evasion
Content
node scripts/imap.js check --limit 5
Confidence
100% confidence
Finding
Referenced artifact was not completely inspected

Ae1

High
Category
analysis-evasion
Content
node scripts/imap.js check --limit 5
Confidence
100% confidence
Finding
Referenced artifact was not completely inspected

Ae1

High
Category
analysis-evasion
Content
node scripts/imap.js check --limit 5
Confidence
100% confidence
Finding
Referenced artifact was not completely inspected

Ae1

High
Category
analysis-evasion
Content
node scripts/imap.js check --limit 5
Confidence
100% confidence
Finding
Referenced artifact was not completely inspected

Ae1

High
Category
analysis-evasion
Content
node scripts/imap.js check --limit 5
Confidence
100% confidence
Finding
Referenced artifact was not completely inspected

Ae1

High
Category
analysis-evasion
Content
node scripts/imap.js check --limit 5
Confidence
100% confidence
Finding
Referenced artifact was not completely inspected

Ae1

High
Category
analysis-evasion
Content
node scripts/imap.js check --limit 5
Confidence
100% confidence
Finding
Referenced artifact was not completely inspected

Ae1

High
Category
analysis-evasion
Content
node scripts/imap.js check --limit 5
Confidence
100% confidence
Finding
Referenced artifact was not completely inspected

Ae1

High
Category
analysis-evasion
Content
node scripts/imap.js check --limit 5
Confidence
100% confidence
Finding
Referenced artifact was not completely inspected

Ae1

High
Category
analysis-evasion
Content
node scripts/imap.js check --limit 5
Confidence
100% confidence
Finding
Referenced artifact was not completely inspected

Ae1

High
Category
analysis-evasion
Content
node scripts/imap.js check --limit 5
Confidence
100% confidence
Finding
Referenced artifact was not completely inspected

Static analysis

Detected: suspicious.env_credential_access

Environment variable access combined with network send.

Critical
Code
suspicious.env_credential_access
Location
scripts/imap.js:17