Files
ep-mail-client/ANDROID_SECURITY_PLAN.md
T

13 KiB
Raw Blame History

Android security plan for ep-mail

Status: Experimental Android OpenPGP implementation for local testing; security review and release gate remain open. This document tracks Android protections and the remaining work. Neither the test implementation nor this plan is a security certification or a substitute for an independent review.

Related: ENCRYPTION_PLAN.md, SECURITY_REVIEW.md, and TODO.md.

Implementation progress (2026-11-03)

  • Implemented: explicit Android cleartext denial and backup/data-extraction exclusions; removed the wildcard Cordova origin and unused broad FileProvider; DAV now requires HTTPS, rejects embedded credentials/fragments, stays on the configured origin, and does not follow redirects; saved attachment names are sanitized; notification details are opt-in, stored in the encrypted vault, and redacted on the lock screen; the optional native Android app lock covers the WebView, disables JavaScript bridge access while locked, and uses the device credential without blocking background sync; native logs no longer expose mailbox content; debug APKs are labeled as debug and signed release builds require environment-provided signing credentials.
  • Tested: DAV URL, attachment-name, and notification privacy policies have Android unit tests. The optional app lock was exercised on an Android emulator with a device PIN, including background lock and unlock. Phone and landscape layouts were checked for horizontal overflow. The debug Android build and unit tests pass, as does the Node test suite.
  • Experimental Phase 2 implementation: Android now bundles the pinned OpenPGP.js 6.3.2, stores passphrase-protected keys and public contacts in the existing Keystore-encrypted vault, supports key generation/import/export, contact trust controls, PGP/MIME encrypt/sign, and on-demand PGP/MIME or inline-message decryption. Encrypted sends are converted to ciphertext before native sending or offline queueing; decrypted content is held in renderer memory only. Android key-server lookup is disabled, and PGP/MIME messages are capped at 25 MiB on the Android test path. This test path has not had an independent human cryptography review and is not approved for sensitive or production use.
  • Still open before release: independent cryptography/security review; native enforcement of trust/key-replacement and plaintext-downgrade decisions; full signed/inline-message and hostile-input parity tests; Android/GnuPG/Thunderbird interoperability; Keystore lifecycle/recovery and biometric design; invalid-certificate integration tests; device-level review of a production-signed merged APK; app-lock timeout and recovery polish; and resolution/compatibility review of the three moderate npm audit --omit=dev advisories in ip-address and the nodemailer/mailparser dependency chain.

Goals and limits

Protect account credentials and locally cached mail if app files are copied; prevent untrusted mail or renderer content from gaining native capabilities; protect message content in transit; give users control over sensitive previews and local unlock; and bring Android OpenPGP behavior up to the security guarantees already implemented on desktop.

This does not protect a device while malware or an attacker controls it, prevent a user from sending mail to an unintended recipient, or hide mail metadata from providers. OpenPGP protects message content only where recipients' keys are correctly managed. Android's system lock and device integrity remain important assumptions.

Existing protections to preserve and verify

  • AndroidAccountVault encrypts the combined account, cached-mail, draft, and outbox store using AES-GCM and an Android Keystore key.
  • The manifest sets allowBackup="false"; the background service and FileProvider are not exported.
  • IMAP and SMTP configure required STARTTLS. Mail HTML is sanitized, remote images are blocked until user approval, HTTP images are rejected, and the web CSP blocks remote connections, scripts in mail, frames, and forms.
  • The Android WebView calls native operations through a Capacitor plugin rather than making mail connections from the renderer.

These are implementation observations, not proof that all paths are safe. In particular, verify certificate and hostname validation for IMAP/SMTP and DAV, the generated release manifest/WebView configuration, and how app data behaves on Keystore errors. Do not silently replace a lost Keystore key with a new one and present the store as empty; fail closed and explain recovery/data-loss options.

Phased plan

Phase 0 — Android security baseline and release gate (P0)

  1. Establish a repeatable security checklist for the actual merged manifest and release APK: permissions, exported components, backup/data-extraction rules, cleartext policy, WebView debugging, file access, and Capacitor plugin exposure.
  2. Audit all native network clients. Require TLS, certificate-chain and hostname validation for IMAP/SMTP STARTTLS and DAV HTTPS; reject downgrade and insecure schemes. Add negative tests using invalid, expired, and mismatched certificates. Do not add certificate pinning by default; it creates rotation and recovery risks.
  3. Review all EpMailPlugin methods as an untrusted-input boundary. Validate IDs, folders, URLs, attachment sizes/types, and state transitions natively; return only data needed by the UI. Ensure external navigation permits only explicitly supported safe schemes and is always user initiated.
  4. Ensure release builds disable WebView debugging and do not include debug-only configuration. Keep signing keys outside the repository and CI logs. Publish only signed release artifacts, not the current debug APK output.
  5. Remove or sanitize sensitive diagnostics. Logs must not contain credentials, message bodies, subjects, recipient lists, attachment contents, passphrases, or raw protocol errors containing secrets. Use opaque IDs where correlation is needed.

Exit criteria: documented release manifest/config review; TLS validation and downgrade regression tests pass; no sensitive data in logs; release APK is signed and distinguishable from debug output.

