rexml-expansion-fix 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/LICENSE ADDED
@@ -0,0 +1,14 @@
1
+ Copyright (c) 2008 Michael Koziarski <michael@koziarski.com>
2
+
3
+ Permission to use, copy, modify, and/or distribute this software for any
4
+ purpose with or without fee is hereby granted, provided that the above
5
+ copyright notice and this permission notice appear in all copies.
6
+
7
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
8
+ WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
9
+ MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
10
+ ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
11
+ WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
12
+ ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
13
+ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
14
+
@@ -0,0 +1,9 @@
1
+ h1. REXML Expansion Fix
2
+
3
+ The version of rexml which ships with ruby at present will not restrict the total number of entity expanstions when processing inline attributes. This can allow specially crafted documents to consume enormous amounts of CPU. To prevent this from happening this fix causes processing to abort processing after a certain number of expansions have taken place. The limit defaults to 10000 but you can change it as follows:
4
+
5
+ REXML::Document.entity_expansion_limit= 50
6
+
7
+ The example xml in example.xml can be used to verify that your application is safe.
8
+
9
+
@@ -0,0 +1,13 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <!DOCTYPE member [
3
+ <!ENTITY a "&b;&b;&b;&b;&b;&b;&b;&b;&b;&b;">
4
+ <!ENTITY b "&c;&c;&c;&c;&c;&c;&c;&c;&c;&c;">
5
+ <!ENTITY c "&d;&d;&d;&d;&d;&d;&d;&d;&d;&d;">
6
+ <!ENTITY d "&e;&e;&e;&e;&e;&e;&e;&e;&e;&e;">
7
+ <!ENTITY e "&f;&f;&f;&f;&f;&f;&f;&f;&f;&f;">
8
+ <!ENTITY f "&g;&g;&g;&g;&g;&g;&g;&g;&g;&g;">
9
+ <!ENTITY g "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx">
10
+ ]>
11
+ <member>
12
+ &a;
13
+ </member>
@@ -0,0 +1,43 @@
1
+ # Copyright (c) 2008 Michael Koziarski <michael@koziarski.com>
2
+ #
3
+ # Permission to use, copy, modify, and/or distribute this software for any
4
+ # purpose with or without fee is hereby granted, provided that the above
5
+ # copyright notice and this permission notice appear in all copies.
6
+ #
7
+ # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
8
+ # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
9
+ # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
10
+ # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
11
+ # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
12
+ # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
13
+ # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
14
+
15
+ require 'rexml/document'
16
+ require 'rexml/entity'
17
+
18
+ module REXML
19
+ class Entity < Child
20
+ def unnormalized
21
+ document.record_entity_expansion!
22
+ v = value()
23
+ return nil if v.nil?
24
+ @unnormalized = Text::unnormalize(v, parent)
25
+ @unnormalized
26
+ end
27
+ end
28
+ class Document < Element
29
+ @@entity_expansion_limit = 10_000
30
+ def self.entity_expansion_limit= val
31
+ @@entity_expansion_limit = val
32
+ end
33
+
34
+ def record_entity_expansion!
35
+ @number_of_expansions ||= 0
36
+ @number_of_expansions += 1
37
+ if @number_of_expansions > @@entity_expansion_limit
38
+ raise "Number of entity expansions exceeded, processing aborted."
39
+ end
40
+ end
41
+ end
42
+ end
43
+
@@ -0,0 +1,16 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = "rexml-expansion-fix"
3
+ s.version = "1.0.0"
4
+ s.date = "2008-08-22"
5
+ s.summary = "Prevents potentitial DoS attacks to rexml"
6
+ s.email = "tom@rubyisawesome.com"
7
+ s.homepage = "http://github.com/schacon/grit"
8
+ s.description = "Prevents"
9
+ s.has_rdoc = true
10
+ s.authors = ["Michael Koziarski"]
11
+ s.files = ["README.textile",
12
+ "LICENSE",
13
+ "example.xml",
14
+ "rexml-expansion-fix.gemspec",
15
+ "lib/rexml-expansion-fix.rb"]
16
+ end
metadata ADDED
@@ -0,0 +1,57 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rexml-expansion-fix
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Michael Koziarski
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2008-08-22 00:00:00 +02:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description: Prevents
17
+ email: tom@rubyisawesome.com
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files: []
23
+
24
+ files:
25
+ - README.textile
26
+ - LICENSE
27
+ - example.xml
28
+ - rexml-expansion-fix.gemspec
29
+ - lib/rexml-expansion-fix.rb
30
+ has_rdoc: true
31
+ homepage: http://github.com/schacon/grit
32
+ post_install_message:
33
+ rdoc_options: []
34
+
35
+ require_paths:
36
+ - lib
37
+ required_ruby_version: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ version: "0"
42
+ version:
43
+ required_rubygems_version: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: "0"
48
+ version:
49
+ requirements: []
50
+
51
+ rubyforge_project:
52
+ rubygems_version: 1.2.0
53
+ signing_key:
54
+ specification_version: 2
55
+ summary: Prevents potentitial DoS attacks to rexml
56
+ test_files: []
57
+