loofah 0.4.7 → 1.0.0.beta.1

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of loofah might be problematic. Click here for more details.

@@ -1,5 +1,12 @@
1
1
  = Changelog
2
2
 
3
+ == 1.0.0.beta.1 (UNRELEASED)
4
+
5
+ Notes:
6
+
7
+ * Moved ActiveRecord functionality into `loofah-activerecord` gem.
8
+ * Removed DEPRECATIONS.rdoc documenting 0.3.0 API changes.
9
+
3
10
  == 0.4.7 (2010-03-09)
4
11
 
5
12
  Enhancements:
@@ -1,6 +1,6 @@
1
1
  The MIT License
2
2
 
3
- Copyright (c) 2009 Mike Dalessio, Bryan Helmkamp
3
+ Copyright (c) 2009, 2010 by Mike Dalessio, Bryan Helmkamp
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
@@ -1,17 +1,13 @@
1
1
  CHANGELOG.rdoc
2
- DEPRECATED.rdoc
3
2
  MIT-LICENSE.txt
4
3
  Manifest.txt
5
4
  README.rdoc
6
5
  Rakefile
7
- TODO.rdoc
8
6
  benchmark/benchmark.rb
9
7
  benchmark/fragment.html
10
8
  benchmark/helper.rb
11
9
  benchmark/www.slashdot.com.html
12
- init.rb
13
10
  lib/loofah.rb
14
- lib/loofah/active_record.rb
15
11
  lib/loofah/elements.rb
16
12
  lib/loofah/helpers.rb
17
13
  lib/loofah/html/document.rb
@@ -24,7 +20,6 @@ lib/loofah/scrubber.rb
24
20
  lib/loofah/scrubbers.rb
25
21
  lib/loofah/xml/document.rb
26
22
  lib/loofah/xml/document_fragment.rb
27
- lib/loofah/xss_foliate.rb
28
23
  test/helper.rb
29
24
  test/html5/test_sanitizer.rb
30
25
  test/integration/test_ad_hoc.rb
@@ -32,9 +27,7 @@ test/integration/test_helpers.rb
32
27
  test/integration/test_html.rb
33
28
  test/integration/test_scrubbers.rb
34
29
  test/integration/test_xml.rb
35
- test/unit/test_active_record.rb
36
30
  test/unit/test_api.rb
37
31
  test/unit/test_helpers.rb
38
32
  test/unit/test_scrubber.rb
39
33
  test/unit/test_scrubbers.rb
40
- test/unit/test_xss_foliate.rb
@@ -6,15 +6,19 @@
6
6
 
7
7
  == Description
8
8
 
9
- Loofah is a general library for manipulating HTML/XML documents and
10
- fragments. It's built on top of Nokogiri and libxml2, so it's fast and
11
- has a nice API.
9
+ Loofah is a general library for manipulating and transforming HTML/XML
10
+ documents and fragments. It's built on top of Nokogiri and libxml2, so
11
+ it's fast and has a nice API.
12
12
 
13
13
  Loofah excels at HTML sanitization (XSS prevention). It includes some
14
14
  nice HTML sanitizers, which are based on HTML5lib's whitelist, so it
15
15
  most likely won't make your codes less secure. (These statements have
16
16
  not been evaluated by Netexperts.)
17
17
 
