October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsWindows FixRecommendedWindows errors stealing your time? Find the fix fastScan stability, cleanup and performance issues.Fix NowOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk3 min

Sanitize Twice? Why One Pass Isn’t Always Enough for Rich-Text Email

Sanitizing rich-text email once only works if nothing changes the HTML afterward. Here is how pipeline order, mutation XSS and sink choice decide whether a second pass is needed.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

One sanitizer pass is enough only if nothing touches the HTML afterward. Once your code, another library, or a different rendering context changes the markup, the earlier approval no longer describes what the browser will interpret. A second pass at the final boundary is a sensible guard when such changes can’t be removed. It is not a universal “always twice” rule, and neither OWASP nor the DOMPurify project says it is.

Why encoding isn’t an option for rich-text email

Rich-text editors produce paragraphs, links, lists and emphasis. Output-encoding that content shows the tags as literal text and destroys the formatting. When users are meant to author HTML, the OWASP Cross Site Scripting Prevention Cheat Sheet calls for an HTML sanitizer, and it specifically recommends DOMPurify. The OWASP Input Validation Cheat Sheet adds that validation and regular expressions don’t substitute for a maintained sanitization library. It also says normalization is not sanitization and does not replace output encoding.

As an Amazon Associate I earn from qualifying purchases.

Can HTML become unsafe after sanitization?

Yes. OWASP puts it bluntly: “If you sanitize content and then modify it afterwards, you can easily void your security efforts.” It warns specifically that mutation by another library can undo the protection.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

The underlying problem is a trust-boundary mismatch. The sanitizer approves one representation of the markup. A later step then changes that representation, or the place where it is interpreted. Typical later steps include:

#1 Best Overall
Sale
Bitdefender Total Security - 5 Devices | 1 year Subscription | PC/Mac | Activation Code by email
  • SPEED-OPTIMIZED, CROSS-PLATFORM PROTECTION: World-class antivirus security and cyber protection for Windows, Mac OS, iOS, and Android. Organize and keep your digital life safe from hackers.
  • ADVANCED THREAT DEFENSE: Your software is always up-to-date to defend against the latest attacks, and includes: complete real-time data protection, multi-layer malware, ransomware, cryptomining, phishing, fraud, and spam protection, and more.
  • SUPERIOR PRIVACY PROTECTION: including a dedicated safe online banking browser, microphone monitor, webcam protection, anti-tracker, file shredder, parental controls, privacy firewall, anti-theft protection, social network protection, and more.
  • TOP-TIER PERFORMANCE: Bitdefender technology provides near-zero impact on your computer’s hardware, including: Autopilot security advisor, auto-adaptive performance technology, game/movie/work modes, OneClick Optimizer, battery mode, and more
  • rewriting links for click tracking;
  • inlining styles or appending a footer by string manipulation;
  • running the output through a templating, minifying or conversion library;
  • moving the string from one HTML context into another.

I haven’t tested any of these steps against specific payloads or mail clients, and the guidance behind this article doesn’t audit Gmail, Outlook or Apple Mail. Treat the list as the kinds of steps to watch for, not as a catalogue of known bypasses.

Mutation XSS: why a clean-looking string isn’t permanently safe

The DOMPurify project’s Security Goals & Threat Model describes mutation XSS (mXSS) as parse asymmetry. Markup can look inert in the parsed tree the sanitizer inspects, then become active after it is serialized to a string and parsed again. The lesson is to tie sanitized output to the sink it was prepared for, not to treat the string as safe everywhere. The project’s own sentence: “Keep HTML going into an HTML sink, insert without post-processing, and don’t change the sink contract afterward.”

Rank #2
Sale
Bitdefender Total Security - 10 Devices | 2 year Subscription | PC/MAC |Activation Code by email
  • SPEED-OPTIMIZED, CROSS-PLATFORM PROTECTION: World-class antivirus security and cyber protection for Windows, Mac OS, iOS, and Android. Organize and keep your digital life safe from hackers.
  • ADVANCED THREAT DEFENSE: Your software is always up-to-date to defend against the latest attacks, and includes: complete real-time data protection, multi-layer malware, ransomware, cryptomining, phishing, fraud, and spam protection, and more.
  • SUPERIOR PRIVACY PROTECTION: including a dedicated safe online banking browser, microphone monitor, webcam protection, anti-tracker, file shredder, parental controls, privacy firewall, anti-theft protection, social network protection, and more.
  • TOP-TIER PERFORMANCE: Bitdefender technology provides near-zero impact on your computer’s hardware, including: Autopilot security advisor, auto-adaptive performance technology, game/movie/work modes, OneClick Optimizer, battery mode, and more

Should you sanitize again after transforming it?

