Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
The original Safe ERB project pulled in from RubyForge
Ruby
Tree: 80be62a02c

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
lib
tasks
test
MIT-LICENSE
README
Rakefile
init.rb
install.rb

README

= Safe ERB

== Overview

Safe ERB lets you make sure that the string written by "<%= %>" in your rhtml template is escaped correctly. If you try to show the attributes in the ActiveRecord instance read from the database or the parameters received from the request without escaping them using "h" method, an exception will be raised. This will significantly reduce the possibility of putting cross-site scripting vulnerability into your web application.

The check is done using "tainted?" method in Object class which is a standard feature provided by Ruby - the string is "tainted" when it is read from IO. When ERB::Util#h method is called, this plugin "untaints" the string, and when "<%= %>" is called in your rhtml template, it raises an exception if the string you are trying to show is tainted.

== Installation

Just put this plugin into vendor/plugins directory in your Rails application. No configuration is needed.

Safe ERB works on Rails 1.2.x and 2.0.x. It has been tested using following database libraries:

- PostgreSQL (postgres-0.7.1 gem)
- MySQL (mysql-2.7 gem)

It does NOT work properly on SQLite (because the data read from SQLite driver is not tainted).

== Details

The string becomes tainted when it is read from IO, such as the data read from the DB or HTTP request. However, the request parameters are not tainted in functional and integration tests, and also if your server is Mongrel. Hence this plugin installs before_filter into ActionController::Base that always taints request parameters and cookies.

The returned values from the following methods become untainted:

- ERB::Util#h
- ActionView::Helpers::TextHelper#strip_tags

Also, you can always untaint any string manually by calling "untaint" method (standard Ruby feature).

== Contact

Shinya Kasatani <kasatani at gmail.com>
Something went wrong with that request. Please try again.