xss_terminate 0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,12 @@
1
+ require 'action_pack/version'
2
+
3
+ # This class exists so including the Rails HTML sanitization helpers doesn't pollute your models.
4
+ #module XssTerminate
5
+ class RailsSanitize
6
+ if ActionPack::VERSION::MINOR >= 2 # Rails 2.2+
7
+ extend ActionView::Helpers::SanitizeHelper::ClassMethods
8
+ else # Rails 2.1 or earlier (note: xss_terminate does not support Rails 1.x)
9
+ include ActionView::Helpers::SanitizeHelper
10
+ end
11
+ end
12
+ #end
@@ -0,0 +1,3 @@
1
+ module XssTerminate
2
+ VERSION = "0.1"
3
+ end
@@ -0,0 +1,57 @@
1
+ require "rails_sanitize"
2
+ require "html5"
3
+ require "html5lib_sanitize"
4
+
5
+ module XssTerminate
6
+ def self.included(base)
7
+ base.extend(ClassMethods)
8
+ # sets up default of stripping tags for all fields
9
+ # base.send(:xss_terminate)
10
+ end
11
+
12
+ module ClassMethods
13
+ def xss_terminate(options = {})
14
+ before_validation :sanitize_fields
15
+
16
+ class_attribute :xss_terminate_options
17
+ self.xss_terminate_options = {
18
+ :except => (options[:except] || []),
19
+ :html5lib_sanitize => (options[:html5lib_sanitize] || []),
20
+ :sanitize => (options[:sanitize] || [])
21
+ }
22
+
23
+ include XssTerminate::InstanceMethods
24
+ end
25
+ end
26
+
27
+ module InstanceMethods
28
+
29
+ def sanitize_fields
30
+ # fix a bug with Rails internal AR::Base models that get loaded before
31
+ # the plugin, like CGI::Sessions::ActiveRecordStore::Session
32
+ return if xss_terminate_options.nil?
33
+
34
+ self.class.columns.each do |column|
35
+ next unless (column.type == :string || column.type == :text)
36
+
37
+ field = column.name.to_sym
38
+ value = self[field]
39
+
40
+ next if value.nil? || !value.is_a?(String)
41
+
42
+ if xss_terminate_options[:except].include?(field)
43
+ next
44
+ elsif xss_terminate_options[:html5lib_sanitize].include?(field)
45
+ self[field] = HTML5libSanitize.new.sanitize_html(value)
46
+ elsif xss_terminate_options[:sanitize].include?(field)
47
+ self[field] = RailsSanitize.white_list_sanitizer.sanitize(value)
48
+ else
49
+ self[field] = RailsSanitize.full_sanitizer.sanitize(value)
50
+ end
51
+ end
52
+
53
+ end
54
+ end
55
+ end
56
+
57
+ ActiveRecord::Base.send(:include, XssTerminate)
metadata ADDED
@@ -0,0 +1,53 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: xss_terminate
3
+ version: !ruby/object:Gem::Version
4
+ version: '0.1'
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Railscode
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-05-19 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: XssTerminate for Rails 3.2
15
+ email:
16
+ - railscode@gmail.com
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - lib/rails_sanitize.rb
22
+ - lib/xss_terminate.rb
23
+ - lib/html5lib_sanitize.rb
24
+ - lib/xss_terminate/version.rb
25
+ - LICENSE
26
+ - README.md
27
+ - CHANGELOG.md
28
+ - ROADMAP.md
29
+ homepage: http://github.com/vav/xss_terminate
30
+ licenses: []
31
+ post_install_message:
32
+ rdoc_options: []
33
+ require_paths:
34
+ - lib
35
+ required_ruby_version: !ruby/object:Gem::Requirement
36
+ none: false
37
+ requirements:
38
+ - - ! '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ required_rubygems_version: !ruby/object:Gem::Requirement
42
+ none: false
43
+ requirements:
44
+ - - ! '>='
45
+ - !ruby/object:Gem::Version
46
+ version: 1.3.6
47
+ requirements: []
48
+ rubyforge_project: xss_terminate
49
+ rubygems_version: 1.8.19
50
+ signing_key:
51
+ specification_version: 3
52
+ summary: XssTerminate
53
+ test_files: []