Back to skill

Security audit

AgentMail sending and receiving with Python scripts

Security checks for vulnerabilities and agentic risk

Overview

This skill does what it says: it helps an agent send email and download unread AgentMail messages, with disclosed local storage and mailbox state changes.

Install only if you are comfortable giving the skill an AgentMail API key that can send mail, read unread messages, save message contents locally, and mark those messages as read. Protect ~/.openclaw/workspace/agentmail/.env with restrictive permissions, treat MAIL.* files as sensitive email data, and consider pinning dependencies before use.

Vulnerability Patterns
  • Insecure DependenciesIntroduces malicious components through unsafe dependency sources
  • 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
Findings (2)

T09 · Insecure Skill Coding Practices

Warning
Location
SKILL.md:44
Finding
AgentMail API key file is created without restrictive permissions<![CDATA[ ## Vulnerability Details **File Location**: `SKILL.md`, lines 44-46 **Vulnerability Type**: Insecure secret-file permissions **Risk Level**: Medium ### Vulnerable Code ```bash cat > ~/.openclaw/workspace/agentmail/.env << 'EOF' AGENTMAIL_API_KEY=am_us_..... EOF ``` ### Technical Analysis The setup instructions write the AgentMail API key to a plaintext `.env` file without explicitly setting restrictive file permissions. The resulting permissions depend on the user's current `umask`. With a common `022` umask, the file can be created with mode `0644`, making it readable by other local users if they can traverse the parent directories. The API key is legitimately required for the declared email functionality, but making it potentially accessible outside the Agent account exceeds the minimum access necessary. This is a local credential-disclosure risk rather than evidence that the Skill intentionally transmits the key to an unrelated service. ### Attack Path 1. A user follows the documented setup instructions under a permissive `umask`. 2. The shell creates `.env` with group-readable or world-readable permissions. 3. Another local account traverses the workspace path and reads the `.env` file. 4. The attacker extracts `AGENTMAIL_API_KEY`. 5. The attacker authenticates to AgentMail using the stolen credential. 6. Subject to the API key's server-side permissions, the attacker reads mailbox data or sends messages as the configured inbox. ### Impact Assessment Successful exploitation discloses the AgentMail API credential. The attacker may gain the mailbox privileges granted to that key, potentially including access to email content and metadata, modification of message state, and the ability to send messages as the configured inbox. The scope is limited by local filesystem accessibility and the permissions assigned to the API key. This issue does not itself grant operating-system privilege escalation. ]]>
Remediation
<![CDATA[ ## Remediation Suggestions Create the secret file with owner-only permissions and ensure its parent directory is also private. For example: ```bash DEST="$HOME/.openclaw/workspace/agentmail" mkdir -p "$DEST" chmod 700 "$DEST" umask 077 cat > "$DEST/.env" << 'EOF' AGENTMAIL_API_KEY=am_us_..... EOF chmod 600 "$DEST/.env" ``` Additional hardening measures: - Prefer injecting the key through a dedicated secret manager or protected runtime environment rather than storing it in a project file. - Verify ownership before reading the file. - Exclude `.env` from source control and backups that are not approved for secrets. - Rotate the API key if the file was previously created with permissive permissions. - Restrict the API key server-side to only the mailbox operations required by this Skill. ]]>

T08 · Insecure Dependencies

Warning
Location
SKILL.md:31
Finding
Third-party Python dependencies are installed without version or integrity pinning<![CDATA[ ## Vulnerability Details **File Location**: `SKILL.md`, lines 31-34 **Vulnerability Type**: Unpinned third-party dependencies **Risk Level**: Medium ### Vulnerable Code ```bash uv pip install --python venv/bin/python agentmail python-dotenv else python3 -m venv venv venv/bin/pip install agentmail python-dotenv ``` ### Technical Analysis The setup process installs `agentmail` and `python-dotenv` by package name without fixed versions, a lock file, or cryptographic hashes. Each installation may therefore resolve to whatever package versions are current in the configured Python package index. This creates a supply-chain exposure: a compromised upstream release, compromised package-index account, or unexpected incompatible update could introduce code that executes when the package is imported. Both project scripts import these dependencies, and the resulting process has access to the AgentMail API key and the Agent user's filesystem privileges. There is no evidence in the reviewed project that the named packages are currently malicious. The vulnerability is the absence of reproducible and integrity-verified dependency resolution. ### Attack Path 1. An attacker compromises an upstream dependency release or its package-index publishing account. 2. The attacker publishes a malicious version under the legitimate package name. 3. A user follows the Skill setup instructions after that release becomes the version selected by the package installer. 4. The unpinned installation downloads and installs the malicious package. 5. The user runs `check_mail.py` or `send_email.py`. 6. Python imports the compromised dependency, executing attacker-controlled package code. 7. The malicious code accesses the API key, email data, local files, or network using the privileges of the Agent process. ### Impact Assessment A compromised dependency could execute arbitrary code as the user running the Skill. It could potentially steal the AgentMail API key, access down ...[truncated 409 chars]
Remediation
<![CDATA[ ## Remediation Suggestions Use reviewed, reproducible dependency versions and verify package integrity: 1. Pin exact versions of all direct and transitive dependencies. 2. Generate a lock file from a trusted environment. 3. Record and enforce cryptographic hashes, such as with: ```bash python -m pip install --require-hashes -r requirements.txt ``` 4. Review dependency changes before updating the lock file. 5. Use a trusted package index and prevent fallback to unapproved indexes. 6. Run vulnerability and provenance checks against locked dependencies. 7. Execute the Skill in a minimally privileged environment with access only to the required workspace and AgentMail credential. ]]>
Vulnerability Patterns
  • Privilege EscalationExcessive Permissions, Sudo/Root Execution, Credential Access
  • Rogue AgentSelf-Modification, Session Persistence
  • MCP Least PrivilegeUnderdeclared Capability, Wildcard Permission, Missing Permission Declaration
  • MCP Tool PoisoningHidden Instructions, Unicode Deception, Parameter Description Injection
  • Prompt InjectionInstruction Override, Hidden Instructions, Exfiltration Commands
Findings (8)

Tp4

High
Category
MCP Tool Poisoning
Confidence
90% confidence
Finding
The declared behavior understates materially important side effects: downloaded emails are persisted locally and unread messages are marked read remotely. That mismatch can cause users or agents to invoke the skill expecting passive email access, while it actually changes mailbox state and stores potentially sensitive message contents on disk.

Credential Access

High
Category
Privilege Escalation
Content
### Create the `.env` file

```bash
cat > ~/.openclaw/workspace/agentmail/.env << 'EOF'
AGENTMAIL_API_KEY=am_us_.....
EOF
```
Confidence
91% confidence
Finding
The skill directs users to place an API key in a plaintext .env file under a workspace directory. Even though this is a common pattern, storing long-lived credentials in local plaintext can enable credential theft through other workspace access, backups, logs, or accidental check-in, leading to unauthorized mailbox access and email operations.

Credential Access

High
Category
Privilege Escalation
Content
def main():
    load_dotenv(os.path.join(SCRIPT_DIR, ".env"))

    api_key = os.getenv("AGENTMAIL_API_KEY")
    if not api_key:
Confidence
60% confidence
Finding
Code accesses credential files (SSH keys, AWS credentials, etc.). This could indicate credential theft attempts.

Lp3

Medium
Category
MCP Least Privilege
Confidence
93% confidence
Finding
The skill performs filesystem writes and reads environment-backed credentials, but the manifest does not declare any tool scope or permission boundaries. That makes the capability less transparent to users and any execution framework, increasing the chance that sensitive actions occur without informed approval or sandboxing.

Session Persistence

Medium
Category
Rogue Agent
Content
### Deploy the skill

Copy the scripts and create the venv in the workspace:

```bash
DEST=~/.openclaw/workspace/agentmail
Confidence
60% confidence
Finding
Skill establishes unauthorized persistence across sessions via cron jobs, startup scripts, or state files. Session persistence allows an attacker to maintain access beyond the current interaction.

Missing User Warnings

Medium
Confidence
95% confidence
Finding
The skill instructs users to download full message contents into local MAIL.* JSON files and mark messages as read, but it does not present a prominent warning about these privacy and state-change consequences before use. This can expose sensitive email bodies, metadata, and attachments to other local processes or users, and can interfere with auditability of unread mail.

Intent-Code Divergence

Medium
Confidence
97% confidence
Finding
The top-level docstring describes a download-only behavior. However, later code performs a mailbox update that changes labels from unread to read, which is a meaningful side effect contradicting the stated intent of mere batch download.

Description-Behavior Mismatch

Medium
Confidence
95% confidence
Finding
The manifest description frames the skill as sending email and downloading received email from an inbox. In addition to downloading and saving messages, this code updates each message's labels to remove "unread" and add "read", which is a state-changing mailbox operation not conveyed by the description.

Static analysis

No suspicious patterns detected.