Skip to content

fix(pgp): require real PGP/MIME structure for encryption gate - #128

Draft
KamyarAT wants to merge 1 commit into
mainfrom
fix/pgp-encryption-substring-bypass
Draft

fix(pgp): require real PGP/MIME structure for encryption gate#128
KamyarAT wants to merge 1 commit into
mainfrom
fix/pgp-encryption-substring-bypass

Conversation

@KamyarAT

Copy link
Copy Markdown
Collaborator

Summary

The PGP-only gate accepted any message containing the raw substring application/pgp-encrypted, including when that token only appeared in Subject, body text, MIME parameters, or other non-structural places. Attackers could therefore submit cleartext (or weakly structured) mail that still passed the encryption check.

This PR requires a real PGP/MIME structure: root Content-Type: multipart/encrypted and a part with Content-Type: application/pgp-encrypted (RFC 3156 control part). Secure-Join multipart/mixed handshakes and mailer-daemon + multipart/report bounces remain allowed.

Regression coverage from the earlier marker suite is restored and expected to pass with the production fix.

Type of change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature that would cause existing behavior to change)
  • Documentation only
  • Build / CI / tooling
  • Refactor (no functional change)

Area

  • SMTP
  • IMAP
  • Federation / delivery queue
  • Authentication / JIT
  • Admin API / admin web UI (external/madmail-admin-web)
  • TURN / Iroh / proxy services
  • Storage / quota / DB migrations
  • Configuration / CLI
  • Docs (docs/project/, docs/TDD/, user guide)
  • Other: chatmail-pgp encryption gate

Testing

  • cargo fmt --all -- --check
  • cargo clippy -p chatmail-pgp -p chatmail-smtp --all-targets -- -D warnings
  • cargo test -p chatmail-pgp --lib (30/30)
  • cargo test -p chatmail-smtp --lib (37/37, includes marker → 523 and real PGP/MIME → 250)
  • Manual / E2E verification (describe below)

Manual verification (if any):

cargo test -p chatmail-pgp --lib
cargo test -p chatmail-smtp --lib smtp_rejects_pgp_marker
cargo test -p chatmail-smtp --lib smtp_still_accepts_real_pgp_mime

Documentation

  • No doc updates needed
  • Updated operator/user docs (docs/project/user-guide/, install guides)
  • Updated developer docs (docs/project/)
  • Updated or added TDD section (docs/TDD/)

Security & privacy

  • Not security-sensitive
  • Security-sensitive — added/updated tests for the security property
  • Reviewed error messages for information leakage

Failures still surface as 523 Encryption Needed / EncryptionNeeded without leaking internal structure details.

Commits

  • fix: bug fix

Checklist

  • PR is focused and reviewable (small vertical slices preferred)
  • No secrets, data/, target/, or node_modules/ committed
  • Submodule pointers updated if external/madmail-admin-web changed
  • Behavior parity with Madmail v1 considered (or intentional difference documented)

Aligns with TDD/security policy: properly formed multipart/encrypted PGP/MIME, Secure-Join, and bounce exceptions only.

Stop accepting mail when application/pgp-encrypted appears only as a
raw substring. Accept only multipart/encrypted messages that include an
application/pgp-encrypted control part, plus Secure-Join and bounce
exceptions. Restore marker-bypass regression tests (unit + SMTP 523)
and fix the SMTP test DATA harness so blank MIME lines are preserved.
@KamyarAT KamyarAT self-assigned this Jul 30, 2026
@KamyarAT KamyarAT added the bug Something isn't working label Jul 30, 2026
@KamyarAT KamyarAT moved this from Todo to In Review in madmail-v2 Jul 30, 2026
@omidz4t

omidz4t commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

I think this must be a feature that we can activate it on the dashboard panel as an service option to enforce it hardy + know the cost of it

@KamyarAT
KamyarAT marked this pull request as draft August 14, 2026 09:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

Status: In Review

Development

Successfully merging this pull request may close these issues.

2 participants