Files
ep-mail-client/SECURITY_REVIEW.md
T
thuttu a9c52e7868 Fix PGP security review items and add architecture docs
- Harden key replacement in the Electron main process with a confirmation dialog showing the old and new fingerprints before accepting a replacement.
- Enforce plaintext-send checks in the main process before allowing a message to be sent without encryption when recipient keys exist.
- Reject the insecure Linux safeStorage basic_text backend before writing mail credentials or OpenPGP keys.
- Update the security review findings to reflect the fixes and mark the related TODO item as complete.
- Add a project architecture overview and link it from the main README.
2026-10-10 19:34:25 +03:00

4.4 KiB

Security review: OpenPGP encryption

Date: 2026-10-08 Version reviewed: 0.3.2 (working tree, uncommitted changes included) Type: automated review by an AI security-review agent. It is not a substitute for a human review.

Scope

  • desktop/pgp-keystore.cjs: key store, safeStorage wrapping, contacts, trust
  • desktop/pgp-mail.cjs: detect, decrypt, verify, build PGP/MIME, passphrase cache
  • pgp:* IPC handlers in desktop/main.cjs and desktop/preload.cjs
  • Renderer: pgp-mail-ui.js, pgp-ui.js, the pgpPrepareSend hook in mail-ui.js
  • Design reference: ENCRYPTION_PLAN.md

Focus areas: secret leaks (disk, logs, outbox, renderer), IPC abuse by a compromised renderer, HTML injection from key user IDs and decrypted content, signature status spoofing, key matching by fingerprint, silent downgrade to plaintext, malformed or oversized input, passphrase cache lifetime.

Findings

# Severity File Issue Confidence Status
1 🟡 MEDIUM pgp-mail-ui.js, mail-ui.js Encrypt-by-default is applied after a 300 ms debounced key lookup. Sending before it finished skipped the key check and sent the message unencrypted. 9/10 Fixed
2 🟡 MEDIUM desktop/preload.cjs, desktop/main.cjs, desktop/pgp-keystore.cjs A compromised renderer could add a public key for a recipient's address and call pgp:set-trust to mark it verified. Recipient key selection prefers higher trust, so later mail could be encrypted to the attacker's key. The confirmation existed only in the renderer UI. 8/10 Fixed

No critical or high severity issues were reported.

Fixes applied

  1. Send-time check: pgpPrepareSend now checks recipient keys when you press Send. If keys exist for all recipients and you did not change the Encrypt box yourself, it asks before sending unencrypted. Unticking Encrypt on purpose still sends without a prompt.
  2. Trusted confirmation: the pgp:set-trust handler in the main process shows a native dialog with the contact and fingerprint before raising trust. A cancelled dialog aborts the change. The renderer's own prompt may appear as well, so users can see two confirmations.

Verification

  • npm test: 20 passed, 0 failed (includes the GnuPG interoperability tests).
  • node --check on the edited files.
  • The fixes were not exercised in the running app.

Remaining work

  • Human review of the key store, the IPC boundary and the signature UI.
  • Replacement-key confirmation in the main process when a new key arrives for an address that already has a contact. The review suggested it, and only the trust confirmation was added.
  • Run npm audit and pin the OpenPGP.js version.
  • Re-run the GnuPG interoperability tests after dependency updates.
  • Android has no encryption support yet, so it was not reviewed.

Second review pass (2026-10-09)

Fresh review of the same scope after the first round of fixes. Tests: 20 passed, 0 failed. No code was changed in this pass.

# Severity File Issue Confidence Status
3 🟡 MEDIUM desktop/pgp-keystore.cjs, desktop/main.cjs pgp:add-contact adds a key for an address that already has one without a main-process confirmation. At equal trust the newest key wins recipient selection, so an added key can take over outgoing encryption. The trust dialog does not cover replacement. 9/10 Fixed
4 🟡 MEDIUM desktop/main.cjs, desktop/preload.cjs The send-time downgrade check exists only in the renderer. mail:send sends plaintext when pgp is omitted, so a compromised renderer can bypass the warning. 9/10 Fixed
5 🟡 MEDIUM desktop/main.cjs safeStorage is used without checking the backend. On Linux the basic_text backend uses a hardcoded password, so a copied store would expose account credentials and mail data. PGP private keys stay protected by their own passphrases. 8/10 Fixed

Applied fixes:

  • #3: native confirmation showing both fingerprints when a key overlaps existing contacts, and the add-contact flow aborts if the replacement is not confirmed.
  • #4: the main process checks recipient keys before allowing a plaintext send and shows a trusted confirmation dialog.
  • #5: Linux now rejects the insecure basic_text safeStorage backend and asks the user to switch to a secure system keyring before storing mail or PGP secrets.