18
+ ActiveRecord extensions for sanitization are available in the
19
+ `loofah-activerecord` gem (see
20
+ http://github.com/flavorjones/loofah-activerecord).
21
+
18
22
  == Features
19
23
 
20
24
  * Easily write custom scrubbers for HTML/XML leveraging the sweetness of Nokogiri (and HTML5lib's whitelists).
@@ -25,11 +29,8 @@ not been evaluated by Netexperts.)
25
29
  * _Whitewash_ the markup, removing all attributes and namespaced nodes.
26
30
  * Common HTML transformation tasks are built-in:
27
31
  * Add the _nofollow_ attribute to all hyperlinks.
28
- * Format markup as plain text.
29
- * Replace Rails's +strip_tags+ and +sanitize+ helper methods.
30
- * Two ActiveRecord extensions:
31
- * Loofah::XssFoliate, an XssTerminate[http://github.com/look/xss_terminate/tree/master] drop-in replacement, is an *opt-out* sanitizer. By default all models and attributes are sanitized.
32
- * Loofah::ActiveRecordExtension is an *opt-in* sanitizer. You must explicitly declare attributes to be sanitized.
32
+ * Format markup as plain text, with or without sensible whitespace handling around block elements.
33
+ * Replace Rails's +strip_tags+ and +sanitize+ view helper methods.
33
34
 
34
35
  == Compare and Contrast
35
36
 
@@ -37,7 +38,7 @@ Loofah is one of two known Ruby XSS/sanitization solutions that
37
38
  guarantees well-formed and valid markup (the other is Sanitize, which
38
39
  also uses Nokogiri).
39
40
 
40
- Loofah works fine on XML, XHTML and HTML documents.
41
+ Loofah works on XML, XHTML and HTML documents.
41
42
 
42
43
  Also, it's pretty fast. Here is a benchmark comparing Loofah to other
43
44
  commonly-used libraries (ActionView, Sanitize, HTML5lib and HTMLfilter):
@@ -226,45 +227,15 @@ are the same thing as (and arguably semantically clearer than):
226
227
  Loofah.xml_fragment(bad_xml).scrub!(custom_scrubber)
227
228
  Loofah.xml_document(bad_xml).scrub!(custom_scrubber)
228
229
 
229
- === ActiveRecord Extension \#1: Opt-In
230
-
231
- See Loofah::ActiveRecordExtension for full documentation. The methods
232
- mixed into ActiveRecord are:
233
-
234
- * Loofah::ActiveRecordExtension.html_document
235
- * Loofah::ActiveRecordExtension.html_fragment
236
-
237
- which are used to declare how specific string and text attributes
238
- should be scrubbed at +before_validation+.
239
-
240
- # app/model/post.rb
241
- class Post < ActiveRecord::Base
242
- html_fragment :body, :scrub => :prune # scrubs 'body' at before_validation
243
- end
244
-
245
- === ActiveRecord Extension \#2: Opt-Out
246
-
247
- See Loofah::XssFoliate::ClassMethods for more documentation. The methods mixed into ActiveRecord are:
248
-
249
- * Loofah::XssFoliate::ClassMethods.xss_foliate
250
- * Loofah::XssFoliate::ClassMethods.xss_foliated?
251
-
252
- which are used to declare how specific string and text attributes
253
- should be scrubbed at +before_validation+.
254
-
255
- Attributes are stripped by default, unless another scrubber is
256
- specified or the attribute is present in an +:except+ clause.
257
-
258
230
  === View Helpers
259
231
 
260
232
  Loofah has two "view helpers": Loofah::Helpers.sanitize and
261
233
  Loofah::Helpers.strip_tags, both of which are drop-in replacements for
262
- the ActionView helpers of the same name.
234
+ the Rails ActionView helpers of the same name.
263
235
 
264
236
  == Requirements
265
237
 
266
238
  * Nokogiri >= 1.3.3
267
- * Rails 2.3, 2.2, 2.1, 2.0 or 1.2 (if you're using the ActiveRecord extensions)
268
239
 
269
240
  == Installation
270
241
 
@@ -289,7 +260,6 @@ And the IRC channel is \#loofah on freenode.
289
260
  * Nokogiri: http://nokogiri.org
290
261
  * libxml2: http://xmlsoft.org
291
262
  * html5lib: http://code.google.com/p/html5lib
292
- * XssTerminate: http://github.com/look/xss_terminate/tree/master
293
263
 
294
264
  == Authors
295
265
 
@@ -302,7 +272,6 @@ Featuring code contributed by:
302
272
  * John Barnette
303
273
  * Josh Owens
304
274
  * Paul Dix
305
- * Josh Nichols
306
275
  * Luke Melia
307
276
 
308
277
  And a big shout-out to Corey Innis for the name, and feedback on the API.
@@ -322,7 +291,7 @@ name that nobody could spell properly.
322
291
 
323
292
  The MIT License
324
293
 
325
- Copyright (c) 2009 Mike Dalessio, Bryan Helmkamp
294
+ Copyright (c) 2009, 2010 by Mike Dalessio, Bryan Helmkamp
326
295
 
327
296
  Permission is hereby granted, free of charge, to any person obtaining a copy
328
297
  of this software and associated documentation files (the "Software"), to deal
data/Rakefile CHANGED
@@ -3,6 +3,7 @@ gem 'hoe', '>= 2.3.0'
3
3
  require 'hoe'
4
4
 
5
5
  Hoe.plugin :git
6
+ Hoe.plugin :bundler
6
7
 
7
8
  Hoe.spec "loofah" do
8
9
  developer "Mike Dalessio", "mike.dalessio@gmail.com"
@@ -12,23 +13,14 @@ Hoe.spec "loofah" do
12
13
  self.history_file = "CHANGELOG.rdoc"
13
14
  self.readme_file = "README.rdoc"
14
15
 
15
- extra_deps << ["nokogiri", ">= 1.3.3"]
16
+ extra_deps << ["nokogiri", ">=1.3.3"]
16
17
  extra_dev_deps << ["mocha", ">=0.9"]
17
- extra_dev_deps << ["thoughtbot-shoulda", ">=2.10"]
18
- extra_dev_deps << ["acts_as_fu", ">=0.0.5"]
19
-
20
- # note: .hoerc should have the following line to omit rails tests and tmp
21
- # exclude: !ruby/regexp /\/tmp\/|\/rails_tests\/|CVS|TAGS|\.(svn|git|DS_Store)/
18
+ extra_dev_deps << ["shoulda", ">=2.10"]
19
+ extra_dev_deps << ["rake", ">=0.8"]
22
20
  end
23
21
 
24
- if File.exist?("rails_test/Rakefile")
25
- load "rails_test/Rakefile"
26
- else
27
- task :test do
28
- puts "----------"
29
- puts "-- NOTE: An additional Rails regression test suite is available in source repository"
30
- puts "----------"
31
- end
22
+ task :gemspec do
23
+ system %q(rake debug_gem | grep -v "^\(in " > loofah.gemspec)
32
24
  end
33
25
 
34
26
  task :redocs => :fix_css
@@ -29,7 +29,7 @@ require 'loofah/helpers'
29
29
  #
30
30
  module Loofah
31
31
  # The version of Loofah you are using
32
- VERSION = '0.4.7'
32
+ VERSION = '1.0.0.beta.1'
33
33
 
34
34
  # The minimum required version of Nokogiri
35
35
  REQUIRED_NOKOGIRI_VERSION = '1.3.3'
@@ -85,13 +85,3 @@ end
85
85
  if Nokogiri::VERSION < Loofah::REQUIRED_NOKOGIRI_VERSION
86
86
  raise RuntimeError, "Loofah requires Nokogiri #{Loofah::REQUIRED_NOKOGIRI_VERSION} or later (currently #{Nokogiri::VERSION})"
87
87
  end
88
-
89
- if defined? Rails.configuration and Rails.configuration.frameworks.include?([:active_record]) # rails 2.1 and later
90
- Rails.configuration.after_initialize do
91
- require 'loofah/active_record'
92
- require 'loofah/xss_foliate'
93
- end
94
- elsif defined? ActiveRecord::Base # rails 2.0
95
- require 'loofah/active_record'
96
- require 'loofah/xss_foliate'
97
- end
@@ -2,7 +2,6 @@ require 'rubygems'
2
2
  require 'test/unit'
3
3
  require 'shoulda'
4
4
  require 'mocha'
5
- require 'acts_as_fu'
6
5
  require File.expand_path(File.join(File.dirname(__FILE__), "..", "lib", "loofah"))
7
6
 
8
7
  puts "=> testing with Nokogiri #{Nokogiri::VERSION_INFO.inspect}"
@@ -7,7 +7,7 @@ class TestScrubbers < Test::Unit::TestCase
7
7
  INVALID_PRUNED = "<div>quux</div>"
8
8
  INVALID_STRIPPED = "foo<p>bar</p>bazz<div>quux</div>"
9
9
 
10
- WHITEWASH_FRAGMENT = "<o:div>no</o:div><div id='no'>foo</div><invalid>bar</invalid>"
10
+ WHITEWASH_FRAGMENT = "<o:div>no</o:div><div id='no'>foo</div><invalid>bar</invalid><!--[if gts mso9]><div>microsofty stuff</div><![endif]-->"
11
11
  WHITEWASH_RESULT = "<div>foo</div>"
12
12
 
13
13
  NOFOLLOW_FRAGMENT = '<a href="http://www.example.com/">Click here</a>'
metadata CHANGED
@@ -1,51 +1,35 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: loofah
3
3
  version: !ruby/object:Gem::Version
4
- prerelease: false
4
+ hash: 62196353
5
+ prerelease: true
5
6
  segments:
7
+ - 1
8
+ - 0
6
9
  - 0
7
- - 4
8
- - 7
9
- version: 0.4.7
10
+ - beta
11
+ - 1
12
+ version: 1.0.0.beta.1
10
13
  platform: ruby
11
14
  authors:
12
15
  - Mike Dalessio
13
16
  - Bryan Helmkamp
14
17
  autorequire:
15
18
  bindir: bin
16
- cert_chain:
17
- - |
18
- -----BEGIN CERTIFICATE-----
19
- MIIDPDCCAiSgAwIBAgIBADANBgkqhkiG9w0BAQUFADBEMRYwFAYDVQQDDA1taWtl
20
- LmRhbGVzc2lvMRUwEwYKCZImiZPyLGQBGRYFZ21haWwxEzARBgoJkiaJk/IsZAEZ
21
- FgNjb20wHhcNMDkwODExMDU0MjQ5WhcNMTAwODExMDU0MjQ5WjBEMRYwFAYDVQQD
22
- DA1taWtlLmRhbGVzc2lvMRUwEwYKCZImiZPyLGQBGRYFZ21haWwxEzARBgoJkiaJ
23
- k/IsZAEZFgNjb20wggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQDANjr7
24
- lZ1DKtK8YvNp+5kBzIpwrpClHRrosqo01qmWfGBxZckQUtrJUwGPxpzvIHVq1VKp
25
- a9FXU/QWYek/1S0vhkOf9XGmFBnVCtbJhwGeyzsQFFSoQIfs2hd5gO0dSRpuKdi3
26
- slfJAXzFKg1u/7OCVPgrY/mkdh34MzL5p0gSDzPt7vLPibctHg0GoepYT5Fh1tMQ
27
- luzgrN0weTw/QoEWTMQcNk6CyUpzv0pOe7d0qEPQ9Lx7Lz64gIym3f0pKFpWLfME
28
- l7PFLeR95zw2zsuZQwCR5ma5zjXD3mo2jk1mVqiI8qplOL1u30FU7hRhTV5n/Qe9
29
- elDQoZW9Xz0R5JGDAgMBAAGjOTA3MAkGA1UdEwQCMAAwCwYDVR0PBAQDAgSwMB0G
30
- A1UdDgQWBBRXWlUJZXcR1jkZPE24+mjUTCqNxjANBgkqhkiG9w0BAQUFAAOCAQEA
31
- jDh5M41sg1MZKG1DXzQmo/IADeWRmXyb3EZaED9lhFFpoQqaralgpgmvuc0GswvO
32
- QIZijh03tPQz8lgp1U1OFZod2ZwbEVTtVZpxs1ssjMraOA6KzlsNROH0XonIiy6j
33
- r2Q0UF35ax8pvr3D5Y6AKzIW1F3aeiREylUDJlb/i1dPQ2PVK0yRrSQoK2epwM9E
34
- zoczlHTTJc/tRvH5Up3Agcv9y+J0U9a1Af9NRsnHPVBdo2H32MsJ99x5NRDWJmJg
35
- ohH37UR7njcc6j4fo22IwTqXaaXJdtVdAWjXP/xs5B3cPYSP6uqFnR46Jf86Iqj1
36
- FlqnTjy13J3nD30uxy9a1g==
37
- -----END CERTIFICATE-----
19
+ cert_chain: []
38
20
 
39
- date: 2010-03-09 00:00:00 -05:00
21
+ date: 2010-07-21 00:00:00 -04:00
40
22
  default_executable:
41
23
  dependencies:
42
24
  - !ruby/object:Gem::Dependency
43
25
  name: nokogiri
44
26
  prerelease: false
45
27
  requirement: &id001 !ruby/object:Gem::Requirement
28
+ none: false
46
29
  requirements:
47
30
  - - ">="
48
31
  - !ruby/object:Gem::Version
32
+ hash: 29
49
33
  segments:
50
34
  - 1
51
35
  - 3
@@ -57,93 +41,92 @@ dependencies:
57
41
  name: rubyforge
58
42
  prerelease: false
59
43
  requirement: &id002 !ruby/object:Gem::Requirement
44
+ none: false
60
45
  requirements:
61
46
  - - ">="
62
47
  - !ruby/object:Gem::Version
48
+ hash: 7
63
49
  segments:
64
50
  - 2
65
51
  - 0
66
- - 3
67
- version: 2.0.3
52
+ - 4
53
+ version: 2.0.4
68
54
  type: :development
69
55
  version_requirements: *id002
70
- - !ruby/object:Gem::Dependency
71
- name: gemcutter
72
- prerelease: false
73
- requirement: &id003 !ruby/object:Gem::Requirement
74
- requirements:
75
- - - ">="
76
- - !ruby/object:Gem::Version
77
- segments:
78
- - 0
79
- - 3
80
- - 0
81
- version: 0.3.0
82
- type: :development
83
- version_requirements: *id003
84
56
  - !ruby/object:Gem::Dependency
85
57
  name: mocha
86
58
  prerelease: false
87
- requirement: &id004 !ruby/object:Gem::Requirement
59
+ requirement: &id003 !ruby/object:Gem::Requirement
60
+ none: false
88
61
  requirements:
89
62
  - - ">="
90
63
  - !ruby/object:Gem::Version
64
+ hash: 25
91
65
  segments:
92
66
  - 0
93
67
  - 9
94
68
  version: "0.9"
95
69
  type: :development
96
- version_requirements: *id004
70
+ version_requirements: *id003
97
71
  - !ruby/object:Gem::Dependency
98
- name: thoughtbot-shoulda
72
+ name: shoulda
99
73
  prerelease: false
100
- requirement: &id005 !ruby/object:Gem::Requirement
74
+ requirement: &id004 !ruby/object:Gem::Requirement
75
+ none: false
101
76
  requirements:
102
77
  - - ">="
103
78
  - !ruby/object:Gem::Version
79
+ hash: 23
104
80
  segments:
105
81
  - 2
106
82
  - 10
107
83
  version: "2.10"
108
84
  type: :development
109
- version_requirements: *id005
85
+ version_requirements: *id004
110
86
  - !ruby/object:Gem::Dependency
111
- name: acts_as_fu
87
+ name: rake
112
88
  prerelease: false
113
- requirement: &id006 !ruby/object:Gem::Requirement
89
+ requirement: &id005 !ruby/object:Gem::Requirement
90
+ none: false
114
91
  requirements:
115
92
  - - ">="
116
93
  - !ruby/object:Gem::Version
94
+ hash: 27
117
95
  segments:
118
96
  - 0
119
- - 0
120
- - 5
121
- version: 0.0.5
97
+ - 8
98
+ version: "0.8"
122
99
  type: :development
123
- version_requirements: *id006
100
+ version_requirements: *id005
124
101
  - !ruby/object:Gem::Dependency
125
102
  name: hoe
126
103
  prerelease: false
127
- requirement: &id007 !ruby/object:Gem::Requirement
104
+ requirement: &id006 !ruby/object:Gem::Requirement
105
+ none: false
128
106
  requirements:
129
107
  - - ">="
130
108
  - !ruby/object:Gem::Version
109
+ hash: 21
131
110
  segments:
132
111
  - 2
133
- - 5
134
- - 0
135
- version: 2.5.0
112
+ - 6
113
+ - 1
114
+ version: 2.6.1
136
115
  type: :development
137
- version_requirements: *id007
116
+ version_requirements: *id006
138
117
  description: |-
139
- Loofah is a general library for manipulating HTML/XML documents and
140
- fragments. It's built on top of Nokogiri and libxml2, so it's fast and
141
- has a nice API.
118
+ Loofah is a general library for manipulating and transforming HTML/XML
119
+ documents and fragments. It's built on top of Nokogiri and libxml2, so
120
+ it's fast and has a nice API.
142
121
 
143
122
  Loofah excels at HTML sanitization (XSS prevention). It includes some
144
123
  nice HTML sanitizers, which are based on HTML5lib's whitelist, so it
145
124
  most likely won't make your codes less secure. (These statements have
146
125
  not been evaluated by Netexperts.)
126
+
127
+ ActiveRecord extensions for sanitization are available in the
128
+ `loofah-activerecord` gem (see
129
+ http://github.com/flavorjones/loofah-activerecord).
147
130
  email:
148
131
  - mike.dalessio@gmail.com
149
132
  - bryan@brynary.com
@@ -154,25 +137,19 @@ extensions: []
154
137
  extra_rdoc_files:
155
138
  - MIT-LICENSE.txt
156
139
  - Manifest.txt
157
- - TODO.rdoc
158
140
  - CHANGELOG.rdoc
159
- - DEPRECATED.rdoc
160
141
  - README.rdoc
161
142
  files:
162
143
  - CHANGELOG.rdoc
163
- - DEPRECATED.rdoc
164
144
  - MIT-LICENSE.txt
165
145
  - Manifest.txt
166
146
  - README.rdoc
167
147
  - Rakefile
168
- - TODO.rdoc
169
148
  - benchmark/benchmark.rb
170
149
  - benchmark/fragment.html
171
150
  - benchmark/helper.rb
172
151
  - benchmark/www.slashdot.com.html
173
- - init.rb
174
152
  - lib/loofah.rb
175
- - lib/loofah/active_record.rb
176
153
  - lib/loofah/elements.rb
177
154
  - lib/loofah/helpers.rb
178
155
  - lib/loofah/html/document.rb
@@ -185,7 +162,6 @@ files:
185
162
  - lib/loofah/scrubbers.rb
186
163
  - lib/loofah/xml/document.rb
187
164
  - lib/loofah/xml/document_fragment.rb
188
- - lib/loofah/xss_foliate.rb
189
165
  - test/helper.rb
190
166
  - test/html5/test_sanitizer.rb
191
167
  - test/integration/test_ad_hoc.rb
@@ -193,12 +169,10 @@ files:
193
169
  - test/integration/test_html.rb
194
170
  - test/integration/test_scrubbers.rb
195
171
  - test/integration/test_xml.rb
196
- - test/unit/test_active_record.rb
197
172
  - test/unit/test_api.rb
198
173
  - test/unit/test_helpers.rb
199
174
  - test/unit/test_scrubber.rb
200
175
  - test/unit/test_scrubbers.rb
201
- - test/unit/test_xss_foliate.rb
202
176
  has_rdoc: true
203
177
  homepage: http://github.com/flavorjones/loofah
204
178
  licenses: []
@@ -210,36 +184,40 @@ rdoc_options:
210
184
  require_paths:
211
185
  - lib
212
186
  required_ruby_version: !ruby/object:Gem::Requirement
187
+ none: false
213
188
  requirements:
214
189
  - - ">="
215
190
  - !ruby/object:Gem::Version
191
+ hash: 3
216
192
  segments:
217
193
  - 0
218
194
  version: "0"
219
195
  required_rubygems_version: !ruby/object:Gem::Requirement
196
+ none: false
220
197
  requirements:
221
- - - ">="
198
+ - - ">"
222
199
  - !ruby/object:Gem::Version
200
+ hash: 25
223
201
  segments:
224
- - 0
225
- version: "0"
202
+ - 1
203
+ - 3
204
+ - 1
205
+ version: 1.3.1
226
206
  requirements: []
227
207
 
228
208
  rubyforge_project: loofah
229
- rubygems_version: 1.3.6
209
+ rubygems_version: 1.3.7
230
210
  signing_key:
231
211
  specification_version: 3
232
- summary: Loofah is a general library for manipulating HTML/XML documents and fragments
212
+ summary: Loofah is a general library for manipulating and transforming HTML/XML documents and fragments
233
213
  test_files:
214
+ - test/integration/test_html.rb
215
+ - test/integration/test_ad_hoc.rb
234
216
  - test/integration/test_helpers.rb
235
217
  - test/integration/test_scrubbers.rb
236
- - test/integration/test_ad_hoc.rb
237
218
  - test/integration/test_xml.rb
238
- - test/integration/test_html.rb
239
- - test/unit/test_xss_foliate.rb
240
- - test/unit/test_helpers.rb
219
+ - test/html5/test_sanitizer.rb
241
220
  - test/unit/test_scrubber.rb
221
+ - test/unit/test_helpers.rb
242
222
  - test/unit/test_scrubbers.rb
243
223
  - test/unit/test_api.rb
244
- - test/unit/test_active_record.rb
245
- - test/html5/test_sanitizer.rb
data.tar.gz.sig DELETED
@@ -1,4 +0,0 @@
1
- ����'�e�#$G(�ޓ���z�_�%R#�
2
- ި�-�8
3
- ��JS![e�&�޽�'u�`�2mR��� [ȇ��Qi��v�iq_�п�����{�\e�XU�hb�`���� �׭��|*�V���l�E��D_en"l������4��x�:P���&�({j����c87;
4
- -%pcvy�c��kf��1#�S��мd�:���`����7��f�ޑ��Z��k.pAZ�СZY #~1< C!VU}�z�Z����
@@ -1,12 +0,0 @@
1
- = Deprecations
2
-
3
- In Loofah 0.3.0, some methods have been deprecated. The following
4
- lists the equivalent calls with the post-0.2 API:
5
-
6
- * <tt>strip_tags(string_or_io)</tt> is now <tt>scrub_document(string_or_io, :prune).text</tt>
7
- * <tt>whitewash(string_or_io)</tt> is now <tt>scrub_fragment(string_or_io, :whitewash).to_s</tt>
8
- * <tt>whitewash_document(string_or_io)</tt> is now <tt>scrub_document(string_or_io, :whitewash).to_s</tt>
9
- * <tt>sanitize(string_or_io)</tt> is now <tt>scrub_fragment(string_or_io, :escape).to_xml</tt>
10
- * <tt>sanitize_document(string_or_io)</tt> is now <tt>scrub_document(string_or_io, :escape).to_xml</tt>
11
-
12
- Have a nice day.
data/TODO.rdoc DELETED
@@ -1,4 +0,0 @@
1
- = TODO
2
-
3
- * Allow a <tt>text</tt> option to insert nice newlines after headers and block elements.
4
- * <tt>to_markdown<tt>
data/init.rb DELETED
@@ -1 +0,0 @@
1
- require "loofah"
@@ -1,60 +0,0 @@
1
- module Loofah
2
- #
3
- # Loofah can scrub ActiveRecord attributes in a before_validation callback:
4
- #
5
- # # config/initializers/loofah.rb
6
- # require 'loofah'
7
- #
8
- # # db/schema.rb
9
- # create_table "posts" do |t|
10
- # t.string "title"
11
- # t.string "body"
12
- # end
13
- #
14
- # # app/model/post.rb
15
- # class Post < ActiveRecord::Base
16
- # html_fragment :body, :scrub => :prune # scrubs 'body' in a before_validation
17
- # end
18
- #
19
- module ActiveRecordExtension
20
- #
21
- # :call-seq:
22
- # html_fragment(attribute, :scrub => scrubber_specification)
23
- #
24
- # Scrub an ActiveRecord attribute +attribute+ as an HTML *fragment*
25
- # using the method specified by +scrubber_specification+.
26
- #
27
- # +scrubber_specification+ must be an argument acceptable to Loofah::ScrubBehavior.scrub!, namely:
28
- #
29
- # * a symbol for one of the built-in scrubbers (see Loofah::Scrubbers for a full list)
30
- # * or a Scrubber instance. (see Loofah::Scrubber for help on implementing a custom scrubber)
31
- #
32
- def html_fragment(attr, options={})
33
- raise ArgumentError, "html_fragment requires :scrub option" unless method = options[:scrub]
34
- before_validation do |record|
35
- record[attr] = Loofah.scrub_fragment(record[attr], method).to_s
36
- end
37
- end
38
-
39
- #
40
- # :call-seq:
41
- # model.html_document(attribute, :scrub => scrubber_specification)
42
- #
43
- # Scrub an ActiveRecord attribute +attribute+ as an HTML *document*
44
- # using the method specified by +scrubber_specification+.
45
- #
46
- # +scrubber_specification+ must be an argument acceptable to Loofah::ScrubBehavior.scrub!, namely:
47
- #
48
- # * a symbol for one of the built-in scrubbers (see Loofah::Scrubbers for a full list)
49
- # * or a Scrubber instance.
50
- #
51
- def html_document(attr, options={})
52
- raise ArgumentError, "html_document requires :scrub option" unless method = options[:scrub]
53
- before_validation do |record|
54
- record[attr] = Loofah.scrub_document(record[attr], method).to_s
55
- end
56
- end
57
- end
58
- end
59
-
60
- ActiveRecord::Base.extend(Loofah::ActiveRecordExtension)
@@ -1,211 +0,0 @@
1
- module Loofah
2
- #
3
- # A replacement for
4
- # XssTerminate[http://github.com/look/xss_terminate/tree/master],
5
- # XssFoliate will strip all tags from your ActiveRecord models'
6
- # string and text attributes.
7
- #
8
- # Please read the Loofah documentation for an explanation of the
9
- # different scrubbing methods, and
10
- # Loofah::XssFoliate::ClassMethods for more information on the
11
- # methods.
12
- #
13
- # If you'd like to scrub all fields in all your models (and perhaps *opt-out* in specific models):
14
- #
15
- # # config/initializers/loofah.rb
16
- # require 'loofah'
17
- # Loofah::XssFoliate.xss_foliate_all_models
18
- #
19
- # # db/schema.rb
20
- # create_table "posts" do |t|
21
- # t.string "title"
22
- # t.text "body"
23
- # t.string "author"
24
- # end
25
- #
26
- # # app/model/post.rb
27
- # class Post < ActiveRecord::Base
28
- # # by default, title, body and author will all be scrubbed down to their inner text
29
- # end
30
- #
31
- # OR
32
- #
33
- # # app/model/post.rb
34
- # class Post < ActiveRecord::Base
35
- # xss_foliate :except => :author # opt-out of sanitizing author
36
- # end
37
- #
38
- # OR
39
- #
40
- # xss_foliate :strip => [:title, body] # strip unsafe tags from both title and body
41
- #
42
- # OR
43
- #
44
- # xss_foliate :except => :title # scrub body and author but not title
45
- #
46
- # OR
47
- #
48
- # # remove all tags from title, remove unsafe tags from body
49
- # xss_foliate :sanitize => :title, :scrub => :body
50
- #
51
- # OR
52
- #
53
- # # old xss_terminate code will work if you s/_terminate/_foliate/
54
- # # was: xss_terminate :except => [:title], :sanitize => [:body]
55
- # xss_foliate :except => [:title], :sanitize => [:body]
56
- #
57
- # Alternatively, if you would like to *opt-in* to the models and attributes that are sanitized:
58
- #
59
- # # config/initializers/loofah.rb
60
- # require 'loofah'
61
- # ## note omission of call to Loofah::XssFoliate.xss_foliate_all_models
62
- #
63
- # # db/schema.rb
64
- # create_table "posts" do |t|
65
- # t.string "title"
66
- # t.text "body"
67
- # t.string "author"
68
- # end
69
- #
70
- # # app/model/post.rb
71
- # class Post < ActiveRecord::Base
72
- # xss_foliate # scrub title, body and author down to their inner text
73
- # end
74
- #
75
- module XssFoliate
76
- #
77
- # A replacement for
78
- # XssTerminate[http://github.com/look/xss_terminate/tree/master],
79
- # XssFoliate will strip all tags from your ActiveRecord models'
80
- # string and text attributes.
81
- #
82
- # See Loofah::XssFoliate for more example usage.
83
- #
84
- module ClassMethods
85
- # :stopdoc:
86
- VALID_OPTIONS = [:except, :html5lib_sanitize, :sanitize] + Loofah::Scrubbers.scrubber_symbols
87
- ALIASED_OPTIONS = {:html5lib_sanitize => :escape, :sanitize => :strip}
88
- REAL_OPTIONS = VALID_OPTIONS - ALIASED_OPTIONS.keys
89
- # :startdoc:
90
-
91
- #
92
- # Annotate your model with this method to specify which fields
93
- # you want scrubbed, and how you want them scrubbed. XssFoliate
94
- # assumes all character fields are HTML fragments (as opposed to
95
- # full documents, see the Loofah[http://loofah.rubyforge.org/]
96
- # documentation for a full explanation of the difference).
97
- #
98
- # Example call:
99
- #
100
- # xss_foliate :except => :author, :strip => :body, :prune => [:title, :description]
101
- #
102
- # *Note* that the values in the options hash can be either an
103
- # array of attributes or a single attribute.
104
- #
105
- # Options:
106
- #
107
- # :except => [fields] # don't scrub these fields
108
- # :strip => [fields] # strip unsafe tags from these fields
109
- # :escape => [fields] # escape unsafe tags from these fields
110
- # :prune => [fields] # prune unsafe tags and subtrees from these fields
111
- # :text => [fields] # remove everything except the inner text from these fields
112
- #
113
- # XssTerminate compatibility options (note that the default
114
- # behavior in XssTerminate corresponds to :text)
115
- #
116
- # :html5lib_sanitize => [fields] # same as :escape
117
- # :sanitize => [fields] # same as :strip
118
- #
119
- # The default is :text for all fields unless otherwise specified.
120
- #
121
- def xss_foliate(options = {})
122
- callback_already_declared = \
123
- if respond_to?(:before_validation_callback_chain)
124
- # Rails 2.1 and later
125
- before_validation_callback_chain.any? {|cb| cb.method == :xss_foliate_fields}
126
- else
127
- # Rails 2.0
128
- cbs = read_inheritable_attribute(:before_validation)
129
- (! cbs.nil?) && cbs.any? {|cb| cb == :xss_foliate_fields}
130
- end
131
-
132
- unless callback_already_declared
133
- before_validation :xss_foliate_fields
134
- class_inheritable_reader :xss_foliate_options
135
- include XssFoliate::InstanceMethods
136
- end
137
-
138
- options.keys.each do |option|
139
- raise ArgumentError, "unknown xss_foliate option #{option}" unless VALID_OPTIONS.include?(option)
140
- end
141
-
142
- REAL_OPTIONS.each do |option|
143
- options[option] = Array(options[option]).collect { |val| val.to_sym }
144
- end
145
-
146
- ALIASED_OPTIONS.each do |option, real|
147
- options[real] += Array(options.delete(option)).collect { |val| val.to_sym } if options[option]
148
- end
149
-
150
- write_inheritable_attribute(:xss_foliate_options, options)
151
- end
152
-
153
- #
154
- # Class method to determine whether or not this model is applying
155
- # xss_foliation to its attributes. Could be useful in test suites.
156
- #
157
- def xss_foliated?
158
- options = read_inheritable_attribute(:xss_foliate_options)
159
- ! (options.nil? || options.empty?)
160
- end
161
- end
162
-
163
- module InstanceMethods
164
- def xss_foliate_fields # :nodoc:
165
- # fix a bug with Rails internal AR::Base models that get loaded before
166
- # the plugin, like CGI::Sessions::ActiveRecordStore::Session
167
- return if xss_foliate_options.nil?
168
-
169
- self.class.columns.each do |column|
170
- next unless (column.type == :string || column.type == :text)
171
-
172
- field = column.name.to_sym
173
- value = self[field]
174
-
175
- next if value.nil? || !value.is_a?(String)
176
-
177
- next if xss_foliate_options[:except].include?(field)
178
-
179
- next if xss_foliated_with_standard_scrubber(field)
180
-
181
- # :text if we're here
182
- fragment = Loofah.scrub_fragment(value, :strip)
183
- self[field] = fragment.nil? ? "" : fragment.text
184
- end
185
- end
186
-
187
- private
188
-
189
- def xss_foliated_with_standard_scrubber(field)
190
- Loofah::Scrubbers.scrubber_symbols.each do |method|
191
- if xss_foliate_options[method].include?(field)
192
- fragment = Loofah.scrub_fragment(self[field], method)
193
- self[field] = fragment.nil? ? "" : fragment.to_s
194
- return true
195
- end
196
- end
197
- false
198
- end
199
- end
200
-
201
- def self.xss_foliate_all_models
202
- ActiveRecord::Base.xss_foliate
203
- end
204
- end
205
- end
206
-
207
- ActiveRecord::Base.extend(Loofah::XssFoliate::ClassMethods)
208
-
209
- if defined?(LOOFAH_XSS_FOLIATE_ALL_MODELS) && LOOFAH_XSS_FOLIATE_ALL_MODELS
210
- Loofah::XssFoliate.xss_foliate_all_models
211
- end
@@ -1,143 +0,0 @@
1
- require File.expand_path(File.join(File.dirname(__FILE__), '..', 'helper'))
2
-
3
- require 'loofah/active_record'
4
-
5
- class TestActiveRecord < Test::Unit::TestCase
6
-
7
- HTML_STRING = "<div>omgwtfbbq</div>"
8
- PLAIN_TEXT = "vanilla text"
9
-
10
- context "with a Post model" do
11
- setup do
12
- ActsAsFu.build_model(:posts) do
13
- string :plain_text
14
- string :html_string
15
- end
16
- end
17
-
18
- context "scrubbing a single field as a fragment" do
19
- context "using a symbol to indicate the attribute" do
20
- setup do
21
- Post.html_fragment :html_string, :scrub => :prune
22
- assert ! Post.xss_foliated?
23
- @post = Post.new :html_string => HTML_STRING, :plain_text => PLAIN_TEXT
24
- end
25
-
26
- should "scrub the specified field" do
27
- Loofah.expects(:scrub_fragment).with(HTML_STRING, :prune).once
28
- Loofah.expects(:scrub_fragment).with(PLAIN_TEXT, :prune).never
29
- @post.valid?
30
- end
31
-
32
- should "only call scrub_fragment once" do
33
- Loofah.expects(:scrub_fragment).once
34
- @post.valid?
35
- end
36
-
37
- should "generate strings" do
38
- @post.valid?
39
- assert_equal String, @post.html_string.class
40
- assert_equal HTML_STRING, @post.html_string
41
- end
42
- end
43
-
44
- context "using a string to indicate the attribute" do
45
- setup do
46
- Post.html_fragment 'html_string', :scrub => :prune
47
- assert ! Post.xss_foliated?
48
- @post = Post.new :html_string => HTML_STRING, :plain_text => PLAIN_TEXT
49
- end
50
-
51
- should "scrub the specified field" do
52
- Loofah.expects(:scrub_fragment).with(HTML_STRING, :prune).once
53
- Loofah.expects(:scrub_fragment).with(PLAIN_TEXT, :prune).never
54
- @post.valid?
55
- end
56
- end
57
- end
58
-
59
- context "scrubbing a single field as a document" do
60
- context "using a symbol to indicate the attribute" do
61
- setup do
62
- Post.html_document :html_string, :scrub => :strip
63
- @post = Post.new :html_string => HTML_STRING, :plain_text => PLAIN_TEXT
64
- end
65
-
66
- should "scrub the specified field, but not other fields" do
67
- Loofah.expects(:scrub_document).with(HTML_STRING, :strip).once
68
- Loofah.expects(:scrub_document).with(PLAIN_TEXT, :strip).never
69
- @post.valid?
70
- end
71
-
72
- should "only call scrub_document once" do
73
- Loofah.expects(:scrub_document).once
74
- @post.valid?
75
- end
76
-
77
- should "generate strings" do
78
- @post.valid?
79
- assert_equal String, @post.html_string.class
80
- end
81
- end
82
-
83
- context "using a string to indicate the attribute" do
84
- setup do
85
- Post.html_document 'html_string', :scrub => :strip
86
- @post = Post.new :html_string => HTML_STRING, :plain_text => PLAIN_TEXT
87
- end
88
-
89
- should "scrub the specified field, but not other fields" do
90
- Loofah.expects(:scrub_document).with(HTML_STRING, :strip).once
91
- Loofah.expects(:scrub_document).with(PLAIN_TEXT, :strip).never
92
- @post.valid?
93
- end
94
- end
95
- end
96
-
97
- context "not passing any options" do
98
- should "raise ArgumentError" do
99
- assert_raises(ArgumentError) {
100
- Post.html_fragment :foo
101
- }
102
- end
103
- end
104
-
105
- context "not passing :scrub option" do
106
- should "raise ArgumentError" do
107
- assert_raise(ArgumentError) {
108
- Post.html_fragment :foo, :bar => :quux
109
- }
110
- end
111
- end
112
-
113
- context "passing a :scrub option" do
114
- should "not raise ArgumentError" do
115
- assert_nothing_raised {
116
- Post.html_fragment :foo, :scrub => :quux
117
- }
118
- end
119
- end
120
-
121
- context "passing a Scrubber" do
122
- setup do
123
- @called = false
124
- @scrubber = Loofah::Scrubber.new do |node|
125
- @called = true
126
- end
127
- end
128
-
129
- should "not raise ArgumentError" do
130
- assert_nothing_raised {
131
- Post.html_fragment :html_string, :scrub => @scrubber
132
- }
133
- end
134
-
135
- should "scrub properly" do
136
- Post.html_fragment :html_string, :scrub => @scrubber
137
- post = Post.new :html_string => HTML_STRING, :plain_text => PLAIN_TEXT
138
- post.valid?
139
- assert @called
140
- end
141
- end
142
- end
143
- end
@@ -1,188 +0,0 @@
1
- require File.expand_path(File.join(File.dirname(__FILE__), '..', 'helper'))
2
-
3
- class TestXssFoliate < Test::Unit::TestCase
4
-
5
- HTML_STRING = "<div>omgwtfbbq</div>"
6
- PLAIN_TEXT = "vanilla text"
7
- INTEGER_VALUE = "1234"
8
- WHITESPACEY = " <br> "
9
-
10
- def new_post(overrides={})
11
- Post.new({:html_string => HTML_STRING, :plain_text => PLAIN_TEXT, :not_a_string => INTEGER_VALUE}.merge(overrides))
12
- end
13
-
14
- context "with a Post model" do
15
- setup do
16
- ActsAsFu.build_model(:posts) do
17
- string :plain_text
18
- string :html_string
19
- integer :not_a_string
20
- end
21
- end
22
-
23
- context "#xss_foliated?" do
24
- context "when xss_foliate has not been called" do
25
- should "return false" do
26
- assert ! Post.xss_foliated?
27
- end
28
- end
29
-
30
- context "when xss_foliate has been called with no options" do
31
- setup do
32
- Post.xss_foliate
33
- end
34
-
35
- should "return true" do
36
- assert Post.xss_foliated?
37
- end
38
- end
39
-
40
- context "when xss_foliate has been called with options" do
41
- setup do
42
- Post.xss_foliate :prune => :plain_text
43
- end
44
-
45
- should "return true" do
46
- assert Post.xss_foliated?
47
- end
48
- end
49
- end
50
-
51
- context "#xss_foliate" do
52
- context "when passed invalid option" do
53
- should "raise ArgumentError" do
54
- assert_raise(ArgumentError) { Post.xss_foliate :quux => [:foo] }
55
- end
56
- end
57
-
58
- context "when passed a symbol" do
59
- should "calls the right scrubber" do
60
- assert_nothing_raised(ArgumentError) { Post.xss_foliate :prune => :plain_text }
61
- Loofah.expects(:scrub_fragment).with(HTML_STRING, :strip).once
62
- Loofah.expects(:scrub_fragment).with(PLAIN_TEXT, :prune).once
63
- new_post.valid?
64
- end
65
- end
66
-
67
- context "when passed an array of symbols" do
68
- should "calls the right scrubbers" do
69
- assert_nothing_raised(ArgumentError) {
70
- Post.xss_foliate :prune => [:plain_text, :html_string]
71
- }
72
- Loofah.expects(:scrub_fragment).with(HTML_STRING, :prune).once
73
- Loofah.expects(:scrub_fragment).with(PLAIN_TEXT, :prune).once
74
- new_post.valid?
75
- end
76
- end
77
-
78
- context "when passed a string" do
79
- should "calls the right scrubber" do
80
- assert_nothing_raised(ArgumentError) { Post.xss_foliate :prune => 'plain_text' }
81
- Loofah.expects(:scrub_fragment).with(HTML_STRING, :strip).once
82
- Loofah.expects(:scrub_fragment).with(PLAIN_TEXT, :prune).once
83
- new_post.valid?
84
- end
85
- end
86
-
87
- context "when passed an array of strings" do
88
- should "calls the right scrubbers" do
89
- assert_nothing_raised(ArgumentError) {
90
- Post.xss_foliate :prune => ['plain_text', 'html_string']
91
- }
92
- Loofah.expects(:scrub_fragment).with(HTML_STRING, :prune).once
93
- Loofah.expects(:scrub_fragment).with(PLAIN_TEXT, :prune).once
94
- new_post.valid?
95
- end
96
- end
97
- end
98
-
99
- context "declaring scrubbed fields" do
100
- context "on all fields" do
101
- setup do
102
- Post.xss_foliate
103
- end
104
-
105
- should "scrub all fields" do
106
- mock_doc = mock
107
- Loofah.expects(:scrub_fragment).with(HTML_STRING, :strip).once.returns(mock_doc)
108
- Loofah.expects(:scrub_fragment).with(PLAIN_TEXT, :strip).once.returns(mock_doc)
109
- Loofah.expects(:scrub_fragment).with(INTEGER_VALUE, :strip).never
110
- mock_doc.expects(:text).twice
111
- assert new_post.valid?
112
- end
113
- end
114
-
115
- context "omitting one field" do
116
- setup do
117
- Post.xss_foliate :except => [:plain_text]
118
- end
119
-
120
- should "not scrub omitted field" do
121
- mock_doc = mock
122
- Loofah.expects(:scrub_fragment).with(HTML_STRING, :strip).once.returns(mock_doc)
123
- Loofah.expects(:scrub_fragment).with(PLAIN_TEXT, :strip).never
124
- Loofah.expects(:scrub_fragment).with(INTEGER_VALUE, :strip).never
125
- mock_doc.expects(:text).once
126
- new_post.valid?
127
- end
128
- end
129
-
130
- Loofah::Scrubbers.scrubber_symbols.each do |method|
131
- context "declaring one field to be scrubbed with #{method}" do
132
- setup do
133
- Post.xss_foliate method => [:plain_text]
134
- end
135
-
136
- should "scrub that field appropriately" do
137
- mock_doc = mock
138
- Loofah.expects(:scrub_fragment).with(HTML_STRING, :strip).once
139
- Loofah.expects(:scrub_fragment).with(PLAIN_TEXT, method).once.returns(mock_doc)
140
- Loofah.expects(:scrub_fragment).with(INTEGER_VALUE, :strip).never
141
- mock_doc.expects(:to_s)
142
- new_post.valid?
143
- end
144
- end
145
- end
146
-
147
- context "declaring one field to be scrubbed with html5lib_sanitize" do
148
- setup do
149
- Post.xss_foliate :html5lib_sanitize => [:plain_text]
150
- end
151
-
152
- should "not that field appropriately" do
153
- Loofah.expects(:scrub_fragment).with(HTML_STRING, :strip) .once
154
- Loofah.expects(:scrub_fragment).with(PLAIN_TEXT, :escape).once
155
- Loofah.expects(:scrub_fragment).with(INTEGER_VALUE, :strip) .never
156
- new_post.valid?
157
- end
158
- end
159
- end
160
-
161
- context "invalid model data" do
162
- setup do
163
- Post.validates_presence_of :html_string
164
- Post.xss_foliate
165
- end
166
-
167
- should "not be valid after sanitizing" do
168
- Loofah.expects(:scrub_fragment).with(WHITESPACEY, :strip).once
169
- Loofah.expects(:scrub_fragment).with(PLAIN_TEXT, :strip).once
170
- assert ! new_post(:html_string => WHITESPACEY).valid?
171
- end
172
- end
173
-
174
- context "given an XSS attempt" do
175
- setup do
176
- Post.xss_foliate :strip => :html_string
177
- end
178
-
179
- should "escape html entities" do
180
- hackattack = "<div>&lt;script&gt;alert('evil')&lt;/script&gt;</div>"
181
- post = new_post :html_string => hackattack, :plain_text => hackattack
182
- post.valid?
183
- assert_equal "<div>&lt;script&gt;alert('evil')&lt;/script&gt;</div>", post.html_string
184
- assert_equal "&lt;script&gt;alert('evil')&lt;/script&gt;", post.plain_text
185
- end
186
- end
187
- end
188
- end
metadata.gz.sig DELETED
Binary file