antisamy 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE.txt +20 -0
- data/README.rdoc +36 -0
- data/lib/antisamy.rb +42 -0
- data/lib/antisamy/html/handler.rb +95 -0
- data/lib/antisamy/html/sax_filter.rb +286 -0
- data/lib/antisamy/html/scanner.rb +85 -0
- data/lib/antisamy/model/attribute.rb +19 -0
- data/lib/antisamy/model/css_property.rb +39 -0
- data/lib/antisamy/model/tag.rb +31 -0
- data/lib/antisamy/policy.rb +540 -0
- data/lib/antisamy/scan_results.rb +21 -0
- data/spec/antisamy_spec.rb +28 -0
- data/spec/spec_helper.rb +12 -0
- metadata +160 -0
@@ -0,0 +1,21 @@
|
|
1
|
+
module AntiSamy
|
2
|
+
# Container of scan results, provides a list of ScanMessage indicating
|
3
|
+
# why elements were removed from the resulting html
|
4
|
+
class ScanResults
|
5
|
+
attr_reader :scan_start, :scan_end
|
6
|
+
attr_accessor :messages, :clean_html
|
7
|
+
def initialize(scan_start,scan_end = nil)
|
8
|
+
@errors = []
|
9
|
+
@scan_start = scan_start
|
10
|
+
@scan_end = scan_end
|
11
|
+
@clean_html = ''
|
12
|
+
end
|
13
|
+
|
14
|
+
# Get the calculated scan time
|
15
|
+
def scan_time
|
16
|
+
@scan_end ||= Time.now
|
17
|
+
(@scan_end - @scan_start).round(2)
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
|
3
|
+
module AntiSamy
|
4
|
+
describe AntiSamy do
|
5
|
+
let(:policy_file) {"#{File.join(File.dirname(__FILE__), '..', 'policy-examples')}/antisamy.xml"}
|
6
|
+
|
7
|
+
it "should load a policy" do
|
8
|
+
p = AntiSamy.policy(policy_file)
|
9
|
+
p.should_not == nil
|
10
|
+
end
|
11
|
+
|
12
|
+
it "should scan our sample html and change nothing" do
|
13
|
+
input = "<p>Hi</p>"
|
14
|
+
p = AntiSamy.policy(policy_file)
|
15
|
+
r = AntiSamy.scan(input,p)
|
16
|
+
r.clean_html.should == input
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should tak our input and remove the script tags" do
|
20
|
+
input = "<p>Hi</p><script> some junk</script>"
|
21
|
+
expec = "<p>Hi</p>"
|
22
|
+
p = AntiSamy.policy(policy_file)
|
23
|
+
r = AntiSamy.scan(input,p)
|
24
|
+
r.clean_html.should == expec
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
2
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
3
|
+
require 'rspec'
|
4
|
+
require 'antisamy'
|
5
|
+
|
6
|
+
# Requires supporting files with custom matchers and macros, etc,
|
7
|
+
# in ./support/ and its subdirectories.
|
8
|
+
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
|
9
|
+
|
10
|
+
RSpec.configure do |config|
|
11
|
+
|
12
|
+
end
|
metadata
ADDED
@@ -0,0 +1,160 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: antisamy
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease:
|
5
|
+
version: 0.0.1
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Sal Scotto
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
|
13
|
+
date: 2011-03-07 00:00:00 -05:00
|
14
|
+
default_executable:
|
15
|
+
dependencies:
|
16
|
+
- !ruby/object:Gem::Dependency
|
17
|
+
name: rspec
|
18
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
19
|
+
none: false
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 2.3.0
|
24
|
+
type: :development
|
25
|
+
prerelease: false
|
26
|
+
version_requirements: *id001
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: yard
|
29
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
30
|
+
none: false
|
31
|
+
requirements:
|
32
|
+
- - ~>
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: 0.6.0
|
35
|
+
type: :development
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: *id002
|
38
|
+
- !ruby/object:Gem::Dependency
|
39
|
+
name: bundler
|
40
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ~>
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: 1.0.0
|
46
|
+
type: :development
|
47
|
+
prerelease: false
|
48
|
+
version_requirements: *id003
|
49
|
+
- !ruby/object:Gem::Dependency
|
50
|
+
name: jeweler
|
51
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
52
|
+
none: false
|
53
|
+
requirements:
|
54
|
+
- - ~>
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: 1.5.2
|
57
|
+
type: :development
|
58
|
+
prerelease: false
|
59
|
+
version_requirements: *id004
|
60
|
+
- !ruby/object:Gem::Dependency
|
61
|
+
name: rcov
|
62
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
63
|
+
none: false
|
64
|
+
requirements:
|
65
|
+
- - ">="
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: "0"
|
68
|
+
type: :development
|
69
|
+
prerelease: false
|
70
|
+
version_requirements: *id005
|
71
|
+
- !ruby/object:Gem::Dependency
|
72
|
+
name: nokogiri
|
73
|
+
requirement: &id006 !ruby/object:Gem::Requirement
|
74
|
+
none: false
|
75
|
+
requirements:
|
76
|
+
- - ">="
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
version: "0"
|
79
|
+
type: :development
|
80
|
+
prerelease: false
|
81
|
+
version_requirements: *id006
|
82
|
+
- !ruby/object:Gem::Dependency
|
83
|
+
name: nokogiri
|
84
|
+
requirement: &id007 !ruby/object:Gem::Requirement
|
85
|
+
none: false
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: "0"
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: *id007
|
93
|
+
- !ruby/object:Gem::Dependency
|
94
|
+
name: nokogiri
|
95
|
+
requirement: &id008 !ruby/object:Gem::Requirement
|
96
|
+
none: false
|
97
|
+
requirements:
|
98
|
+
- - ">="
|
99
|
+
- !ruby/object:Gem::Version
|
100
|
+
version: "0"
|
101
|
+
type: :development
|
102
|
+
prerelease: false
|
103
|
+
version_requirements: *id008
|
104
|
+
description: "\n AntiSamy is a library to clean user-supplied HTML/CSS. This gem is a port of the anti-samy framework created for OWASP (http://www.owasp.org/index.php/Category:OWASP_AntiSamy_Project)\n AntiSamy works by using a policy to removed any dangerous input you specify from attributes to tags. This gem is built using nokogiri\n "
|
105
|
+
email: sal.scotto@gmail.com
|
106
|
+
executables: []
|
107
|
+
|
108
|
+
extensions: []
|
109
|
+
|
110
|
+
extra_rdoc_files:
|
111
|
+
- LICENSE.txt
|
112
|
+
- README.rdoc
|
113
|
+
files:
|
114
|
+
- lib/antisamy.rb
|
115
|
+
- lib/antisamy/html/handler.rb
|
116
|
+
- lib/antisamy/html/sax_filter.rb
|
117
|
+
- lib/antisamy/html/scanner.rb
|
118
|
+
- lib/antisamy/model/attribute.rb
|
119
|
+
- lib/antisamy/model/css_property.rb
|
120
|
+
- lib/antisamy/model/tag.rb
|
121
|
+
- lib/antisamy/policy.rb
|
122
|
+
- lib/antisamy/scan_results.rb
|
123
|
+
- LICENSE.txt
|
124
|
+
- README.rdoc
|
125
|
+
- spec/antisamy_spec.rb
|
126
|
+
- spec/spec_helper.rb
|
127
|
+
has_rdoc: true
|
128
|
+
homepage: http://github.com/washu/antisamy-ruby
|
129
|
+
licenses:
|
130
|
+
- MIT
|
131
|
+
post_install_message:
|
132
|
+
rdoc_options: []
|
133
|
+
|
134
|
+
require_paths:
|
135
|
+
- lib
|
136
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
137
|
+
none: false
|
138
|
+
requirements:
|
139
|
+
- - ">="
|
140
|
+
- !ruby/object:Gem::Version
|
141
|
+
hash: -39737283441268027
|
142
|
+
segments:
|
143
|
+
- 0
|
144
|
+
version: "0"
|
145
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
146
|
+
none: false
|
147
|
+
requirements:
|
148
|
+
- - ">="
|
149
|
+
- !ruby/object:Gem::Version
|
150
|
+
version: "0"
|
151
|
+
requirements: []
|
152
|
+
|
153
|
+
rubyforge_project:
|
154
|
+
rubygems_version: 1.6.1
|
155
|
+
signing_key:
|
156
|
+
specification_version: 3
|
157
|
+
summary: AntiSamy implmentation for Ruby.
|
158
|
+
test_files:
|
159
|
+
- spec/antisamy_spec.rb
|
160
|
+
- spec/spec_helper.rb
|