Commit 8383b52e919f32187208aa4db758a5c1549b7769

Authored by Rodrigo Souto
Committed by Antonio Terceiro
1 parent 0f455456

Filtering xss attack in comment field name

(ActionItem1371)
app/models/comment.rb
... ... @@ -17,7 +17,7 @@ class Comment < ActiveRecord::Base
17 17 end
18 18 end
19 19  
20   - xss_terminate :only => [ :body, :title ]
  20 + xss_terminate :only => [ :body, :title, :name ]
21 21  
22 22 def author_name
23 23 if author
... ...
test/unit/comment_test.rb
... ... @@ -179,4 +179,12 @@ class CommentTest < Test::Unit::TestCase
179 179 assert comment.url[:view]
180 180 end
181 181  
  182 + should 'not fill fields with javascript' do
  183 + owner = create_user('testuser').person
  184 + article = owner.articles.create!(:name => 'test', :body => '...')
  185 + javascript = "<script>alert('XSS')</script>"
  186 + comment = article.comments.create!(:article => article, :name => javascript, :title => javascript, :body => javascript, :email => 'cracker@test.org')
  187 + assert_no_match(/<script>/, comment.name)
  188 + end
  189 +
182 190 end
... ...