Skip to content

Commit

Permalink
fix for Issue #2: internal Rails ActiveRecord::Base subclasses get lo…
Browse files Browse the repository at this point in the history
…aded before the plugin and thus do not have xss_terminate_options set. Return early from sanitize_fields in this case

git-svn-id: http://xssterminate.googlecode.com/svn/trunk/xss_terminate@7 503a6658-bc44-0410-a8bd-599819d3de0a
  • Loading branch information
look@recursion.org committed Jun 2, 2008
1 parent 50ab117 commit 974c5bf
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/xss_terminate.rb
Expand Up @@ -22,8 +22,12 @@ def xss_terminate(options = {})
end end


module InstanceMethods module InstanceMethods

def sanitize_fields def sanitize_fields
# fix a bug with Rails internal AR::Base models that get loaded before
# the plugin, like CGI::Sessions::ActiveRecordStore::Session
return if xss_terminate_options.nil?

self.class.columns.each do |column| self.class.columns.each do |column|
next unless (column.type == :string || column.type == :text) next unless (column.type == :string || column.type == :text)


Expand Down
6 changes: 6 additions & 0 deletions test/schema.rb
Expand Up @@ -31,4 +31,10 @@
t.column :person_id, :integer t.column :person_id, :integer
t.column :created_on, :datetime t.column :created_on, :datetime
end end

create_table :sessions, :force => true do |t|
t.string :session_id, :null => false
t.text :data
t.timestamps
end
end end
8 changes: 8 additions & 0 deletions test/xss_terminate_test.rb
Expand Up @@ -55,5 +55,13 @@ def test_nil_attributes_should_be_allowed_with_html5
assert_nil review.title assert_nil review.title
assert_nil review.body assert_nil review.body
end end

# issue reported by Garrett Dimon and jmcnevin
def test_active_record_session_store_does_not_cause_nil_exception
assert_nil CGI::Session::ActiveRecordStore::Session.xss_terminate_options

session = CGI::Session::ActiveRecordStore::Session.new(:session_id => 'foo', :data => 'blah')
assert session.save
end


end end

0 comments on commit 974c5bf

Please sign in to comment.