Skip to content

Commit

Permalink
Allow for ignoring insecure sources.
Browse files Browse the repository at this point in the history
Ignoring internal sources is already supported with a fixed IP
whitelist, but this doesn't support cases where an internal source
doesn't fall within those IPs blocks. This change allows specific
hostnames to be ignored.
  • Loading branch information
Daniel O'Brien committed Mar 1, 2018
1 parent b84d88f commit cb7e5b3
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 6 deletions.
7 changes: 5 additions & 2 deletions lib/bundler/audit/scanner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -99,18 +99,21 @@ def scan(options={},&block)
def scan_sources(options={})
return enum_for(__method__,options) unless block_given?

ignore = Set[]
ignore += options[:ignore] if options[:ignore]

@lockfile.sources.map do |source|
case source
when Source::Git
case source.uri
when /^git:/, /^http:/
unless internal_source?(source.uri)
unless internal_source?(source.uri) || ignore.include?(source.uri)
yield InsecureSource.new(source.uri)
end
end
when Source::Rubygems
source.remotes.each do |uri|
if (uri.scheme == 'http' && !internal_source?(uri))
if (uri.scheme == 'http' && !internal_source?(uri)) && !ignore.include?(uri.to_s)
yield InsecureSource.new(uri.to_s)
end
end
Expand Down
5 changes: 2 additions & 3 deletions spec/bundle/insecure_sources/Gemfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
source 'http://rubygems.org'

gem 'rails', '3.2.12'
gem 'rails', '~> 4.2.7.1'

# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'
Expand All @@ -20,8 +20,7 @@ group :assets do
# gem 'uglifier', '>= 1.0.3'
end

gem 'jquery-rails', :git => 'git://github.com/rails/jquery-rails.git',
:tag => 'v2.2.1'
gem 'jquery-rails', :git => 'git://github.com/rails/jquery-rails.git'

# To use ActiveModel has_secure_password
# gem 'bcrypt-ruby', '~> 3.0.0'
Expand Down
10 changes: 9 additions & 1 deletion spec/scanner_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@

it "should ignore the specified advisories" do
ids = subject.map { |result| result.advisory.id }

expect(ids).not_to include('OSVDB-89026')
end
end
Expand All @@ -58,6 +58,14 @@
expect(subject[0].source).to eq('git://github.com/rails/jquery-rails.git')
expect(subject[1].source).to eq('http://rubygems.org/')
end

context "when ignoring insecure sources" do
subject { scanner.scan(:ignore => ['http://rubygems.org/', 'git://github.com/rails/jquery-rails.git']).to_a }

it "should print nothing when otherwise fine" do
expect(subject).to be_empty
end
end
end

context "when auditing a secure bundle" do
Expand Down

0 comments on commit cb7e5b3

Please sign in to comment.