Skip to content
This repository


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Whitelist-based HTML filter for Ruby

branch: master

Fetching latest commit…


Cannot retrieve the latest commit at this time

Octocat-spinner-32 data
Octocat-spinner-32 lib
Octocat-spinner-32 spec
Octocat-spinner-32 COPYING
Octocat-spinner-32 README.rdoc
Octocat-spinner-32 setup.rb
Octocat-spinner-32 whitewash.gemspec

Whitewash - whitelist-based HTML filter for Ruby

This module allows Ruby programs to clean up any HTML document or fragment coming from an untrusted source and to remove all dangerous constructs that could be used for cross-site scripting or request forgery.


require 'whitewash'

whitewash =   # use default whitelist.yaml
clean_xhtml = whitewash.sanitize(html)


All HTML tags, attribute names and values, and CSS properties are filtered through a whitelist that defines which names and what kinds of values are allowed, everything that doesn't match the whitelist is removed.

The whitelist is provided externally, default whitelist is loaded from the whitelist.yaml shipped with Whitewash. The default is most strict (for example, it does not allow cross-site links to images in IMG tags) and can be considered safe for all uses. If you find that it lets anything exploitable through, please report it as a bug to Whitewash developers.

An alternative whitelist is provided for HTML5 in html5_whitelist.yaml. This whitelist is as much a work in progress as HTML5 standard itself, use at your own risk.

External Dependencies

Whitewash relies on Nokogiri to parse arbitrary HTML and put it back together as valid XHTML:



Copyright (c) 2002-2011  Dmitry Borodaenko <>

This program is free software.
You can distribute/modify this program under the terms of the GNU
General Public License version 3 or later.
Something went wrong with that request. Please try again.