TLS Encryption
All IMAP connections require TLS encryption by default. The server enforces strict TLS verification to prevent man-in-the-middle attacks.Configuration
TLS is enabled by default for all accounts:.env
TLS Behavior
The server enforces the following TLS security measures (source/src/imap.rs:64-68):- Certificate verification: TLS certificates are validated against system root certificates
- Hostname verification: Server hostname is verified during TLS handshake
- Connection rejection: Connections fail if certificates cannot be validated
- No STARTTLS support: Only implicit TLS (IMAPS on port 993) is supported
Password Protection
Passwords are handled with strict secrecy guarantees throughout the application lifecycle.Secure Storage
Passwords are protected using Rust’sSecretString type (source/src/config.rs:19-33):
- Stored in memory using
SecretStringto prevent accidental logging - Never included in debug output or logs
- Never returned in tool responses or error messages
- Automatically cleared from memory when dropped
Environment Variables
Passwords must be provided via environment variables:.env
- Variables matching
*_PASS,*_TOKEN,*_KEYare redacted - Only non-sensitive configuration is logged at startup
Write Operation Protection
Destructive operations are disabled by default and require explicit opt-in to prevent accidental data modification.Enabling Write Operations
Write operations must be explicitly enabled via environment variable:.env
Protected Tools
WhenMAIL_IMAP_WRITE_ENABLED=false, the following tools return errors (source/docs/security.md:62-66):
imap_update_message_flags- Add/remove message flagsimap_copy_message- Copy messages between mailboxesimap_move_message- Move messages to different mailboximap_delete_message- Permanently delete messages
Delete Confirmation
Theimap_delete_message tool requires explicit confirmation regardless of write gating (source/src/server.rs:1512-1516):
Input Validation
All user inputs are validated before IMAP operations to prevent injection attacks and ensure data integrity.String Length Bounds
The server enforces strict length limits on all inputs (source/docs/security.md:124-129):query,from,to,subject: 1-256 charactersaccount_id: 1-64 characters, pattern^[A-Za-z0-9_-]+$mailbox: 1-256 characterslimit: 1-50 messages per page
Content Sanitization
All text inputs are sanitized to prevent IMAP protocol injection (source/src/server.rs:2039-2047):- Search text fields must not contain ASCII control characters
- Mailbox names must not contain ASCII control characters
- IMAP flags are validated against allowed patterns
Search Result Limits
Searches matching more than 20,000 messages are rejected to prevent resource exhaustion (source/src/server.rs:35):last_days, from, subject, or date ranges.
Output Bounding
All potentially large outputs are bounded to prevent resource exhaustion and ensure predictable performance.Message Body Text
Body text is limited to prevent excessive memory usage:HTML Sanitization
HTML content is sanitized using theammonia library (source/src/mime.rs:133):
- Potentially dangerous tags are stripped
- JavaScript is completely removed
- CSS styles are removed
- Only safe HTML elements are preserved
Attachment Text Extraction
PDF text extraction is bounded and failure-tolerant:- PDF extraction is limited to attachments ≤ 5MB
- Larger attachments are skipped without failing the request
Raw Message Source
RFC822 message source is bounded to prevent excessive data transfer:Timeout Protection
All network operations have configurable timeouts to prevent indefinite hanging and ensure server responsiveness.Timeout Configuration
Timeouts can be configured via environment variables (source/docs/security.md:150-158):.env
Timeout Behavior
- Connection timeout: Applied to TCP socket connection (source/src/imap.rs:73-79)
- Greeting timeout: Applied to TLS handshake and IMAP greeting (source/src/imap.rs:90-99)
- Socket timeout: Applied to all IMAP commands and data transfers
Logging and Auditing
The server provides comprehensive logging while protecting sensitive information.Log Redaction
Sensitive data is automatically redacted from logs:- Passwords: Never logged (source/src/config.rs:32)
- Secret keys: Variables like
*_PASS,*_TOKEN,*_KEYare redacted - Message bodies: Not included in logs
- Attachments: Not included in logs
Response Metadata
All tool responses include metadata for auditing (source/docs/security.md:173-181):- Performance monitoring
- Anomaly detection
- Audit trail creation
- Request correlation
Known Limitations
The following security features are not supported in the current implementation (source/docs/security.md:209-214):Next Steps
Security Best Practices
Learn recommended security practices for production deployments
Configuration Reference
Review all security-related configuration options