This document outlines security features and considerations for the mail-mcp MCP server.
All IMAP connections require TLS encryption by default. Insecure connections are rejected.
# Per-account (default: true)
MAIL_IMAP_<ACCOUNT>_SECURE=true
# Common IMAP TLS ports
MAIL_IMAP_<ACCOUNT>_PORT=993 # IMAPS (implicit TLS)- TLS certificate verification is enforced
- Hostname verification is performed
- Connection failures occur if certificates cannot be validated
- STARTTLS is not supported; use implicit TLS (IMAPS) on port 993
Passwords are handled with strict secrecy guarantees:
- Passwords are stored using Rust's
SecretStringtype - Passwords are never included in log output
- Passwords are never returned in tool responses
# Password in environment (never logged)
MAIL_IMAP_DEFAULT_PASS=your-app-password- Use app-specific passwords instead of account passwords when available
- Never commit
.envfiles to version control - Use secure credential managers for production deployments
- Rotate credentials periodically
Destructive operations are disabled by default and require explicit opt-in.
MAIL_IMAP_WRITE_ENABLED=trueWhen MAIL_IMAP_WRITE_ENABLED=false, these tools return errors:
imap_update_message_flags- Add/remove flagsimap_copy_message- Copy messagesimap_move_message- Move messagesimap_delete_message- Delete messages
imap_delete_message requires explicit confirmation regardless of write gating:
{
"account_id": "default",
"message_id": "imap:default:INBOX:12345:42",
"confirm": true // Required literal true
}All potentially large outputs are bounded to prevent resource exhaustion.
{
"body_max_chars": 2000 // Range: 100..20000, default: 2000
}- HTML is sanitized using
ammoniabefore return - Potentially dangerous tags and attributes are stripped
- CSS styles are removed
- JavaScript is completely removed
{
"extract_attachment_text": true,
"attachment_text_max_chars": 10000 // Range: 100..50000, default: 10000
}{
"max_bytes": 200000 // Range: 1024..1000000, default: 200000
}PDF text extraction is limited to attachments ≤ 5MB. Larger attachments are skipped but do not fail the tool call.
All inputs are validated before IMAP operations:
query,from,to,subject: 1..256 charactersaccount_id: 1..64 characters, pattern^[A-Za-z0-9_-]+$mailbox: 1..256 characterslimit: 1..50 messages
- Search text fields must not contain ASCII control characters
- Mailbox names must not contain ASCII control characters
Searches matching more than 20,000 messages are rejected:
Error: invalid input: search matched 25000 messages; narrow filters to at most 20000 results
Resolution: Add tighter filters (last_days, from, subject, date ranges).
All network operations have configurable timeouts:
# Connection establishment
MAIL_IMAP_CONNECT_TIMEOUT_MS=30000 # 30 seconds
# Server greeting
MAIL_IMAP_GREETING_TIMEOUT_MS=15000 # 15 seconds
# Socket operations (idle, read, write)
MAIL_IMAP_SOCKET_TIMEOUT_MS=300000 # 5 minutesTimeouts prevent indefinite hanging and ensure the server remains responsive.
- Passwords are never logged
- Secret-like keys (
*_PASS,*_TOKEN,*_KEY) are redacted in logs - Message bodies and attachments are not logged
All tool responses include metadata for auditing:
{
"meta": {
"now_utc": "2024-02-26T10:30:45.123Z",
"duration_ms": 245
}
}- Use app passwords: For Gmail, Outlook, and other services, use app-specific passwords rather than account passwords
- Enable 2FA: Require two-factor authentication on email accounts
- Review access logs: Periodically review email account access logs for suspicious activity
- Restrict write access: Keep
MAIL_IMAP_WRITE_ENABLED=falseunless needed - Secure .env files: Ensure
.envfiles have restrictive permissions (chmod 600 .env)
- Principle of least privilege: Run the server with minimal required permissions
- Network isolation: Deploy in isolated network segments where possible
- Regular updates: Keep dependencies and the server updated
- Audit logs: Monitor server logs for unusual patterns or errors
- Rate limiting: Consider implementing additional rate limiting at the infrastructure layer
- Security review: Changes to security-sensitive code should be reviewed
- Dependency auditing: Regularly audit dependencies for vulnerabilities
- Test boundaries: Test input validation and output bounding thoroughly
- Secret management: Never hardcode credentials in code or tests
- No STARTTLS support: Only implicit TLS (IMAPS) is supported
- No certificate pinning: Certificates are validated per standard PKI; custom CA chains are not supported
- No client authentication: Client certificates are not supported
- No encryption at rest: Credentials are in memory only; disk encryption is the user's responsibility