Skip to content

Vulnerability Management

Software has vulnerabilities. The goal isn't to have zero — it's to find and fix them quickly.

Dependency Scanning

Python Dependencies

Scan for known vulnerabilities in Python packages:

Bash
# Install safety
pip install safety

# Scan requirements
safety check -r requirements.txt

# Scan installed packages
safety check

Run this in CI on every PR and weekly on main.

Alternative: pip-audit

Bash
pip install pip-audit
pip-audit -r requirements.txt

Docker Image Scanning

Scan container images for OS-level vulnerabilities:

Bash
# Using Trivy (recommended)
trivy image mailyte-api:latest
trivy image mailyte-postfix:latest
trivy image mailyte-dovecot:latest
trivy image mailyte-rspamd:latest

# Scan all images
for img in api postfix dovecot rspamd cert_manager tracking webhooks analytics; do
  echo "=== mailyte-${img} ==="
  trivy image --severity HIGH,CRITICAL mailyte-${img}:latest
done

GitHub Dependabot

If the repo is on GitHub, enable Dependabot:

YAML
# .github/dependabot.yml
version: 2
updates:
  - package-ecosystem: "pip"
    directory: "/"
    schedule:
      interval: "weekly"
    open-pull-requests-limit: 10

  - package-ecosystem: "docker"
    directory: "/worker/api"
    schedule:
      interval: "weekly"

  - package-ecosystem: "docker"
    directory: "/mailer/postfix"
    schedule:
      interval: "weekly"

Container Image Updates

Base Image Policy

Base Image Update Frequency How
python:3.11-slim Monthly Rebuild worker images
mysql:8.0 Monthly Pull latest tag
redis:7-alpine Monthly Pull latest tag
Postfix/Dovecot/Rspamd Monthly Rebuild from upstream

Update Process

Bash
# Pull latest base images
docker compose pull

# Rebuild all images with latest bases
docker compose build --no-cache

# Test
docker compose up -d
# Run health checks and tests

# Deploy
docker compose up -d

Automated Image Updates

Use a tool like Watchtower for automatic updates (use cautiously in production):

YAML
watchtower:
  image: containrrr/watchtower
  volumes:
    - /var/run/docker.sock:/var/run/docker.sock
  environment:
    - WATCHTOWER_CLEANUP=true
    - WATCHTOWER_SCHEDULE=0 0 4 * * MON  # 4am every Monday
    - WATCHTOWER_NOTIFICATIONS=slack

Security Patches

Response Timeline

Severity Response Time Patch Time
Critical (CVSS 9.0+) Same day 24 hours
High (CVSS 7.0-8.9) 24 hours 72 hours
Medium (CVSS 4.0-6.9) 1 week Next release
Low (CVSS < 4.0) Next sprint Next release

Patch Process

  1. Assess — determine if the vulnerability affects Mailyte
  2. Isolate — if actively exploited, apply a workaround immediately
  3. Fix — update the dependency or apply a code fix
  4. Test — verify the fix doesn't break anything
  5. Deploy — push to production
  6. Communicate — notify affected users if data was exposed

Common Vulnerability Areas

Email-Specific Risks

Risk Mitigation
Open relay SASL auth required for submission, strict mynetworks
Header injection Postfix sanitizes headers
Content spoofing DKIM/SPF/DMARC validation
Buffer overflow in SMTP Keep Postfix/Dovecot updated
SSRF via webhooks Validate webhook URLs, block internal IPs

Application Risks

Risk Mitigation
SQL injection Parameterized queries everywhere
XSS API-only (no HTML rendering), proper content types
CSRF API uses key-based auth, no cookies
Auth bypass API key validation on every request
Path traversal No user-controlled file paths
Dependency vulnerabilities Regular scanning (see above)

Security Monitoring Integration

Feed vulnerability scan results into your monitoring:

Bash
# Export Trivy results as Prometheus metrics
trivy image --format json mailyte-api:latest | \
  python3 scripts/trivy_to_prometheus.py > /var/lib/node-exporter/textfile/vulnerabilities.prom

Alert when new critical vulnerabilities are found:

YAML
- alert: CriticalVulnerability
  expr: mailyte_vulnerabilities{severity="CRITICAL"} > 0
  for: 1h
  labels:
    severity: critical
  annotations:
    summary: "Critical vulnerability found in {{ $labels.image }}"

Checklist

  • Python dependency scanning in CI
  • Docker image scanning in CI
  • Dependabot or similar enabled
  • Base images updated monthly
  • Security patch response timeline defined
  • CVE monitoring for Postfix, Dovecot, Rspamd
  • SSRF protection on webhook URLs
  • SQL injection prevention verified
  • Regular penetration testing (annually)