Security

Security

How mail is shown safely

How Postern cleans HTML mail, shows it without scripts in every app, loads remote images through a proxy, removes tracking pixels and handles links and attachments.

An email is a web page written by a stranger. This page explains how Postern shows HTML mail without letting it run code, track you, read your other mail or cover the app with a fake screen. It summarizes the security review in docs/dev/mail-rendering-security.md, which lists every threat, the code that handles it and the test that proves it.

The idea: several independent layers, so that a bug in one is not enough.

  1. The engine (the Hub, or the app's built-in engine in direct mode) cleans the HTML with an allow-list.
  2. Each app shows the result with scripts turned off and a strict Content Security Policy.
  3. Remote content only loads through a signed image proxy, and only when you allow it.

Layer 1: cleaning on the engine #

Before any app sees a message, the engine parses its HTML and keeps only what is on an allow-list. It parses the HTML into a tree (Go's x/net/html), removes what is dangerous, and then runs a second sanitizer (bluemonday) over the result.

Removed (most of these together with their content):

What Examples
Elements that run code or embed other content <script>, <iframe>, <frame>, <object>, <embed>, <template>, <slot>, <dialog>, <audio>, <video>, <canvas>, custom elements
Forms and inputs <form>, <input>, <button>, <textarea>, <select>
Elements that change how the page loads <link>, <meta http-equiv>, <base>
Foreign content SVG and MathML
Event handlers Every on... attribute, in any spelling
Attributes that load or change things srcdoc, formaction, ping, srcset, poster, remote background, xlink:href, is, popover, loading
Attributes that could hijack page behavior id and name (DOM clobbering), autofocus, tabindex, accesskey, contenteditable

Links keep only http:, https:, mailto: and tel: addresses, after decoding entities, tabs, newlines and odd casing. javascript:, vbscript:, data:, blob: and file: links are removed. Every link gets target="_blank" and rel="noopener noreferrer".

Style sheets are cleaned too:

  • Only a fixed list of CSS properties stays. position: fixed, absolute and sticky are refused, so a message cannot place a fake dialog over the app. Animations, filters, pointer-events, zoom, content and all are not on the list.
  • Only @media and @supports rules stay. @import, @font-face, @keyframes and others are dropped.
  • url() is rewritten to the image proxy (when remote images are allowed) or removed.
  • Selectors that could reach outside the message (:host, ::part, ::slotted, /deep/, >>>) are dropped.

Layer 2: showing it in the apps #

Web app and desktop app #

The web app (also inside the desktop app) shows a message in one of two ways:

  • Inline, drawn inside the page, which looks and scrolls like the rest of the app. Before drawing, the app checks the message again in the browser against its own allow-list of elements, attributes and CSS. The check runs on the browser's own parse of the HTML, and the checked nodes are moved into the page as they are, never turned back into text and parsed again, so differences between parsers cannot sneak anything past it. The message goes into its own shadow root, every style rule is scoped to it, and paint containment keeps it inside its box: it cannot style or cover the app's header, toolbar or warnings.
  • In a sandboxed frame (sandbox="allow-popups allow-popups-to-escape-sandbox"): no scripts and no access to the app's origin. The frame has its own policy (default-src 'none', images only from data:, blob: and your Hub), no referrer, and opens links in a new tab.

The app uses the frame whenever anything is unknown: an element, attribute or CSS feature outside its list, content in the document head, attributes on <body>, or more than 20,000 elements. It never repairs a message silently.

Inline drawing also requires proof that the page's Content Security Policy blocks inline scripts. The app runs a small probe the first time it opens a message; if an inline event handler could run, every message uses the frame. (That probe causes one "Refused to execute inline event handler" line in the browser console. The line means the protection works.)

Every HTML page from the Hub carries this policy:

default-src 'self'; script-src 'self'; style-src 'self' 'unsafe-inline'; img-src 'self' data: blob:;
font-src 'self' data:; connect-src 'self'; frame-src 'self' blob: data:; worker-src 'self'; manifest-src 'self';
object-src 'none'; base-uri 'self'; form-action 'self' postern: mailclient: exp:; frame-ancestors 'none'

script-src 'self' with no inline scripts means that even HTML that got past both checks could not run code. Images can come only from the Hub itself (the proxy and attachments), data: and blob:.

The desktop app adds Electron's own protections: pages run with contextIsolation, the Chromium sandbox and no Node.js access, and permission requests (camera, microphone, location and others) are refused except notifications.

iOS and Android #

The mobile app shows HTML mail in a web view sized to the message. The page it builds around the cleaned HTML has this policy:

default-src 'none'; img-src data: <your Hub or the app's engine>; style-src 'unsafe-inline';
font-src data:; script-src 'none'; form-action 'none'; frame-src 'none'; base-uri 'none'

JavaScript in the web view runs only a small script the app itself injects (to measure the height and to fetch or replace pictures that did not load); the page's policy blocks every script from the mail, and the Hub has already removed them. A picture that is blocked or cannot be loaded shows as a quiet box with its description, as in the web app. The web view has no file access, cannot open windows and does not autoplay media. Every navigation is cancelled and handled by the app instead (see Links). Plain-text mail is drawn with a native text view.

Layer 3: remote images and tracking #

The setting #

Remote images (pictures loaded from the internet instead of attached to the message) can tell the sender when and where you opened a message. You choose when they load under Settings → Reading & sending → Pictures in messages in the web app:

Option Value When remote images load
Ask every time block Never on their own.
Load from people I know (default) known See below.
Always load allow Always (still through the proxy, with trackers removed).

With Load from people I know, images load for:

  • people you have written to, and senders or domains you allowed;
  • your own mailbox domains;
  • established senders: the receiving provider verified that the mail really comes from the sender's domain (DMARC, or a DKIM signature of that domain), and that domain has sent you at least 3 messages over at least 72 hours, fewer than half of them in Spam.

They never load on their own for mail in Spam, mail with a forged-sender, lookalike-domain or failed-authentication warning, or unknown people on public mail services such as gmail.com.

When images are held back, the message shows "Images are hidden so the sender can't see when you read this." with Load images (this message only), Always load images from the sender's address, and a button for the sender's whole domain. Your own sent mail always shows its images.

The image proxy #

The cleaned HTML never points at a remote server directly. Each remote image address is replaced with a link to the engine's proxy (/api/v1/proxy/image), signed with a secret key (HMAC-SHA256), so the proxy only fetches addresses that it wrote itself. The proxy:

  • fetches only http and https addresses;
  • refuses private, loopback and link-local addresses, checked when it connects so that DNS tricks cannot get around it (a message cannot make your Hub probe your home network);
  • follows at most 3 redirects, checking each one;
  • sends no cookies and no referrer, with the User-Agent Postern-ImageProxy/1.0;
  • gives up after 15 seconds and refuses images over 10 MB;
  • checks the actual bytes and only serves raster images: SVG and anything that is not an image are refused;
  • serves the image with Content-Security-Policy: default-src 'none'; sandbox, X-Content-Type-Options: nosniff and Referrer-Policy: no-referrer;
  • keeps a small in-memory cache (256 images, 32 MB).

The proxy hides your device and browser from the sender. Which IP address the sender sees depends on where the engine runs:

App Who fetches the image
Web app Your Hub. The sender sees the Hub's IP address.
Desktop and mobile apps in direct mode The app's built-in engine on your device. The sender sees your device's IP address, but no cookies, referrer or browser details.

Tracking pixels #

Images that only exist to report that you opened a message are removed during cleaning, even when images are allowed:

  • images from known tracking services (for example HubSpot, Mixmax, Superhuman, Bananatag, Google Analytics and several mailing-list platforms);
  • images at typical tracking paths such as /track/open, /wf/open, /email/open;
  • images of 1 by 1 pixel or smaller, and hidden images.

What tracking protection cannot do: once you load images for a sender, they can tell that the message was opened. With images allowed, CSS rules can still trigger image loads through the proxy, so a sender could learn which rule matched. Rules only match inside the message itself, so they can only learn about the message's own content.

  • Links open outside the message: in a new browser tab in the web app, in your default browser from the desktop app (which passes on only http, https and mailto links), and in an in-app browser sheet on iOS and Android.
  • mailto: links open Postern's composer with the address filled in. Nothing is sent until you press Send.
  • No referrer is sent when you follow a link (rel="noreferrer" and Referrer-Policy: no-referrer), and the opened page gets no handle on the app (noopener).
  • On mobile, tel: and sms: links open the phone's own apps. Long-pressing a link shows the system preview with Open, Copy and Share.

Postern also checks messages for common phishing signs and shows a warning above the message: a display name that pretends to be another address, a domain that looks like a known one, links whose text shows a different address than they lead to, and failed sender authentication.

Attachments #

  • Attachments are stored encrypted on the Hub (see Encryption at rest).
  • When you download an attachment, files declared as JavaScript, HTML, XML, SVG, CSS or WebAssembly are sent as application/octet-stream, so the browser saves them instead of running or showing them. All downloads carry X-Content-Type-Options: nosniff and Content-Security-Policy: sandbox.
  • Only images and PDFs are shown inline.
  • The desktop app opens only attachments from your Hub, and only reveals risky file types in the folder instead of opening them.

What remains #

From the review, the known limits:

  • A browser bug in shadow DOM, CSS containment or the Content Security Policy is outside Postern's control. Inline messages share the app's origin, so such a bug could reach your session; the sandboxed frame would not. That is the price of inline drawing.
  • Fakes inside the message's own box. A message can still draw something that looks like app interface, such as a fake badge or fake buttons, but only inside its own area, never over the real header, toolbar or warnings.
  • Tracking after you load images, as described above.
  • Compose (the rich text editor) was not part of the in-depth review.

To report a problem, see Reporting a vulnerability.