Phase 1 — Local data and privacy controls (P0)

  1. Harden the encrypted vault: document the Keystore key's security properties and fallback behavior; use authenticated encryption with unique IVs; handle corruption, reinstall, lock-screen/key invalidation, and upgrades without plaintext fallback. Confirm all cached bodies, drafts, attachments, pending sends, DAV credentials, and account passwords remain inside the encrypted store or are deleted safely.
  2. Add explicit account removal and app-data deletion behavior, including queued messages, caches, downloaded attachments, and encryption keys. Test that deletion is complete within app-controlled storage and explain that exported files/backups are outside app control.
  3. Add a privacy setting for notification content. Default to generic “New mail” text without sender or subject; allow a user choice to show details. Apply the same rule to snooze reminders. Keep foreground-service notifications non-sensitive.
  4. Add optional app-lock behavior (immediate, after a delay, or off) using Android biometric/device credential authentication. Lock on background/resume and process recreation according to the chosen timeout; obscure sensitive UI in the task switcher. Make screenshot/screen-recording blocking an optional policy rather than an unconditional default.
  5. Keep background sync semantics separate from UI lock. Do not require biometric auth for every background sync if that would break notifications; instead define which credential/key material is available to background work, minimize it, and ensure the UI lock prevents reading local mail. Document that a UI lock is not equivalent to encrypting against a rooted or already-unlocked device.

Exit criteria: storage migration and failure tests; no plaintext fallback; app-lock/session tests across lifecycle events; notification privacy tests on supported Android versions; data removal tests.

Phase 2 — OpenPGP on Android (P0 before claiming encrypted-mail parity)

  1. Reuse the desktop OpenPGP.js protocol and MIME behavior only after the independent cryptography review is complete. Confirm the selected library/version and generated key formats interoperate with GnuPG and Thunderbird on Android too.
  2. Add an Android key store for private keys, public contacts, fingerprints, trust, and preferences. Protect the store with a random Android Keystore-wrapped encryption key. Private keys must additionally remain passphrase-protected; never persist passphrases. Support a bounded in-memory passphrase cache and wipe it on expiry, lock, and process teardown where practical.
  3. Support biometric/device-credential unlock as an optional way to release the store-wrapping key. Design background sync so it never needs private-key access. Handle biometric enrollment/key invalidation without silently destroying or regenerating the user's key store; provide explicit recovery/export guidance.
  4. Add the narrow Android bridge and settings UI for key generation, import/export/delete, revocation certificate export, contact-key import, fingerprint comparison, and trust changes. Keep security decisions out of renderer-only code.
  5. Implement read and send paths: detect/decrypt PGP/MIME and supported inline PGP; verify signatures and show clear unknown/bad/changed-key states; encrypt/sign recipients and the sender's Sent copy; include attachments inside the encrypted MIME payload. Do not cache decrypted bodies or put plaintext/passphrases in drafts, logs, notifications, or offline outbox.
  6. Enforce key replacement, trust elevation, and plaintext downgrade confirmations in native code (or another boundary the renderer cannot bypass). Show recipient addresses and full fingerprints; cancellation must leave state unchanged. Never silently send plaintext when encryption was requested or keys exist.
  7. Leave key-server lookup/publication disabled/out of initial Android scope. If added later, make it opt-in, disclose address lookup, require explicit publish destination and confirmation, and never treat server results as verified.

Exit criteria: parity tests for desktop message formats and trust rules; Android-specific tests for cancel/confirm paths, tampering, malformed/oversized messages, key replacement, offline queueing, process death, and passphrase expiry; independent human review before release.

Phase 3 — WebView, native bridge, and content hardening (P1)

  1. Verify the production CSP and generated www assets match the reviewed source. Keep mail HTML inert and sanitized; do not allow remote script, CSS, frames, forms, or arbitrary navigation. Continue blocking remote images by default and reset approval per message.
  2. Restrict WebView navigation to the packaged app origin. External links must be parsed and scheme/host checked, shown to the user, and opened outside the WebView; reject javascript:, file:, content:, intent:, and unknown schemes.
  3. Review every Capacitor plugin/method and remove unused permissions/plugins. No generic filesystem, arbitrary intent, or unrestricted URL capability should be exposed to the renderer.
  4. Treat message HTML, headers, attachment names, filenames, sender data, key user IDs, and decrypted content as hostile input. Add sanitizer and UI regression cases for DOM injection, oversized payloads, spoofed signature indicators, and malicious filenames.

Exit criteria: automated CSP/navigation/bridge tests, sanitizer regressions, and a manual WebView inspection on the minimum and target Android versions.

Phase 4 — Assurance, maintenance, and incident readiness (P1)

  1. Add Android dependency vulnerability checks and update policy for Capacitor, AndroidX, mail libraries, OpenPGP.js, and Gradle plugins. Review licenses and lock versions for security-critical dependencies.
  2. Run static analysis and Android-focused checks (including merged-manifest review and OWASP MASVS-aligned test cases) on release builds. Keep test evidence tied to the exact APK version/hash.
  3. Perform independent reviews of the Android Keystore/vault, Capacitor bridge, network/TLS configuration, and OpenPGP integration before describing Android as security-reviewed.
  4. Publish a concise Android security and recovery page: device-lock assumptions, notification/image privacy, TLS, local encryption, OpenPGP limits, key backup/revocation, and what account/key deletion does.
  5. Define a private vulnerability-reporting contact, triage process, supported Android version range, and security-fix release process.

Minimum release criteria for Android OpenPGP

  • Phases 0–2 are complete and reviewed; no known high/critical issue remains open.
  • No downgrade path can bypass native confirmation; cancellation and stale-key scenarios are tested.
  • Secret key material is encrypted at rest; plaintext and passphrases do not enter persistent queues or logs.
  • Android-generated and Android-consumed messages pass the same interop and tampering tests as desktop.
  • The release APK and its manifest/configuration are reviewed and signed; recovery behavior is documented.

Out of scope for the first security release

  • Guaranteeing security on rooted/compromised devices or protecting against OS-level screen capture by privileged software.
  • Mandatory certificate pinning, remote wipe, enterprise MDM controls, or automatic key-server use.
  • S/MIME, automatic trust, or claiming that TLS protects mail content from mail providers.