About the Author

Chris Shiflett

Hi, I'm Chris, a web developer and a founding member of Analog. I live and work in Brooklyn, NY.


HTML Purifier

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.

I feel comfortable recommending HTML Purifier based on its solid theory of operation as well as its ability to safely handle the XSS Cheat Sheet in its entirety. (Try for yourself.)

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. :-)

About This Post

HTML Purifier was posted on Thu, 28 Jun 2007 at 05:26:29 GMT.

4 Comments

1. Chris Shiflett's GravatarChris Shiflett said:

Christian Matthies has posted an interview with Edward:

http://christ1an.blogspot.com/2007/...ard-z-yang.html

Thu, 28 Jun 2007 at 20:45:27 GMT Link


2. Luke's GravatarLuke said:

Excellent! This is an amazing library. :)

Fri, 29 Jun 2007 at 00:18:47 GMT Link


3. Mindloop's GravatarMindloop said:

I've been playing around a bit with HTMLPurifier and have been trying to get some XSS to pass trough, no luck so far.

Also wrote a quick guide for those that want to use HTMLPurifier in the codeigniter framework

Thu, 05 Jul 2007 at 20:20:53 GMT Link


4. Santosh Patnaik's GravatarSantosh Patnaik said:

htmLawed is a new PHP script like HTML Purifier that can be used to make HTML in input text more secure and standard-compliant, and to administratively restrict HTML elements, attributes, etc. It is a single file script of ~45 kb with low memory usage, and is highly customizable.

Thu, 15 Nov 2007 at 18:11:02 GMT Link


Post A Comment

Personal Details and Comment

Style Guide

Line breaks are converted to paragraphs. Also use:

  • <a href="" title="">text</a>1
  • <em>text</em>
  • <blockquote><p>text</p></blockquote>
  • <code>2  <?php  if ($foo) {      $foo = TRUE;  }  ?></code>
  1. Note: <code> can be used inline (e.g. in paragraphs) or in a block as shown. Include whitespace and newlines in blocks.

Please enter Chris (my first name) below. This is a primitive spam prevention technique, and I apologize for the inconvenience.

Preview and Submit

Upcoming Talks

Kiwi Foo Camp

12 - 14 Feb 2010

At Mahurangi College, Warkworth, New Zealand.

Webstock

15 - 19 Feb 2010

At Wellington Town Hall, Wellington, New Zealand.

ConFoo

10 - 12 Mar 2010

At Hilton Montréal Bonaventure, Montréal, Canada.

South by Southwest

12 - 16 Mar 2010

At Austin Convention Center, Austin, Texas.

New Comments

Sujoy wrote:

Chris, this is the first time I'm visiting your blog! Your 2009 Highlights is really great! Fanta...

Posted in 2009 Highlights
Giovanni wrote:

Hi Chris! First of all, my persona thanks for all your article about PHP security! it's really u...

Posted in The Truth about Sessions
Chris Shiflett wrote:

Thanks, John. Friendly and trustworthy are high compliments. Much appreciated. :-) Sorry about...

Posted in 2009 Highlights
Eric B wrote:

Hi Chris, Thanks for this clean, concise article on this topic. You are a life saver! -E

Posted in Guru Speak: Storing Sessions in a Database
Radoslav Stankov wrote:

wow, I looks like 2009 wasn't very boring year. p.s. I didn't know you too are Arsenal fan.

Posted in 2009 Highlights

Browse Comments


Work and Books

Analog Essential PHP Security HTTP Developers Handbook