Giter Club home page Giter Club logo

safe-erb's Introduction

Safe ERB Build Status

Overview

Safe ERB lets you make sure that the string written by <%= %> in your erb 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 html template, it raises an exception if the string you are trying to show is tainted.

Installation

You can grab Safe ERB from github and put it in vendor/plugins, or just run:

script/plugin install git://github.com/abedra/safe-erb

Safe ERB works on Rails 2.0.x, 2.1.x, 2.2.x, and 2.3.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::TagHelper#escape
  • ActionView::Helpers::TextHelper#strip_tags

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

Contact

Aaron Bedra

Shinya Kasatani

safe-erb's People

Contributors

abedra avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.