I've been focusing on work and neglecting my blog lately, but I want to take a moment to highlight HTML Purifier, a tool developed by Edward Yang. Edward contacted me a few days ago to let me know that he has just released version 2.0, and because this post is tardy, version 2.0.1 is already available.
What is HTML Purifier? In Edward's own words:
HTML Purifier is a standards-compliant HTML filter library written in PHP. HTML Purifier will not only remove all malicious code (better known as XSS) with a thoroughly audited, secure yet permissive whitelist, it will also make sure your documents are standards compliant, something only achievable with a comprehensive knowledge of W3C's specifications.
HTML Purifier enforces standards, and Edward has explained why this approach is valuable:
I've previously proposed that by insisting standards compliance, you protect yourself against browser quirks. While there wasn't that much discussion on it, I think that it is very possible to do HTML safely.
This is where HTML Purifier really shines. (There are additional reasons to choose it.) Because standards-compliant markup has a limited amount of wiggle room for crafting tricky XSS exploits, enforcing standards can tame a practically unmanageable problem.
I'll probably be talking about HTML Purifier more in the future. In the meantime, perhaps you'd like to try to break it. :-)