Use this decision order:

  1. Do trusted transformations first. Parse, rewrite links, add wrappers and so on before sanitizing, so the sanitizer sees the final content.
  2. Sanitize once, for the final context. Configure a maintained sanitizer for the rich-text profile you actually need.
  3. Insert without further mutation. No string concatenation, regex cleanup or library rewriting between the sanitizer and the sink.
  4. If a later transform can’t be eliminated, treat its output as untrusted again. Sanitize at the final boundary, immediately before insertion.

Step 4 is a practical inference from OWASP’s post-modification warning and DOMPurify’s sink guidance. Neither source claims two passes suffice for every pipeline. A second pass is defense in depth for an unavoidable late transform. It does not fix a design where unsafe content is later re-parsed in a different context.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Configuring for an HTML-only email preview

DOMPurify documents an HTML-only profile for cases like an email preview. It drops SVG and MathML, which removes that namespace surface. It also describes avoiding the serialize/reparse step by returning a fragment and appending it directly.

Rank #3
Sale
McAfee Total Protection, Text, Email, Video Scam Protection | Auto-Renews
  • ALL-IN-ONE SCAM DETECTION – Texts, emails, videos, and QR codes all get checked automatically. Sorting real from fake stops being your job.
  • KEEP SCAMMERS OUT OF YOUR WALLET – Every click is no longer a gamble. Our scam detection spots suspicious texts, email scams, SMS phishing, and fake alerts before you click.
  • QR CODE SCANNING – Point the app at any code and see where it actually leads before you scan it.
  • DEEPFAKE DETECTION – When a video sounds like someone you know but isn't, you hear it from us first.
  • ON-DEMAND CHECKS – Got a message you're unsure about? Run it through the app and know in seconds, wherever it came from.
const fragment = DOMPurify.sanitize(dirtyHtml, {
  USE_PROFILES: { html: true },
  RETURN_DOM_FRAGMENT: true
});
previewEl.replaceChildren(fragment);

Here the sanitized DOM goes straight into the page with no intermediate string. If you must return a string, for example to store it, sanitize again where it is finally rendered rather than trusting the stored copy.

Comparing pipeline choices

Axis Safer choice Riskier choice
Pipeline placement Sanitize after all trusted transforms Sanitize early, transform later
Context match HTML-only profile when only HTML is needed Allowing SVG/MathML without a need
Representation handoff Direct DOM fragment insertion Serialize to string, then reparse
Post-sanitization mutation None Application or library rewrites the output
Maintenance Current, patched sanitizer Stale dependency

Keep the sanitizer current and test your own pipeline

OWASP says sanitizers should be regularly patched, because bypasses are discovered and browser behavior changes. The DOMPurify repository showed version 3.4.16 when checked on 2026-10-05. That is a volatile snapshot, not a recommendation to pin to it. Test with your real transformations and your real rendering sinks, since the risk comes from the combination, not from the sanitizer alone.

Rank #4
Sale
McAfee Total Protection 2027 Antivirus Software for 1 Device | Auto-Renews
  • THREAT DETECTION – Stay one step ahead. Suspicious links, risky sites, viruses, and scams, caught automatically before they reach you.
  • PERSONAL INFO PROTECTION – Keep your personal info safer. Identity monitoring watches for your exposed info and tells you what to do about it.
  • SECURE CONNECTIONS – Just a few easy clicks, and we'll automatically protect your info on public Wi‑Fi, every time you connect.
  • GUIDED ACTION – Know what matters and what to do next. Clear alerts and simple guidance make it easy to take action.
  • MORE THAN ANTIVIRUS – Scam protection, identity monitoring, VPN, web protection, and antivirus work together to protect you, all in one place.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

The Bottom Line

Don’t count passes; control the pipeline. Transform first, sanitize for the final context, insert without mutation, and sanitize again at the last boundary only when a late change can’t be avoided. Keep the sanitizer patched.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Best Value
Sale
Bitdefender Family Pack - 15 Devices | 2 year Subscription | PC/Mac | Activation Code by email
  • SPEED-OPTIMIZED, CROSS-PLATFORM PROTECTION: World-class antivirus security and cyber protection for Windows, Mac OS, iOS, and Android. Organize and keep your digital life safe from hackers.
  • ADVANCED THREAT DEFENSE: Your software is always up-to-date to defend against the latest attacks, and includes: complete real-time data protection, multi-layer malware, ransomware, cryptomining, phishing, fraud, and spam protection, and more.
  • SUPERIOR PRIVACY PROTECTION: including a dedicated safe online banking browser, microphone monitor, webcam protection, anti-tracker, file shredder, parental controls, privacy firewall, anti-theft protection, social network protection, and more.
  • TOP-TIER PERFORMANCE: Bitdefender technology provides near-zero impact on your computer’s hardware, including: Autopilot security advisor, auto-adaptive performance technology, game/movie/work modes, OneClick Optimizer, battery mode, and more

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Windows Errors? Fix Them Before They SpreadFree repair scan
Outdated Drivers Are Slowing You DownFree scan - exact matches

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.