T09 · Insecure Skill Coding Practices
- Location
gmail_enhanced.py:483- Finding
Untrusted Attachment Filename Allows Arbitrary File Overwrite
- Content
View full analysis
- Remediation
View remediation
Security audit
Security checks for vulnerabilities and agentic risk
This Gmail skill does what it says, but it handles powerful mailbox access, persistent OAuth tokens, automatic replies, and attachment downloads with insufficient safety controls.
Review this carefully before installing. Use a dedicated Google OAuth client with the minimum Gmail scopes you need, keep credential and token files private, avoid shared machines or repos, and do not run attachment downloads or auto-reply rules unless you trust the mailbox inputs and have added filename validation, overwrite protection, confirmation, and rate limits.
gmail_enhanced.py:483Untrusted Attachment Filename Allows Arbitrary File Overwrite
gmail_enhanced.py:82Gmail OAuth Refresh Token Is Stored Without Explicit Restrictive Permissions
Referencing credentials.json in itself is expected for OAuth-based Gmail integration, but the skill normalizes handling raw credential material without security controls or warnings. In context, this increases the chance that users will download, store, and reuse sensitive client secrets insecurely, enabling account compromise if those files are stolen.
1. Enable Gmail API in Google Cloud Console
2. Create OAuth 2.0 credentials
3. Download credentials.json
4. Generate tokens.json (run once with authentication)
## Configuration
The environment variable examples directly point to credential and token file paths, signaling that the skill will access high-value authentication artifacts from the local environment. Without guidance on secure handling, this can lead to accidental disclosure through shell history, process inspection, misconfigured environments, or shared execution contexts.
export GMAIL_CREDENTIALS_PATH="/path/to/credentials.json"
export GMAIL_TOKEN_PATH="/path/to/tokens.json"
Publishing predictable default locations for Gmail credential and token files makes discovery easier on shared or compromised systems, especially if permissions are weak. Because these files can grant persistent Gmail access, their presence in standard paths materially raises the risk of credential theft.
Or place credentials in default locations:
- `~/.credentials/gmail-credentials.json`
- `~/.credentials/gmail-token.json`
## Usage
Code accesses credential files (SSH keys, AWS credentials, etc.). This could indicate credential theft attempts.
):
self.credentials_path = credentials_path or os.getenv(
"GMAIL_CREDENTIALS_PATH",
"~/.credentials/gmail-credentials.json"
)
self.token_path = token_path or os.getenv(
"GMAIL_TOKEN_PATH",
The skill describes capabilities that inherently require environment variable access, filesystem reads/writes, and network access, but it does not declare any tool scope or permissions boundary. This creates an authorization gap where the runtime may grant broader access than users expect, increasing the risk of credential exposure, unintended mailbox modification, or unsafe attachment handling.
The attachment handling section promotes downloading, uploading, filtering, and extracting attachments to cloud storage without warning about malware, sensitive-data leakage, or unsafe storage locations. Attachments are a common delivery mechanism for malicious content, and automatic extraction or syncing can spread risk beyond the mailbox.
The email processing section advertises auto-categorization, data extraction, auto-reply rules, and bounce detection without clearly warning that these features can automatically send messages or modify mailbox state. Users may enable workflows that act on live email data without understanding the consequences, leading to unintended replies, data mishandling, or destructive mailbox changes.
The setup instructions tell users to create and store OAuth credential and token files, including default filesystem locations, but provide no warning that these files are highly sensitive secrets. If exposed through weak permissions, backups, logs, or shared systems, an attacker could gain lasting access to the user's Gmail account within the granted scopes.
The instruction to generate tokens.json once and reuse it establishes session persistence, which is functionally normal for OAuth but also means a stolen token can provide ongoing access without repeated authentication. In the context of Gmail automation with modify/send scopes, persistent tokens meaningfully increase the blast radius of local compromise.
## Prerequisites
1. Enable Gmail API in Google Cloud Console
2. Create OAuth 2.0 credentials
3. Download credentials.json
4. Generate tokens.json (run once with authentication)
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.
message_list_visibility: str = "show",
color: str = None
) -> Dict:
"""Create label"""
service = self._get_service()
body = {
The skill can automatically download email attachments and write them to an arbitrary local path without any confirmation, filename sanitization, or trust boundary checks. In an agent setting, this creates a risky bridge from untrusted email content to the local filesystem, enabling silent persistence of attacker-controlled files or overwrite of existing files when filenames collide or paths are manipulated by the caller.
The rule engine can send outbound auto-reply emails automatically based on matching inbound messages, with no approval step, rate limiting, or sender validation. In practice this can be abused by malicious emails to trigger unsolicited responses, data leakage in replies, mail loops, or reputation damage from automated sending.