railsmonk / white_list_objectified
- Source
- Commits
- Network (3)
- Issues (0)
- Downloads (0)
- Wiki (1)
- Graphs
-
Branch:
master
commit 69adb6462bca97ae4854231ff4abb363fbe9758b
tree f8cee5c1a4fbcb81cddb4ece8bc73df3ca5a55f7
parent 4f305faf73935e7154ddaad6ac991b74cd096835
tree f8cee5c1a4fbcb81cddb4ece8bc73df3ca5a55f7
parent 4f305faf73935e7154ddaad6ac991b74cd096835
| name | age | message | |
|---|---|---|---|
| |
AUTHORS | Wed Sep 24 09:30:37 -0700 2008 | |
| |
CHANGELOG | Wed Sep 24 09:30:37 -0700 2008 | |
| |
README | Wed Sep 24 09:30:37 -0700 2008 | |
| |
Rakefile | Sat Sep 02 18:56:48 -0700 2006 | |
| |
init.rb | Wed Sep 24 09:00:37 -0700 2008 | |
| |
lib/ | Wed Sep 24 10:12:13 -0700 2008 | |
| |
test/ | Wed Sep 24 09:00:37 -0700 2008 |
README
WhiteList
=========
This White Listing helper will html encode all tags and strip all attributes that aren't specifically allowed.
It also strips href/src tags with invalid protocols, like javascript: especially. It does its best to counter any
tricks that hackers may use, like throwing in unicode/ascii/hex values to get past the javascript: filters. Check out
the extensive test suite.
<%= white_list @article.body %>
You can add or remove tags/attributes if you want to customize it a bit.
Add table tags
WhiteListHelper.tags.merge %w(table td th)
Remove tags
WhiteListHelper.tags.delete 'div'
Change allowed attributes
WhiteListHelper.attributes.merge %w(id class style)
white_list accepts a block for custom tag escaping. Shown below is the default block that white_list uses if none is
given.
The block is called for all bad tags, and every text node. node is an instance of HTML::Node (either HTML::Tag or
HTML::Text).
bad is nil for text nodes inside good tags, or is the tag name of the bad tag.
<%= white_list(@article.body) { |node, bad| white_listed_bad_tags.include?(bad) ? nil : node.to_s.gsub(/</, '<') }
%>
Original plugin website: http://weblog.techno-weenie.net/2006/9/3/white-listing-plugin-for-rails
Original plugin SVN: http://svn.techno-weenie.net/projects/plugins/white_list/