The best patch is deleting the package
Our checkout's HTML sanitiser had a published XSS bypass. I patched it, and a few months later removed it. Why the second fix was the better one.
In October 2024 a security ticket landed for our hosted checkout: upgrade DOMPurify from 3.1.0 to 3.1.3. It was a one-line change. Three months later I deleted the package entirely, and that was the fix I’m happier with.
What was wrong with 3.1.0
DOMPurify is the library most JavaScript apps use to clean untrusted HTML before putting it on a page. Its whole job is to stop cross-site scripting (XSS).
CVE-2024-45801 showed that specially nested HTML could get past the depth check DOMPurify had recently added, and that prototype pollution elsewhere in an app could weaken the same check. The result, per the advisory: the sanitiser could let XSS through. It was fixed in 2.5.4 and 3.1.3, and there was no workaround except upgrading.
That’s an uncomfortable kind of bug. A sanitiser with a bypass is worse than no sanitiser, because everyone downstream trusts it.
Why I removed it later
In January 2025 I was going through the checkout’s bundle line by line, looking for weight. DOMPurify showed up, and with it a question: what was it actually protecting?
It went out with the other code the page no longer needed. Removing it did two things at once. The bundle got smaller, and a whole class of future advisories stopped applying to us. You can’t be hit by the next DOMPurify CVE if you don’t ship DOMPurify.
What I learned
- Every dependency is a subscription to its advisories. Adding a package is easy. Keeping it patched for years is the real cost, and it’s paid by whoever is on call when the alert arrives.
- Ask what the package is for before you bump it. A patch keeps the risk you have. A removal can delete it. When an alert lands, it’s worth one minute asking whether the code still needs to exist.
- Security libraries deserve the most suspicion, not the least. Code that’s there “for safety” tends to be left alone. It should be checked like anything else, because when it fails, it fails quietly.
- If you do need to render HTML, render less of it. The safest HTML is the HTML you never inject. Text content and plain components avoid the problem the sanitiser exists to solve.