Skip to content

Commit 0146c69

Browse files
committed
Merge pull request #21 from codeclimate/devon/support-alphanumeric-gem-versions
Support alphanumeric ruby gem versions
2 parents 16ffa52 + 316f909 commit 0146c69

File tree

6 files changed

+86
-3
lines changed

6 files changed

+86
-3
lines changed

lib/cc/engine/bundler_audit/unpatched_gem_issue.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ module CC
22
module Engine
33
module BundlerAudit
44
class UnpatchedGemIssue
5-
GEM_REGEX = /^\s*(?<name>\S+) \([\d.]+\)/
5+
GEM_REGEX = /^\s*(?<name>\S+) \([\S.]+\)/
66
SEVERITIES = {
77
high: "critical",
88
medium: "normal",

lib/cc/engine/bundler_audit/unpatched_gem_remediation.rb

+9-2
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,21 @@ def calculate_points(upgrade_version)
3939
end
4040

4141
def current_version
42-
@current_version ||= Versionomy.parse(gem_version.to_s)
42+
@current_version ||= parse_version(gem_version.to_s)
4343
end
4444

4545
def upgrade_versions
4646
@upgrade_versions ||= patched_versions.map do |version|
47-
Versionomy.parse(version.to_s)
47+
parse_version(version)
4848
end
4949
end
50+
51+
def parse_version(version)
52+
Versionomy.parse(version.to_s)
53+
rescue Versionomy::Errors::ParseError
54+
version = Versionomy.parse(version.to_s, :rubygems)
55+
Versionomy.create(major: version.field0, minor: version.field1, tiny: version.field2)
56+
end
5057
end
5158
end
5259
end

spec/cc/engine/bundler_audit/analyzer_spec.rb

+10
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,16 @@ module CC::Engine::BundlerAudit
3030
end
3131
end
3232

33+
it "Supports alphanumeric gem versions like 3.0.0.rc.2 or 2.2.2.backport2" do
34+
directory = fixture_directory("alphanumeric_versions")
35+
36+
issues = analyze_directory(directory)
37+
38+
expected_issues("alphanumeric_versions").each do |expected_issue|
39+
expect(issues).to include(expected_issue)
40+
end
41+
end
42+
3343
it "logs to stderr when we encounter an unsupported vulnerability" do
3444
directory = fixture_directory("unpatched_versions")
3545
stderr = StringIO.new
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
source "https://rubygems.org"
2+
3+
gem "sprockets", "2.2.2.backport2"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
GEM
2+
remote: http://rubygems.org/
3+
specs:
4+
hike (1.2.3)
5+
multi_json (1.11.2)
6+
rack (1.4.7)
7+
sprockets (2.2.2.backport2)
8+
hike (~> 1.2)
9+
multi_json (~> 1.0)
10+
rack (~> 1.0)
11+
tilt (~> 1.1, != 1.3.0)
12+
tilt (1.4.1)
13+
14+
PLATFORMS
15+
ruby
16+
17+
DEPENDENCIES
18+
sprockets (= 2.2.2.backport2)
19+
20+
BUNDLED WITH
21+
1.11.2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
[
2+
{
3+
"categories": [
4+
"Security"
5+
],
6+
"check_name": "Insecure Source",
7+
"content": {
8+
"body": ""
9+
},
10+
"description": "Insecure Source URI found: http://rubygems.org/",
11+
"location": {
12+
"lines": {
13+
"begin": 2,
14+
"end": 2
15+
},
16+
"path": "Gemfile.lock"
17+
},
18+
"remediation_points": 5000000,
19+
"severity": "normal",
20+
"type": "Issue"
21+
},
22+
{
23+
"categories": [
24+
"Security"
25+
],
26+
"check_name": "Insecure Dependency",
27+
"content": {
28+
"body": "**Advisory**: CVE-2014-7819\n\n**Criticality**: Medium\n\n**URL**: https://groups.google.com/forum/#!topic/rubyonrails-security/doAVp0YaTqY\n\n**Solution**: upgrade to ~> 2.0.5, ~> 2.1.4, ~> 2.2.3, ~> 2.3.3, ~> 2.4.6, ~> 2.5.1, ~> 2.7.1, ~> 2.8.3, ~> 2.9.4, ~> 2.10.2, ~> 2.11.3, ~> 2.12.3, >= 3.0.0.beta.3"
29+
},
30+
"description": "Arbitrary file existence disclosure in Sprockets",
31+
"location": {
32+
"lines": {
33+
"begin": 7,
34+
"end": 7
35+
},
36+
"path": "Gemfile.lock"
37+
},
38+
"remediation_points": 500000,
39+
"severity": "normal",
40+
"type": "Issue"
41+
}
42+
]

0 commit comments

Comments
 (0)