rails-security-backports 0.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.
- data/.gitignore +34 -0
- data/CHANGELOG.md +10 -0
- data/Gemfile +3 -0
- data/Gemfile.lock +34 -0
- data/LICENSE +22 -0
- data/README.md +15 -0
- data/Rakefile +17 -0
- data/lib/rails-security-backports.rb +11 -0
- data/lib/rails-security-backports/rails-cve-backports/cve-2013-0276.rb +26 -0
- data/lib/rails-security-backports/rails-cve-backports/cve-2013-0277.rb +37 -0
- data/lib/rails-security-backports/ruby-cve-backports/cve-2008-3790.rb +59 -0
- data/lib/rails-security-backports/ruby-cve-backports/cve-2014-8080.rb +45 -0
- data/lib/rails-security-backports/version.rb +18 -0
- data/rails-security-backports.gemspec +45 -0
- data/test/ruby-cve-2008-3790_test.rb +63 -0
- data/test/ruby-cve-2014-8080_test.rb +67 -0
- metadata +119 -0
data/.gitignore
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
/.config
|
4
|
+
/coverage/
|
5
|
+
/InstalledFiles
|
6
|
+
/pkg/
|
7
|
+
/spec/reports/
|
8
|
+
/test/tmp/
|
9
|
+
/test/version_tmp/
|
10
|
+
/tmp/
|
11
|
+
|
12
|
+
## Specific to RubyMotion:
|
13
|
+
.dat*
|
14
|
+
.repl_history
|
15
|
+
build/
|
16
|
+
|
17
|
+
## Documentation cache and generated files:
|
18
|
+
/.yardoc/
|
19
|
+
/_yardoc/
|
20
|
+
/doc/
|
21
|
+
/rdoc/
|
22
|
+
|
23
|
+
## Environment normalisation:
|
24
|
+
/.bundle/
|
25
|
+
/lib/bundler/man/
|
26
|
+
|
27
|
+
# for a library or gem, you might want to ignore these files since the code is
|
28
|
+
# intended to run in multiple environments; otherwise, check them in:
|
29
|
+
# Gemfile.lock
|
30
|
+
.ruby-version
|
31
|
+
.ruby-gemset
|
32
|
+
|
33
|
+
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
|
34
|
+
.rvmrc
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
# Change Log
|
2
|
+
All notable changes to this project will be documented in this file.
|
3
|
+
|
4
|
+
## 0.0.1 - Unreleased
|
5
|
+
### Added
|
6
|
+
- Initial base files (README, CHANGELOG, .gemspec, etc)
|
7
|
+
- Rails: CVE-2013-0276
|
8
|
+
- Rails: CVE-2013-0277
|
9
|
+
- Ruby: CVE-2008-3790
|
10
|
+
- Ruby: CVE-2014-8080
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
rails-security-backports (0.0.1)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
actionmailer (1.3.6)
|
10
|
+
actionpack (= 1.13.6)
|
11
|
+
actionpack (1.13.6)
|
12
|
+
activesupport (= 1.4.4)
|
13
|
+
actionwebservice (1.2.6)
|
14
|
+
actionpack (= 1.13.6)
|
15
|
+
activerecord (= 1.15.6)
|
16
|
+
activerecord (1.15.6)
|
17
|
+
activesupport (= 1.4.4)
|
18
|
+
activesupport (1.4.4)
|
19
|
+
rails (1.2.6)
|
20
|
+
actionmailer (= 1.3.6)
|
21
|
+
actionpack (= 1.13.6)
|
22
|
+
actionwebservice (= 1.2.6)
|
23
|
+
activerecord (= 1.15.6)
|
24
|
+
activesupport (= 1.4.4)
|
25
|
+
rake (>= 0.7.2)
|
26
|
+
rake (0.9.6)
|
27
|
+
|
28
|
+
PLATFORMS
|
29
|
+
ruby
|
30
|
+
|
31
|
+
DEPENDENCIES
|
32
|
+
rails (~> 1.2)
|
33
|
+
rails-security-backports!
|
34
|
+
rake (~> 0.9)
|
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2014 Marcos Wright-Kuhns
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
22
|
+
|
data/README.md
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
# ruby-126-security-backports
|
2
|
+
|
3
|
+
A collection of security-related Ruby & Rails patches backported from fixes in modern Ruby & Rails.
|
4
|
+
|
5
|
+
This code currently specifically targets Rails 1.2.6 & Ruby 1.8.6, but pull requests targeting other versions are also welcomed.
|
6
|
+
|
7
|
+
## Local Development
|
8
|
+
|
9
|
+
Requirements:
|
10
|
+
- Ruby 1.8.6
|
11
|
+
|
12
|
+
````
|
13
|
+
$ gem install bundler --version='1.0.22'
|
14
|
+
$ bundle install
|
15
|
+
````
|
data/Rakefile
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
begin
|
2
|
+
require "bundler/gem_tasks"
|
3
|
+
rescue LoadError
|
4
|
+
puts "Bundler not available. Install it with: gem install bundler"
|
5
|
+
end
|
6
|
+
|
7
|
+
#Dir[File.join(File.dirname(__FILE__), "lib/tasks/*.rake")].sort.each { |ext| load ext }
|
8
|
+
|
9
|
+
require 'rake/testtask'
|
10
|
+
|
11
|
+
Rake::TestTask.new do |t|
|
12
|
+
t.libs << "test"
|
13
|
+
t.test_files = FileList['test/*_test.rb']
|
14
|
+
t.verbose = true
|
15
|
+
end
|
16
|
+
|
17
|
+
task :default => :test
|
@@ -0,0 +1,11 @@
|
|
1
|
+
$:.unshift File.dirname(__FILE__)
|
2
|
+
|
3
|
+
require 'rails-security-backports/version'
|
4
|
+
|
5
|
+
require 'active_record'
|
6
|
+
|
7
|
+
require 'rails-security-backports/rails-cve-backports/cve-2013-0276.rb'
|
8
|
+
require 'rails-security-backports/rails-cve-backports/cve-2013-0277.rb'
|
9
|
+
|
10
|
+
require 'rails-security-backports/ruby-cve-backports/cve-2008-3790.rb'
|
11
|
+
require 'rails-security-backports/ruby-cve-backports/cve-2014-8080.rb'
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module ActiveRecord
|
2
|
+
module CVE20130276
|
3
|
+
module ClassMethods
|
4
|
+
private
|
5
|
+
# Suffixes a, ?, c become regexp /(a|\?|c)$/
|
6
|
+
def rebuild_attribute_method_regexp
|
7
|
+
suffixes = attribute_method_suffixes.map { |s| Regexp.escape(s) }
|
8
|
+
@@attribute_method_regexp = /(#{suffixes.join('|')})\z/.freeze
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
module Base
|
13
|
+
def remove_attributes_protected_from_mass_assignment(attributes)
|
14
|
+
if self.class.accessible_attributes.nil? && self.class.protected_attributes.nil?
|
15
|
+
attributes.reject { |key, value| attributes_protected_by_default.include?(key.gsub(/\(.+/m, "")) }
|
16
|
+
elsif self.class.protected_attributes.nil?
|
17
|
+
attributes.reject { |key, value| !self.class.accessible_attributes.include?(key.gsub(/\(.+/m, "").intern) || attributes_protected_by_default.include?(key.gsub(/\(.+/m, "")) }
|
18
|
+
elsif self.class.accessible_attributes.nil?
|
19
|
+
attributes.reject { |key, value| self.class.protected_attributes.include?(key.gsub(/\(.+/m,"").intern) || attributes_protected_by_default.include?(key.gsub(/\(.+/m, "")) }
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
ActiveRecord::Base.extend( ActiveRecord::CVE20130276::ClassMethods)
|
26
|
+
ActiveRecord::Base.send(:include, ActiveRecord::CVE20130276::Base)
|
@@ -0,0 +1,37 @@
|
|
1
|
+
module ActiveRecord
|
2
|
+
class Base
|
3
|
+
private
|
4
|
+
def write_attribute(attr_name, value)
|
5
|
+
attr_name = attr_name.to_s
|
6
|
+
if (column = column_for_attribute(attr_name)) && column.number?
|
7
|
+
@attributes[attr_name] = convert_number_column_value(value)
|
8
|
+
else
|
9
|
+
if self.class.serialized_attributes[attr_name] && value.is_a?(String) && value =~ /^---/
|
10
|
+
raise ActiveRecordError, "You tried to assign already serialized content to #{attr_name}. This is disabled due to security issues."
|
11
|
+
end
|
12
|
+
@attributes[attr_name] = value
|
13
|
+
end
|
14
|
+
end
|
15
|
+
# For comparison, this is the original write_attribue from rails 1.2.6
|
16
|
+
# def write_attribute(attr_name, value)
|
17
|
+
# attr_name = attr_name.to_s
|
18
|
+
# if (column = column_for_attribute(attr_name)) && column.number?
|
19
|
+
# @attributes[attr_name] = convert_number_column_value(value)
|
20
|
+
# else
|
21
|
+
# @attributes[attr_name] = value
|
22
|
+
# end
|
23
|
+
# end
|
24
|
+
# For comparison this is the patch from rails 2.3
|
25
|
+
# def define_write_method_for_serialized_attribute(attr_name)
|
26
|
+
# method_body = <<-EOV
|
27
|
+
# def #{attr_name}=(value)
|
28
|
+
# if value.is_a?(String) and value =~ /^---/
|
29
|
+
# raise ActiveRecordError, "You tried to assign already serialized content to #{attr_name}. This is disabled due to security issues."
|
30
|
+
# end
|
31
|
+
# write_attribute(:#{attr_name}, value)
|
32
|
+
# end
|
33
|
+
# EOV
|
34
|
+
# evaluate_attribute_method attr_name, method_body, "#{attr_name}="
|
35
|
+
# end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
# Fixes CVE-2008-3790 - https://www.ruby-lang.org/en/news/2008/08/23/dos-vulnerability-in-rexml/
|
2
|
+
# Originally based on https://github.com/NZKoz/rexml-expansion-fix
|
3
|
+
|
4
|
+
# Copyright (c) 2008 Michael Koziarski <michael@koziarski.com>
|
5
|
+
#
|
6
|
+
# Permission to use, copy, modify, and/or distribute this software for any
|
7
|
+
# purpose with or without fee is hereby granted, provided that the above
|
8
|
+
# copyright notice and this permission notice appear in all copies.
|
9
|
+
#
|
10
|
+
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
11
|
+
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
12
|
+
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
13
|
+
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
14
|
+
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
15
|
+
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
16
|
+
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
17
|
+
require 'rexml/document'
|
18
|
+
require 'rexml/entity'
|
19
|
+
module REXML
|
20
|
+
class Entity < Child
|
21
|
+
def unnormalized
|
22
|
+
# Due to an optimisation in REXML, the default entities aren't
|
23
|
+
# associated with a document. As these enties are defined and
|
24
|
+
# not recursive, we know that expanding them won't cause any
|
25
|
+
# issues. Other entities in the document will still have
|
26
|
+
# the association to the document preventing this from opening
|
27
|
+
# a new attack vector.
|
28
|
+
document.record_entity_expansion! if document
|
29
|
+
v = value()
|
30
|
+
return nil if v.nil?
|
31
|
+
@unnormalized = Text::unnormalize(v, parent)
|
32
|
+
@unnormalized
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
class Document < Element
|
37
|
+
def record_entity_expansion!
|
38
|
+
@number_of_expansions ||= 0
|
39
|
+
@number_of_expansions += 1
|
40
|
+
if @number_of_expansions > Security.entity_expansion_limit
|
41
|
+
raise "Processing aborted: number of entity expansions (#{@number_of_expansions}) exceeded the limit (#{Security.entity_expansion_limit})."
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
class Security
|
47
|
+
@@entity_expansion_limit = 10_000
|
48
|
+
|
49
|
+
# Set the entity expansion limit. By default the limit is set to 10000.
|
50
|
+
def self.entity_expansion_limit=( val )
|
51
|
+
@@entity_expansion_limit = val
|
52
|
+
end
|
53
|
+
|
54
|
+
# Get the entity expansion limit. By default the limit is set to 10000.
|
55
|
+
def self.entity_expansion_limit
|
56
|
+
return @@entity_expansion_limit
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
# Fixes CVE-2014-8080 - https://www.ruby-lang.org/en/news/2014/10/27/rexml-dos-cve-2014-8080/
|
2
|
+
|
3
|
+
require 'rexml/document'
|
4
|
+
require 'rexml/entity'
|
5
|
+
|
6
|
+
module REXML
|
7
|
+
class Entity
|
8
|
+
|
9
|
+
def value
|
10
|
+
if @value
|
11
|
+
matches = @value.scan(PEREFERENCE_RE)
|
12
|
+
rv = @value.clone
|
13
|
+
if @parent
|
14
|
+
sum = 0
|
15
|
+
matches.each do |entity_reference|
|
16
|
+
entity_value = @parent.entity( entity_reference[0] )
|
17
|
+
if sum + entity_value.size > Security.entity_expansion_text_limit
|
18
|
+
raise "Processing aborted: entity expansion (#{sum + entity_value.size}) exceeded our limit (#{Security.entity_expansion_text_limit})."
|
19
|
+
else
|
20
|
+
sum += entity_value.size
|
21
|
+
end
|
22
|
+
rv.gsub!( /%#{entity_reference};/um, entity_value )
|
23
|
+
end
|
24
|
+
end
|
25
|
+
return rv
|
26
|
+
end
|
27
|
+
nil
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
|
32
|
+
class Security
|
33
|
+
@@entity_expansion_text_limit = 10_240
|
34
|
+
|
35
|
+
# Set the entity expansion limit. By default the limit is set to 10240.
|
36
|
+
def self.entity_expansion_text_limit=( val )
|
37
|
+
@@entity_expansion_text_limit = val
|
38
|
+
end
|
39
|
+
|
40
|
+
# Get the entity expansion limit. By default the limit is set to 10240.
|
41
|
+
def self.entity_expansion_text_limit
|
42
|
+
return @@entity_expansion_text_limit
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module RailsSecurityBackports
|
2
|
+
class Version
|
3
|
+
MAJOR = 0
|
4
|
+
MINOR = 0
|
5
|
+
PATCH = 1
|
6
|
+
STRING = "#{MAJOR}.#{MINOR}.#{PATCH}"
|
7
|
+
|
8
|
+
class << self
|
9
|
+
# A String representing the current version of this gem.
|
10
|
+
def inspect
|
11
|
+
STRING
|
12
|
+
end
|
13
|
+
alias_method :to_s, :inspect
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
VERSION = Version::STRING
|
18
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
lib = File.expand_path('../lib/', __FILE__)
|
4
|
+
$:.unshift lib unless $:.include?(lib)
|
5
|
+
|
6
|
+
require 'rails-security-backports/version'
|
7
|
+
|
8
|
+
Gem::Specification.new do |s|
|
9
|
+
s.name = "rails-security-backports"
|
10
|
+
s.version = RailsSecurityBackports::Version.to_s
|
11
|
+
|
12
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
13
|
+
s.authors = ["Marcos Wright Kuhns"]
|
14
|
+
s.date = "2014-11-03"
|
15
|
+
s.description = "A collection of security-related Ruby & Rails patches backported from fixes in modern Ruby & Rails."
|
16
|
+
s.email = "marcos@wrightkuhns.com"
|
17
|
+
s.homepage = "https://github.com/metavida/rails-security-backports"
|
18
|
+
s.licenses = ["MIT"]
|
19
|
+
|
20
|
+
s.files = `git ls-files`.split("\n")
|
21
|
+
s.test_files = s.files.grep(%r{^(test|spec|features,integration_test)/})
|
22
|
+
|
23
|
+
s.rdoc_options = ["--main", "README.rdoc", "--title", "rails-security-backports-#{RailsSecurityBackports::Version}", "--inline-source", "--exclude", "tasks", "CHANGELOG.md"]
|
24
|
+
s.extra_rdoc_files = s.files.grep(%r{\.rdoc$}) + %w{LICENSE}
|
25
|
+
|
26
|
+
s.require_paths = ["lib"]
|
27
|
+
s.rubygems_version = "1.8.19"
|
28
|
+
s.summary = "Backports of security patches for Ruby & Rails"
|
29
|
+
|
30
|
+
if s.respond_to? :specification_version then
|
31
|
+
s.specification_version = 3
|
32
|
+
|
33
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
34
|
+
s.add_development_dependency(%q<rake>, ["~> 0.9"])
|
35
|
+
s.add_development_dependency(%q<rails>, ["~> 1.2"])
|
36
|
+
else
|
37
|
+
s.add_dependency(%q<rake>, ["~> 0.9"])
|
38
|
+
s.add_dependency(%q<rails>, ["~> 1.2"])
|
39
|
+
end
|
40
|
+
else
|
41
|
+
s.add_dependency(%q<rake>, ["~> 0.9"])
|
42
|
+
s.add_dependency(%q<rails>, ["~> 1.2"])
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
@@ -0,0 +1,63 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require 'rails-security-backports'
|
3
|
+
|
4
|
+
class RubyCve_2008_3790Test < Test::Unit::TestCase
|
5
|
+
|
6
|
+
def setup
|
7
|
+
@orig_limit = REXML::Security.entity_expansion_limit
|
8
|
+
end
|
9
|
+
|
10
|
+
def teardown
|
11
|
+
REXML::Security.entity_expansion_limit = @orig_limit
|
12
|
+
end
|
13
|
+
|
14
|
+
|
15
|
+
def test__record_entity_expansion__with_small_num_expansions
|
16
|
+
REXML::Security.entity_expansion_limit = 50
|
17
|
+
|
18
|
+
xml = get_expandable_xml_that_expands_to(REXML::Security.entity_expansion_limit)
|
19
|
+
|
20
|
+
assert_nothing_raised(RuntimeError, "Expected NO exception with xml:\n#{xml}") do
|
21
|
+
REXML::Document.new(xml).root.text
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def test__record_entity_expansion__with_too_many_expansions
|
26
|
+
REXML::Security.entity_expansion_limit = 50
|
27
|
+
|
28
|
+
xml = get_expandable_xml_that_expands_to(REXML::Security.entity_expansion_limit + 1000)
|
29
|
+
|
30
|
+
assert_raise(RuntimeError, "Expected exception with xml:\n#{xml}") do
|
31
|
+
REXML::Document.new(xml).root.text
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
private
|
36
|
+
|
37
|
+
def get_expandable_xml_that_expands_to(num_expansions_required = 51)
|
38
|
+
expansion_keys = %w{a b}
|
39
|
+
expansion_text = "x"*10
|
40
|
+
|
41
|
+
expansions_per_key = Math.sqrt(num_expansions_required).floor - 1
|
42
|
+
num_expansions_expected = expansions_per_key ** 2
|
43
|
+
num_expansions_expected += 1 + expansions_per_key
|
44
|
+
|
45
|
+
non_exponential_expansions = num_expansions_required - 1 - num_expansions_expected
|
46
|
+
|
47
|
+
<<-XML
|
48
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
49
|
+
<!DOCTYPE member [
|
50
|
+
<!ENTITY a "#{'&b;'*expansions_per_key}">
|
51
|
+
<!ENTITY b "#{'&x;'*expansions_per_key}">
|
52
|
+
<!ENTITY x "#{expansion_text}">
|
53
|
+
<!ENTITY c "#{'&y;'*non_exponential_expansions}">
|
54
|
+
<!ENTITY y "#{expansion_text}">
|
55
|
+
]>
|
56
|
+
<member>
|
57
|
+
&a;
|
58
|
+
&c;
|
59
|
+
</member>
|
60
|
+
XML
|
61
|
+
end
|
62
|
+
|
63
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require 'rails-security-backports'
|
3
|
+
|
4
|
+
class RubyCve_2014_8080Test < Test::Unit::TestCase
|
5
|
+
|
6
|
+
def setup
|
7
|
+
@orig_limit = REXML::Security.entity_expansion_text_limit
|
8
|
+
end
|
9
|
+
|
10
|
+
def teardown
|
11
|
+
REXML::Security.entity_expansion_text_limit = @orig_limit
|
12
|
+
end
|
13
|
+
|
14
|
+
def test__record_entity_expansion__with_small_num_text_expansions
|
15
|
+
REXML::Security.entity_expansion_text_limit = 50
|
16
|
+
|
17
|
+
xml = get_expandable_xml_that_expands_to(:less_than=>REXML::Security.entity_expansion_text_limit)
|
18
|
+
|
19
|
+
assert_nothing_raised(REXML::ParseException, "Expected NO exception with xml:\n#{xml}") do
|
20
|
+
REXML::Document.new(xml).root.text
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def test__record_entity_expansion__with_too_many_text_expansions
|
25
|
+
REXML::Security.entity_expansion_text_limit = 50
|
26
|
+
|
27
|
+
xml = get_expandable_xml_that_expands_to(:more_than=>REXML::Security.entity_expansion_text_limit)
|
28
|
+
|
29
|
+
assert_raise(REXML::ParseException, "Expected exception with xml:\n#{xml}") do
|
30
|
+
REXML::Document.new(xml).root.text
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
private
|
35
|
+
|
36
|
+
def get_expandable_xml_that_expands_to(opts = {})
|
37
|
+
more_or_less = nil
|
38
|
+
num_text_expansions_required = if opts.has_key?(:less_than)
|
39
|
+
more_or_less = :less
|
40
|
+
opts[:less_than].to_i
|
41
|
+
elsif opts.has_key?(:more_than)
|
42
|
+
more_or_less = :more
|
43
|
+
opts[:more_than].to_i
|
44
|
+
else
|
45
|
+
raise ArgumentError.new("Argument must be either `:less_than=>x` or `:more_than=>x`, but was #{opts.inspect}")
|
46
|
+
end
|
47
|
+
|
48
|
+
expansion_keys = %w{a b}
|
49
|
+
expansion_text = "x"*1
|
50
|
+
|
51
|
+
expansions_per_key = Math.sqrt(num_text_expansions_required)
|
52
|
+
expansions_per_key = more_or_less == :more ? expansions_per_key.ceil : expansions_per_key.floor
|
53
|
+
|
54
|
+
<<-XML
|
55
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
56
|
+
<!DOCTYPE member [
|
57
|
+
<!ENTITY a "#{'%b;'*expansions_per_key}">
|
58
|
+
<!ENTITY % b "#{'%x;'*expansions_per_key}">
|
59
|
+
<!ENTITY % x "#{expansion_text}">
|
60
|
+
]>
|
61
|
+
<member>
|
62
|
+
&a;
|
63
|
+
</member>
|
64
|
+
XML
|
65
|
+
end
|
66
|
+
|
67
|
+
end
|
metadata
ADDED
@@ -0,0 +1,119 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rails-security-backports
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 29
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 1
|
10
|
+
version: 0.0.1
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Marcos Wright Kuhns
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2014-11-03 00:00:00 -08:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: rake
|
23
|
+
version_requirements: &id001 !ruby/object:Gem::Requirement
|
24
|
+
none: false
|
25
|
+
requirements:
|
26
|
+
- - ~>
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
hash: 25
|
29
|
+
segments:
|
30
|
+
- 0
|
31
|
+
- 9
|
32
|
+
version: "0.9"
|
33
|
+
prerelease: false
|
34
|
+
type: :development
|
35
|
+
requirement: *id001
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: rails
|
38
|
+
version_requirements: &id002 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ~>
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
hash: 11
|
44
|
+
segments:
|
45
|
+
- 1
|
46
|
+
- 2
|
47
|
+
version: "1.2"
|
48
|
+
prerelease: false
|
49
|
+
type: :development
|
50
|
+
requirement: *id002
|
51
|
+
description: A collection of security-related Ruby & Rails patches backported from fixes in modern Ruby & Rails.
|
52
|
+
email: marcos@wrightkuhns.com
|
53
|
+
executables: []
|
54
|
+
|
55
|
+
extensions: []
|
56
|
+
|
57
|
+
extra_rdoc_files:
|
58
|
+
- LICENSE
|
59
|
+
files:
|
60
|
+
- .gitignore
|
61
|
+
- CHANGELOG.md
|
62
|
+
- Gemfile
|
63
|
+
- Gemfile.lock
|
64
|
+
- LICENSE
|
65
|
+
- README.md
|
66
|
+
- Rakefile
|
67
|
+
- lib/rails-security-backports.rb
|
68
|
+
- lib/rails-security-backports/rails-cve-backports/cve-2013-0276.rb
|
69
|
+
- lib/rails-security-backports/rails-cve-backports/cve-2013-0277.rb
|
70
|
+
- lib/rails-security-backports/ruby-cve-backports/cve-2008-3790.rb
|
71
|
+
- lib/rails-security-backports/ruby-cve-backports/cve-2014-8080.rb
|
72
|
+
- lib/rails-security-backports/version.rb
|
73
|
+
- rails-security-backports.gemspec
|
74
|
+
- test/ruby-cve-2008-3790_test.rb
|
75
|
+
- test/ruby-cve-2014-8080_test.rb
|
76
|
+
has_rdoc: true
|
77
|
+
homepage: https://github.com/metavida/rails-security-backports
|
78
|
+
licenses:
|
79
|
+
- MIT
|
80
|
+
post_install_message:
|
81
|
+
rdoc_options:
|
82
|
+
- --main
|
83
|
+
- README.rdoc
|
84
|
+
- --title
|
85
|
+
- rails-security-backports-0.0.1
|
86
|
+
- --inline-source
|
87
|
+
- --exclude
|
88
|
+
- tasks
|
89
|
+
- CHANGELOG.md
|
90
|
+
require_paths:
|
91
|
+
- lib
|
92
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
93
|
+
none: false
|
94
|
+
requirements:
|
95
|
+
- - ">="
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
hash: 3
|
98
|
+
segments:
|
99
|
+
- 0
|
100
|
+
version: "0"
|
101
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
102
|
+
none: false
|
103
|
+
requirements:
|
104
|
+
- - ">="
|
105
|
+
- !ruby/object:Gem::Version
|
106
|
+
hash: 3
|
107
|
+
segments:
|
108
|
+
- 0
|
109
|
+
version: "0"
|
110
|
+
requirements: []
|
111
|
+
|
112
|
+
rubyforge_project:
|
113
|
+
rubygems_version: 1.4.2
|
114
|
+
signing_key:
|
115
|
+
specification_version: 3
|
116
|
+
summary: Backports of security patches for Ruby & Rails
|
117
|
+
test_files:
|
118
|
+
- test/ruby-cve-2008-3790_test.rb
|
119
|
+
- test/ruby-cve-2014-8080_test.rb
|