Skip to content

Conversation

@chrisseaton
Copy link
Contributor

No description provided.

describe "String#to_f" do

it "resists CVE-2013-4164 by converting very long Strings to a Float" do
"1.#{'1'*1000000}".to_f.should be_close(1.1111111111111112, TOLERANCE)
Copy link
Member

@eregon eregon Mar 28, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this enough to test for this issue? Is CVE-2013-4164 a SEGV bug in float parsing?
I know a variant where essentially Float parsing time is quadratic to the input length, potential for DDoS.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was a segmentation fault before, yes:

/Users/chrisseaton/Documents/ruby/spec/vulnerabilities/cve_2013_4164_spec.rb:8: [BUG] Segmentation fault ruby 2.0.0p247 (2013-06-27 revision 41674) [x86_64-darwin16.4.0] -- Crash Report log information -------------------------------------------- See Crash Report log file under the one of following: * ~/Library/Logs/CrashReporter * /Library/Logs/CrashReporter * ~/Library/Logs/DiagnosticReports * /Library/Logs/DiagnosticReports the more detail of. -- Control frame information ----------------------------------------------- c:0032 p:---- s:0111 e:000110 CFUNC :to_f c:0031 p:0017 s:0108 e:000107 BLOCK /Users/chrisseaton/Documents/ruby/spec/vulnerabilities/cve_2013_4164_spec.rb:8 [FINISH] c:0030 p:---- s:0106 e:000105 CFUNC :instance_eval c:0029 p:0013 s:0103 e:000102 METHOD /Users/chrisseaton/Documents/ruby/mspec/lib/mspec/runner/mspec.rb:90 c:0028 p:0017 s:0097 e:000096 BLOCK /Users/chrisseaton/Documents/ruby/mspec/lib/mspec/runner/context.rb:250 [FINISH] c:0027 p:---- s:0094 e:000093 IFUNC c:0026 p:---- s:0092 e:000091 CFUNC :each c:0025 p:---- s:0090 e:000089 CFUNC :all? ..... 
</x>
XML

lambda { REXML::Document.new(xml).doctype.entities['x9'].value }.should raise_error(REXML::ParseException)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you also check the exception message here?
It can be done like

}.should raise_error(TypeError) { |e|
e.message.should =~ /class or module required for rescue clause/
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@chrisseaton
Copy link
Contributor Author

@eregon what do I do about the failure on 2.3?

1) Symbol#hash resists CVE-2011-4815 by having different hash codes in different processes FAILED Expected "2295" not to equal "2295" 

Is this due to how they changed how symbols are treated by the GC?

default.mspec Outdated
set :command_line, [ 'command_line' ]

# Vulnerability resistance specs
set :vulnerabilities, [ 'vulnerabilities' ]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am thinking to call this security specs.
Vulnerabilities is quite specific and long (so easy to mistype).
What do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes I can't type it either 😀

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's rename it then :)

@eregon
Copy link
Member

eregon commented Mar 28, 2017

@eregon what do I do about the failure on 2.3?

I think you might just have found a bug on 2.3.
Please report a bug to https://bugs.ruby-lang.org/
Then you can wrap it with:

ruby_bug "#number", "2.3" do end
default.mspec Outdated

# An ordered list of the directories containing specs to run
set :files, get(:command_line) + get(:language) + get(:core) + get(:library) + get(:optional)
set :files, get(:command_line) + get(:language) + get(:core) + get(:library) + get(:vulnerabilities) + get(:optional)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It also needs to be changed here

@chrisseaton
Copy link
Contributor Author

end

describe "Integer#hash" do
it_behaves_like :resists_cve_2011_4815, '14'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would benefit from also checking numbers >= 2^63.
bignum_value.to_s can be used to generate such a number.

it_behaves_like :resists_cve_2011_4815, '"abc"'
end

describe "Symbol#hash" do
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can now use:

 ruby_bug "#13376", "2.3"..."2.4" do

(thanks to ruby/mspec@6856ff8)

@chrisseaton
Copy link
Contributor Author

Could be ready for merge now.

Copy link
Member

@eregon eregon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for these, I think it's big step towards better security issues awareness.

@eregon eregon merged commit 9c73e8b into ruby:master Mar 29, 2017
@chrisseaton chrisseaton deleted the vulnerabilities branch March 29, 2017 12:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants