bundler-advise 1.0.0
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.
- checksums.yaml +7 -0
- data/.gitignore +10 -0
- data/.rspec +3 -0
- data/.ruby-version +1 -0
- data/.travis.yml +4 -0
- data/Gemfile +4 -0
- data/LICENSE +21 -0
- data/README.md +62 -0
- data/Rakefile +6 -0
- data/bin/console +10 -0
- data/bin/setup +7 -0
- data/bundler-advise.gemspec +28 -0
- data/lib/bundler/advise/advisories.rb +44 -0
- data/lib/bundler/advise/advisory.rb +51 -0
- data/lib/bundler/advise/gem_adviser.rb +23 -0
- data/lib/bundler/advise/version.rb +5 -0
- data/lib/bundler/advise.rb +5 -0
- metadata +130 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 87d25bc27eacc044d69d52b6fcf8d083368e9844
|
4
|
+
data.tar.gz: 8646a541b6fdfd2dcb885ed5022be618dba86d1f
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: becf54f63bde517c9b5219167efb76b19317e232e94de7ce608a4c8e60f464bd19d8469909faab75f95defe128f2fd66ed16cb351265740a830fd46ecaab5e4c
|
7
|
+
data.tar.gz: 750a49c7cb0f56c14a76fb85f16fe46e682760f19f578b832704074b248f91515201927c4ea5595e60c75ce0fdd0482b1c8e0f7100e3e675cfbd4b9d5412dc6e
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.2.4
|
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 cLabs, Inc.
|
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.
|
data/README.md
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
# Bundler::Advise
|
2
|
+
|
3
|
+
Scans a Gemfile looking for known vulnerable gems.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'bundler-advise'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install bundler-advise
|
20
|
+
|
21
|
+
## Goal
|
22
|
+
|
23
|
+
The intent of this gem is to provide a library alternate to `bundler-audit` with an MIT license. The intent of
|
24
|
+
`bundler-audit` is to be a [standalone utility](https://github.com/rubysec/bundler-audit/issues/9),
|
25
|
+
`bundler-advise` can be integrated into other codebases without concerns over GPLv3 licensing.
|
26
|
+
|
27
|
+
Both tools fetch and parse the contents of the [ruby-advisory-db](rubysec/ruby-advisory-db.git). `bundle-advise`
|
28
|
+
has no CLI, does not scan for insecure sources, but does support custom advisory databases that match the interface
|
29
|
+
of the data in ruby-advisory-db, for organizations that want to maintain an internal database for private gems.
|
30
|
+
|
31
|
+
## Usage
|
32
|
+
|
33
|
+
```ruby
|
34
|
+
require 'bundler/advise'
|
35
|
+
|
36
|
+
# Presuming the default ruby-advisory-db on github.com and Dir.pwd is set to
|
37
|
+
# project root, containing the project's Gemfile.lock
|
38
|
+
advisories = Bundler::Advise::GemAdviser.new.scan_lockfile
|
39
|
+
|
40
|
+
# To change the directory:
|
41
|
+
advisories = Bundler::Advise::GemAdviser.new(dir: other_project_dir).scan_lockfile
|
42
|
+
|
43
|
+
# To use a custom advisory db:
|
44
|
+
db = Bundler::Advise::Advisories.new(dir: my_custom_db_path, repo: custom_git_url)
|
45
|
+
advisories = Bundler::Advise::GemAdviser.new(advisories: db).scan_lockfile
|
46
|
+
```
|
47
|
+
|
48
|
+
## Development
|
49
|
+
|
50
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
51
|
+
|
52
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
53
|
+
|
54
|
+
## Contributing
|
55
|
+
|
56
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/chrismo/bundler-advise.
|
57
|
+
|
58
|
+
|
59
|
+
## License
|
60
|
+
|
61
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
62
|
+
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "bundler/advise"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
require "pry"
|
10
|
+
Pry.start
|
data/bin/setup
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'bundler/advise/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'bundler-advise'
|
8
|
+
spec.version = Bundler::Advise::VERSION
|
9
|
+
spec.authors = ['chrismo']
|
10
|
+
spec.email = ['chrismo@clabs.org']
|
11
|
+
|
12
|
+
spec.summary = %q{Scans Gemfile for known vulnerable gems.}
|
13
|
+
# spec.description = %q{TODO: Write a longer description or delete this line.}
|
14
|
+
spec.homepage = 'https://github.com/chrismo/bundler-advise'
|
15
|
+
spec.license = 'MIT'
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
18
|
+
spec.bindir = 'exe'
|
19
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
|
+
spec.require_paths = ['lib']
|
21
|
+
|
22
|
+
spec.add_dependency 'git'
|
23
|
+
spec.add_dependency 'bundler', '~> 1.10'
|
24
|
+
|
25
|
+
spec.add_development_dependency 'pry'
|
26
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
27
|
+
spec.add_development_dependency 'rspec'
|
28
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'git'
|
2
|
+
|
3
|
+
module Bundler::Advise
|
4
|
+
class Advisories
|
5
|
+
attr_reader :dir, :repo
|
6
|
+
|
7
|
+
def initialize(dir: File.expand_path('~/.ruby-advisory-db'),
|
8
|
+
repo: 'git@github.com:rubysec/ruby-advisory-db.git')
|
9
|
+
@dir = dir
|
10
|
+
@repo = repo
|
11
|
+
end
|
12
|
+
|
13
|
+
def update
|
14
|
+
File.exist?(@dir) ? pull : clone
|
15
|
+
rescue ArgumentError => e
|
16
|
+
# git gem is dorky in this case, putting the path into the backtrace.
|
17
|
+
msg = "Unexpected problem with working dir for advisories: #{e.message} #{e.backtrace}.\n" +
|
18
|
+
"Call clean_update! to remove #{@dir} and re-clone it."
|
19
|
+
raise RuntimeError, msg
|
20
|
+
end
|
21
|
+
|
22
|
+
def clean_update!
|
23
|
+
FileUtils.rmtree @dir
|
24
|
+
update
|
25
|
+
end
|
26
|
+
|
27
|
+
def gem_advisories_for(gem_name)
|
28
|
+
Dir[File.join(@dir, 'gems', gem_name, '*.yml')].map do |ad_yml|
|
29
|
+
Advisory.from_yml(ad_yml)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
private
|
34
|
+
|
35
|
+
def clone
|
36
|
+
Git.clone(@repo, @dir)
|
37
|
+
end
|
38
|
+
|
39
|
+
def pull
|
40
|
+
git = Git.open(@dir)
|
41
|
+
git.pull
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
|
3
|
+
module Bundler::Advise
|
4
|
+
class Advisory
|
5
|
+
def self.from_yml(yml_filename)
|
6
|
+
id = File.basename(yml_filename, '.yml')
|
7
|
+
new(YAML.load(File.read(yml_filename)).tap { |h| h[:id] = id })
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.fields
|
11
|
+
[:gem, :cve, :cvss_v2, :date, :description, :framework, :osvdb, :patched_versions,
|
12
|
+
:platform, :related, :title, :unaffected_versions, :url, :vendor_patch]
|
13
|
+
end
|
14
|
+
|
15
|
+
attr_reader *self.fields, :id
|
16
|
+
|
17
|
+
def initialize(fields={})
|
18
|
+
fields.each do |k, v|
|
19
|
+
instance_variable_set("@#{k}", v)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def to_yaml
|
24
|
+
self.class.fields.reduce({}) { |h, f| v = instance_variable_get("@#{f}"); h[f.to_s] = v if v; h }.to_yaml
|
25
|
+
end
|
26
|
+
|
27
|
+
def unaffected_versions
|
28
|
+
Array(@unaffected_versions).map { |v| Gem::Requirement.create(v) }
|
29
|
+
end
|
30
|
+
|
31
|
+
def patched_versions
|
32
|
+
Array(@patched_versions).map { |v| Gem::Requirement.create(v) }
|
33
|
+
end
|
34
|
+
|
35
|
+
def is_affected?(gem_version)
|
36
|
+
is_not_patched?(gem_version) && is_not_unaffected?(gem_version)
|
37
|
+
end
|
38
|
+
|
39
|
+
def is_not_patched?(gem_version)
|
40
|
+
patched_versions.detect do |pv|
|
41
|
+
pv.satisfied_by?(Gem::Version.create(gem_version))
|
42
|
+
end.nil?
|
43
|
+
end
|
44
|
+
|
45
|
+
def is_not_unaffected?(gem_version)
|
46
|
+
unaffected_versions.detect do |pv|
|
47
|
+
pv.satisfied_by?(Gem::Version.create(gem_version))
|
48
|
+
end.nil?
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'bundler/lockfile_parser'
|
2
|
+
|
3
|
+
module Bundler::Advise
|
4
|
+
class GemAdviser
|
5
|
+
def initialize(advisories: Advisories.new, dir: Dir.pwd)
|
6
|
+
@advisories = advisories
|
7
|
+
@dir = dir
|
8
|
+
scan_lockfile
|
9
|
+
end
|
10
|
+
|
11
|
+
def scan_lockfile
|
12
|
+
lockfile = nil
|
13
|
+
Dir.chdir(@dir) do
|
14
|
+
lockfile = Bundler::LockfileParser.new(Bundler.read_file('Gemfile.lock'))
|
15
|
+
end
|
16
|
+
lockfile.specs.map do |spec|
|
17
|
+
@advisories.gem_advisories_for(spec.name).select do |ad|
|
18
|
+
ad.is_affected?(spec.version)
|
19
|
+
end
|
20
|
+
end.flatten
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
metadata
ADDED
@@ -0,0 +1,130 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: bundler-advise
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- chrismo
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-03-05 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: git
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.10'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.10'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: pry
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '10.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '10.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rspec
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
description:
|
84
|
+
email:
|
85
|
+
- chrismo@clabs.org
|
86
|
+
executables: []
|
87
|
+
extensions: []
|
88
|
+
extra_rdoc_files: []
|
89
|
+
files:
|
90
|
+
- ".gitignore"
|
91
|
+
- ".rspec"
|
92
|
+
- ".ruby-version"
|
93
|
+
- ".travis.yml"
|
94
|
+
- Gemfile
|
95
|
+
- LICENSE
|
96
|
+
- README.md
|
97
|
+
- Rakefile
|
98
|
+
- bin/console
|
99
|
+
- bin/setup
|
100
|
+
- bundler-advise.gemspec
|
101
|
+
- lib/bundler/advise.rb
|
102
|
+
- lib/bundler/advise/advisories.rb
|
103
|
+
- lib/bundler/advise/advisory.rb
|
104
|
+
- lib/bundler/advise/gem_adviser.rb
|
105
|
+
- lib/bundler/advise/version.rb
|
106
|
+
homepage: https://github.com/chrismo/bundler-advise
|
107
|
+
licenses:
|
108
|
+
- MIT
|
109
|
+
metadata: {}
|
110
|
+
post_install_message:
|
111
|
+
rdoc_options: []
|
112
|
+
require_paths:
|
113
|
+
- lib
|
114
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
115
|
+
requirements:
|
116
|
+
- - ">="
|
117
|
+
- !ruby/object:Gem::Version
|
118
|
+
version: '0'
|
119
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
120
|
+
requirements:
|
121
|
+
- - ">="
|
122
|
+
- !ruby/object:Gem::Version
|
123
|
+
version: '0'
|
124
|
+
requirements: []
|
125
|
+
rubyforge_project:
|
126
|
+
rubygems_version: 2.4.5.1
|
127
|
+
signing_key:
|
128
|
+
specification_version: 4
|
129
|
+
summary: Scans Gemfile for known vulnerable gems.
|
130
|
+
test_files: []
|