<commit_before>= xss_terminate

+xss_terminate+ is a plugin in that makes stripping and sanitizing HTML 
stupid-simple. Install and forget. And forget about forgetting to <tt>h()</tt>
your output, because you won't need to anymore.

But +xss_terminate+ is also flexible. By default, it will strip all HTML tags
from user input. This is usually what you want, but sometimes you need users to be 
able to enter HTML. The plugin allows you remove bad HTML with your choice
of two whitelist-based sanitizers, or to skip HTML sanitization entirely on
a per-field basis.

To install, do:

  script/plugin install http://xssterminate.googlecode.com/svn/trunk/xss_terminate

== HTML sanitization

A note on your choices.

* Strip tags: removes all HTML using Rails's built-in +strip_tags+ method. Tags are removed, but their content is not.
* Rails sanitization: Removes bad HTML with Rails's built-in sanitize method. Bad tags are removed completely, including their content.
* HTML5lib sanitization: Removes bad HTML after parsing it with {HTML5lib}[http://code.google.com/p/html5lib/], a library that parses HTML like browsers do. It should be very tolerant of invalid HTML. Bad tags are escaped, not removed.
* Do nothing. You can chose not to process given fields.

== Usage

Installing the plugin creates a +before_save+ hook that will strip HTML tags 
from all string and text fields. No further configuration is necessary if this
is what you want. To customize the behavior, you use the +xss_terminate+ class 
method.

To exempt some fields from sanitization, use the <tt>:except</tt> option 
with a list of fields not to process:

 class Comment < ActiveRecord::Base
   xss_terminate :except => [ :body ]
 end

To sanitize HTML with Rails's built-in sanitization, use the <tt>:sanitize</tt> option:

  class Review < ActiveRecord::Base
    xss_sanitize :sanitize => [ :body, :author_name]
  end
 
To sanitize HTML with {HTML5Lib}[http://code.google.com/p/html5lib/] 
(<tt>gem install html5</tt> to get it), use the <tt>:html5lib_sanitize</tt> 
option with a list of fields to sanitize:

 class Entry < ActiveRecord::Base
   xss_terminate :html5lib_sanitize => [ :body, :author_name ]
 end
 
You can combine multiple options if you have some fields you would like skipped
and others sanitized. Fields not listed in the option arrays will be stripped.

 class Message < ActiveRecord::Base
   xss_terminate :except => [ :body ], :sanitize => [ :title ]
 end

== Sanitizing existing records

After installing +xss_terminate+ and configuring it to your liking, you can 
run <tt>rake xss_terminate MODELS=Foo,Bar,Baz</tt> to execute it against your
existing records. This will load each model found and save it again to invoke
the before_save hook.

== Unique features

+xss_terminate+ is based on +acts_as_sanitized+. Here is what's different:

* Rails 2.0-ready.
* Automatic. It is included with default options in <tt>ActiveReord::Base</tt> so all your models are sanitized.
* It works with migrations. Columns are fetched when model is saved, not when the class is loaded.
* You can decide whether to sanitize or strip tags on a field-by-field basis instead of model-by-model.
* HTML5lib support.

== TODO

* Performance tests
* Test suites with "real world" HTML
* Test/make work with Rails 1.2.x (Rails 1.2 sanitization is crap, so you'd want to use HTML5lib)

== Credits

Written by {<NAME>}[http://railspikes.com] and based on acts_as_sanitized by <commit_msg>update README. Fix typo (Thanks Gee) and announce Rails 2.2 support<commit_after>= xss_terminate

+xss_terminate+ is a plugin in that makes stripping and sanitizing HTML 
stupid-simple. Install and forget. And forget about forgetting to <tt>h()</tt>
your output, because you won't need to anymore.

But +xss_terminate+ is also flexible. By default, it will strip all HTML tags
from user input. This is usually what you want, but sometimes you need users to be 
able to enter HTML. The plugin allows you remove bad HTML with your choice
of two whitelist-based sanitizers, or to skip HTML sanitization entirely on
a per-field basis.

To install, do:

  script/plugin install http://xssterminate.googlecode.com/svn/trunk/xss_terminate

== HTML sanitization

A note on your choices.

* Strip tags: removes all HTML using Rails's built-in +strip_tags+ method. Tags are removed, but their content is not.
* Rails sanitization: Removes bad HTML with Rails's built-in sanitize method. Bad tags are removed completely, including their content.
* HTML5lib sanitization: Removes bad HTML after parsing it with {HTML5lib}[http://code.google.com/p/html5lib/], a library that parses HTML like browsers do. It should be very tolerant of invalid HTML. Bad tags are escaped, not removed.
* Do nothing. You can chose not to process given fields.

== Usage

Installing the plugin creates a +before_save+ hook that will strip HTML tags 
from all string and text fields. No further configuration is necessary if this
is what you want. To customize the behavior, you use the +xss_terminate+ class 
method.

To exempt some fields from sanitization, use the <tt>:except</tt> option 
with a list of fields not to process:

 class Comment < ActiveRecord::Base
   xss_terminate :except => [ :body ]
 end

To sanitize HTML with Rails's built-in sanitization, use the <tt>:sanitize</tt> option:

  class Review < ActiveRecord::Base
    xss_terminate :sanitize => [ :body, :author_name]
  end
 
To sanitize HTML with {HTML5Lib}[http://code.google.com/p/html5lib/] 
(<tt>gem install html5</tt> to get it), use the <tt>:html5lib_sanitize</tt> 
option with a list of fields to sanitize:

 class Entry < ActiveRecord::Base
   xss_terminate :html5lib_sanitize => [ :body, :author_name ]
 end
 
You can combine multiple options if you have some fields you would like skipped
and others sanitized. Fields not listed in the option arrays will be stripped.

 class Message < ActiveRecord::Base
   xss_terminate :except => [ :body ], :sanitize => [ :title ]
 end

== Sanitizing existing records

After installing +xss_terminate+ and configuring it to your liking, you can 
run <tt>rake xss_terminate MODELS=Foo,Bar,Baz</tt> to execute it against your
existing records. This will load each model found and save it again to invoke
the before_save hook.

== Unique features

+xss_terminate+ is based on +acts_as_sanitized+. Here is what's different:

* Supports Rails 2.0-2.2 (may work on edge Rails)
* Automatic. It is included with default options in <tt>ActiveReord::Base</tt> so all your models are sanitized.
* It works with migrations. Columns are fetched when model is saved, not when the class is loaded.
* You can decide whether to sanitize or strip tags on a field-by-field basis instead of model-by-model.
* HTML5lib support.

== TODO

* Performance tests
* Test suites with "real world" HTML
* Test/make work with Rails 1.2.x (Rails 1.2 sanitization is crap, so you'd want to use HTML5lib)

== Credits

Written by {<NAME>}[http://railspikes.com] and based on acts_as_sanitized by 
{'fraction_non_alphanumeric': 0.07586993725042784, 'fraction_numerical': 0.00513405590416429, 'mean_word_length': 4.373946360153257, 'pattern_counts': {'":': 0, '<': 41, '<?xml version=': 0, '>': 43, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5340254', 'n_tokens_mistral': 2125, 'n_tokens_neox': 2018, 'n_words': 948}