govuk_security_audit 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 98b7fe0fb8b87cdd432d66f922aff024737d768c
4
+ data.tar.gz: 815404bf280233fc01720d72df97d5d5d3486200
5
+ SHA512:
6
+ metadata.gz: 6354a9d85ff121085d903590dc10a8a51074eea27d96944aefddcbd37e2f0d380c29f02cb22ea73373d32f770054d9d38ed19d227b359dc6f47c10d436bfb6a6
7
+ data.tar.gz: 7edd64c7a2c49ac6ee19d52506cfef0c832caa4e0444b388aa2949ef93ab890448949e4cd87b89836556746aced66d6cf1b503079965756c4b7d2352ccb72da4
data/.gitignore ADDED
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.gem
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.2
data/CHANGELOG.md ADDED
@@ -0,0 +1,3 @@
1
+ ## 0.1.0
2
+
3
+ - Initial gem release
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in govuk_security_audit.gemspec
4
+ gemspec
data/LICENCE.txt ADDED
@@ -0,0 +1,19 @@
1
+ Copyright (C) 2014 Crown Copyright (Government Digital Service)
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
4
+ this software and associated documentation files (the "Software"), to deal in
5
+ the Software without restriction, including without limitation the rights to
6
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
7
+ of the Software, and to permit persons to whom the Software is furnished to do
8
+ so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in all
11
+ copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,48 @@
1
+ # GOV.UK Gem Security Checker
2
+
3
+ This wraps the [`bundler-audit`](https://github.com/rubysec/bundler-audit/) gem to allow checking
4
+ specific Bundler lockfiles.
5
+
6
+ ## Usage
7
+
8
+ Install the gem:
9
+
10
+ ```
11
+ gem install govuk_security_audit
12
+ ```
13
+
14
+ Update the Ruby Advisory Database:
15
+
16
+ ```
17
+ govuk_security_audit update
18
+ ```
19
+
20
+ Check the current directory:
21
+
22
+ ```
23
+ govuk_security_audit check
24
+ ```
25
+
26
+ Check another directory:
27
+
28
+ ```
29
+ govuk_security_audit check ~/govuk/whitehall
30
+ ```
31
+
32
+ Check a specific Gemfile.lock:
33
+
34
+ ```
35
+ govuk_security_audit check /tmp/whitehall-gemfile.lock
36
+ ```
37
+
38
+ Check a repo on Github:
39
+
40
+ ```
41
+ govuk_security_audit github alphagov whitehall
42
+ ```
43
+
44
+ Check a specific branch on Github:
45
+
46
+ ```
47
+ govuk_security_audit github alphagov whitehall upgrade-rails
48
+ ```
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "gem_publisher"
2
+
3
+ task :publish_gem do |t|
4
+ gem = GemPublisher.publish_if_updated("govuk_security_audit.gemspec", :rubygems)
5
+ puts "Published #{gem}" if gem
6
+ end
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rubygems'
4
+
5
+ lib_dir = File.expand_path(File.join(File.dirname(__FILE__),'..','lib'))
6
+ $LOAD_PATH << lib_dir unless $LOAD_PATH.include?(lib_dir)
7
+
8
+ require 'govuk_security_audit/cli'
9
+
10
+ GovukSecurityAudit::CLI.start
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'govuk_security_audit/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "govuk_security_audit"
8
+ spec.version = GovukSecurityAudit::VERSION
9
+ spec.authors = ["Government Digital Service"]
10
+ spec.email = ["govuk-dev@digital.cabinet-office.gov.uk"]
11
+ spec.licenses = ["MIT"]
12
+
13
+ spec.summary = %q{Check repos for gem vulnerabilities}
14
+ spec.description = %q{Wraps bundler-audit gem to check specific repos for gem vulnerabilities}
15
+ spec.homepage = "https://github.com/alphagov/govuk_security_audit"
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_development_dependency "bundler", "~> 1.9"
23
+ spec.add_development_dependency "rake", "~> 10.0"
24
+ spec.add_development_dependency "gem_publisher", "1.5.0"
25
+ spec.add_dependency "bundler-audit", "~> 0.4.0"
26
+ spec.add_dependency "thor", "~> 0.19"
27
+ end
data/jenkins.sh ADDED
@@ -0,0 +1,18 @@
1
+ #!/bin/bash -x
2
+ set -e
3
+
4
+ rm -f Gemfile.lock
5
+ git clean -fdx
6
+ bundle install --path "${HOME}/bundles/${JOB_NAME}"
7
+
8
+ # Run against our own lockfile to test
9
+ bundle exec govuk_security_audit update
10
+ bundle exec govuk_security_audit check
11
+
12
+ # Check against rails/rails master as this should always be ahead of security Updates
13
+ # We can't check our own repo on Github as we don't commit the Gemfile.lock.
14
+ bundle exec govuk_security_audit github rails rails master
15
+
16
+ if [[ -n "$PUBLISH_GEM" ]]; then
17
+ bundle exec rake publish_gem
18
+ fi
@@ -0,0 +1,20 @@
1
+ #!/bin/bash
2
+ set -e
3
+
4
+ VENV_PATH="${HOME}/venv/${JOB_NAME}"
5
+
6
+ [ -x ${VENV_PATH}/bin/pip ] || virtualenv ${VENV_PATH}
7
+ . ${VENV_PATH}/bin/activate
8
+
9
+ pip install -q ghtools
10
+
11
+ REPO="alphagov/govuk_security_audit"
12
+ gh-status "$REPO" "$GIT_COMMIT" pending -d "\"Build #${BUILD_NUMBER} is running on Jenkins\"" -u "$BUILD_URL" >/dev/null
13
+
14
+ if ./jenkins.sh; then
15
+ gh-status "$REPO" "$GIT_COMMIT" success -d "\"Build #${BUILD_NUMBER} succeeded on Jenkins\"" -u "$BUILD_URL" >/dev/null
16
+ exit 0
17
+ else
18
+ gh-status "$REPO" "$GIT_COMMIT" failure -d "\"Build #${BUILD_NUMBER} failed on Jenkins\"" -u "$BUILD_URL" >/dev/null
19
+ exit 1
20
+ fi
@@ -0,0 +1,114 @@
1
+ require "net/https"
2
+ require "uri"
3
+ require "thor"
4
+ require "bundler/audit/database"
5
+
6
+ require "govuk_security_audit/scanner"
7
+
8
+ module GovukSecurityAudit
9
+ class CLI < Thor
10
+ desc "github USER REPO [REF]", "check the Github repo USER/REPO at an optional REF. Defaults to master."
11
+ def github(user, repo, ref="master")
12
+ uri = URI.parse("https://raw.githubusercontent.com/#{user}/#{repo}/#{ref}/Gemfile.lock")
13
+ http = Net::HTTP.new(uri.host, uri.port)
14
+ http.use_ssl = true
15
+ http.verify_mode = OpenSSL::SSL::VERIFY_NONE
16
+
17
+ request = Net::HTTP::Get.new(uri.request_uri)
18
+
19
+ response = http.request(request)
20
+ if response.code != "200"
21
+ say "Failed to fetch from Github: #{response.code} - #{response.message}", :red
22
+ exit 1
23
+ end
24
+
25
+ file = Tempfile.new(["Gemfile", ".lock"])
26
+ file.write(response.body)
27
+ check(file.path)
28
+ end
29
+
30
+ desc "check [PATH]", "check the Gemfile at PATH, or the current directory."
31
+ def check(path=Dir.pwd)
32
+ scanner = Scanner.new(path)
33
+ vulnerable = false
34
+
35
+ scanner.scan do |result|
36
+ vulnerable = true
37
+
38
+ case result
39
+ when Scanner::InsecureSource
40
+ say "Insecure Source URI found: #{result.source}", :yellow
41
+ when Scanner::UnpatchedGem
42
+ print_advisory result.gem, result.advisory
43
+ end
44
+ end
45
+
46
+ if vulnerable
47
+ say "Vulnerabilities found!", :red
48
+ exit 1
49
+ else
50
+ say "No vulnerabilities found", :green
51
+ end
52
+ end
53
+
54
+ desc 'update', 'Updates the ruby-advisory-db'
55
+ def update
56
+ say "Updating ruby-advisory-db ..."
57
+
58
+ Bundler::Audit::Database.update!
59
+ puts "ruby-advisory-db: #{Bundler::Audit::Database.new.size} advisories"
60
+ end
61
+
62
+ private
63
+
64
+ def print_advisory(gem, advisory)
65
+ say "Name: ", :red
66
+ say gem.name
67
+
68
+ say "Version: ", :red
69
+ say gem.version
70
+
71
+ say "Advisory: ", :red
72
+
73
+ if advisory.cve
74
+ say "CVE-#{advisory.cve}"
75
+ elsif advisory.osvdb
76
+ say advisory.osvdb
77
+ end
78
+
79
+ say "Criticality: ", :red
80
+ case advisory.criticality
81
+ when :low then say "Low"
82
+ when :medium then say "Medium", :yellow
83
+ when :high then say "High", [:red, :bold]
84
+ else say "Unknown"
85
+ end
86
+
87
+ say "URL: ", :red
88
+ say advisory.url
89
+
90
+ if options.verbose?
91
+ say "Description:", :red
92
+ say
93
+
94
+ print_wrapped advisory.description, :indent => 2
95
+ say
96
+ else
97
+
98
+ say "Title: ", :red
99
+ say advisory.title
100
+ end
101
+
102
+ unless advisory.patched_versions.empty?
103
+ say "Solution: upgrade to ", :red
104
+ say advisory.patched_versions.join(', ')
105
+ else
106
+ say "Solution: ", :red
107
+ say "remove or disable this gem until a patch is available!", [:red, :bold]
108
+ end
109
+
110
+ say
111
+ end
112
+
113
+ end
114
+ end
@@ -0,0 +1,18 @@
1
+ require "bundler/audit/database"
2
+ require "bundler/audit/scanner"
3
+ require "bundler/lockfile_parser"
4
+
5
+ module GovukSecurityAudit
6
+ class Scanner < Bundler::Audit::Scanner
7
+ def initialize(path=Dir.pwd)
8
+ path = File.expand_path(path)
9
+ if File.directory?(path)
10
+ path = File.join(path, "Gemfile.lock")
11
+ end
12
+
13
+ @root = File.dirname(path)
14
+ @database = Bundler::Audit::Database.new
15
+ @lockfile = Bundler::LockfileParser.new(File.read(path))
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,3 @@
1
+ module GovukSecurityAudit
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,4 @@
1
+ require "govuk_security_audit/version"
2
+
3
+ module GovukSecurityAudit
4
+ end
metadata ADDED
@@ -0,0 +1,130 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: govuk_security_audit
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Government Digital Service
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-07-21 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.9'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.9'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: gem_publisher
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '='
46
+ - !ruby/object:Gem::Version
47
+ version: 1.5.0
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '='
53
+ - !ruby/object:Gem::Version
54
+ version: 1.5.0
55
+ - !ruby/object:Gem::Dependency
56
+ name: bundler-audit
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 0.4.0
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 0.4.0
69
+ - !ruby/object:Gem::Dependency
70
+ name: thor
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '0.19'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '0.19'
83
+ description: Wraps bundler-audit gem to check specific repos for gem vulnerabilities
84
+ email:
85
+ - govuk-dev@digital.cabinet-office.gov.uk
86
+ executables:
87
+ - govuk_security_audit
88
+ extensions: []
89
+ extra_rdoc_files: []
90
+ files:
91
+ - ".gitignore"
92
+ - ".ruby-version"
93
+ - CHANGELOG.md
94
+ - Gemfile
95
+ - LICENCE.txt
96
+ - README.md
97
+ - Rakefile
98
+ - exe/govuk_security_audit
99
+ - govuk_security_audit.gemspec
100
+ - jenkins.sh
101
+ - jenkins_branches.sh
102
+ - lib/govuk_security_audit.rb
103
+ - lib/govuk_security_audit/cli.rb
104
+ - lib/govuk_security_audit/scanner.rb
105
+ - lib/govuk_security_audit/version.rb
106
+ homepage: https://github.com/alphagov/govuk_security_audit
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
127
+ signing_key:
128
+ specification_version: 4
129
+ summary: Check repos for gem vulnerabilities
130
+ test_files: []