dependabot-bundler 0.400.0 → 0.402.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 +4 -4
- data/lib/dependabot/bundler/checksum_mismatch.rb +186 -0
- data/lib/dependabot/bundler/file_updater/lockfile_updater.rb +4 -0
- data/lib/dependabot/bundler/update_checker/force_updater.rb +2 -0
- data/lib/dependabot/bundler/update_checker/shared_bundler_helpers.rb +12 -0
- data/lib/dependabot/bundler/update_checker/version_resolver.rb +3 -0
- metadata +5 -4
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: bb3a335819282e6748205f5fb30c9aacebef64939e246aa257862e9cd7482833
|
|
4
|
+
data.tar.gz: 93d19e9e411e1dfff646c21c2ff7dd6b2561e3fe84f6e3aa431e0418ec3e86bd
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: bee1ab9af8bd0671e04d347c1fcfa7edf048b809ec770970bea06fba9ef39a5901a8666e44df266e3ec3d7e838e17fed095ca5883e90ece3a8badecc37c7baab
|
|
7
|
+
data.tar.gz: fb7f82f7b7c78d4a6dd27ae1c225ca0f523c78b80e55a918828aa2fa298ac3136b7343f44834288b1ba75a9c892d1b80ff1345dc0c5253e13d29889725a21cbf
|
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
# typed: strong
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
require "sorbet-runtime"
|
|
5
|
+
require "uri"
|
|
6
|
+
require "dependabot/errors"
|
|
7
|
+
require "dependabot/shared_helpers"
|
|
8
|
+
|
|
9
|
+
module Dependabot
|
|
10
|
+
module Bundler
|
|
11
|
+
# Bundler (2.5+) refuses to resolve when two sources report different
|
|
12
|
+
# checksums for the same gem version, e.g. the lockfile CHECKSUMS section
|
|
13
|
+
# and the registry's compact index. Because Bundler checks every gem it
|
|
14
|
+
# fetches, one bad entry blocks updates to all dependencies in the lockfile.
|
|
15
|
+
#
|
|
16
|
+
# This turns that helper failure into a DependencyChecksumMismatch whose
|
|
17
|
+
# message names the gem and both checksums. Bundler's own message is not
|
|
18
|
+
# passed through: it suggests disabling checksum validation and can include
|
|
19
|
+
# local file paths.
|
|
20
|
+
module ChecksumMismatch
|
|
21
|
+
extend T::Sig
|
|
22
|
+
|
|
23
|
+
ERROR_CLASS = "Bundler::ChecksumMismatchError"
|
|
24
|
+
HEADER = "Bundler found mismatched checksums."
|
|
25
|
+
ENTRY_LINE = /\A (?<lock_name>\S+ \([^)\s]+\)) (?<checksum>[A-Za-z0-9]+=\S+)\z/
|
|
26
|
+
SOURCE_LINE = /\A (?:from|and) (?<source>\S.*)\z/
|
|
27
|
+
LOCKFILE_SOURCE_PREFIX = "the lockfile CHECKSUMS at "
|
|
28
|
+
API_SOURCE_PREFIX = "the API at "
|
|
29
|
+
GEM_SOURCE_PREFIX = "the gem at "
|
|
30
|
+
BUNDLER_LOCK_NAME_PREFIX = "bundler ("
|
|
31
|
+
|
|
32
|
+
GENERIC_MESSAGE =
|
|
33
|
+
"Bundler found mismatched checksums for a gem in your lockfile, so Dependabot " \
|
|
34
|
+
"can't update it. Check that the checksums in your lockfile match the gems " \
|
|
35
|
+
"served by your registries."
|
|
36
|
+
|
|
37
|
+
class ChecksumEntry < T::Struct
|
|
38
|
+
const :lock_name, String
|
|
39
|
+
const :checksum, String
|
|
40
|
+
const :sources, T::Array[String]
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
class ParsedMismatch < T::Struct
|
|
44
|
+
const :lock_name, String
|
|
45
|
+
const :entries, T::Array[ChecksumEntry]
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
sig do
|
|
49
|
+
params(error: Dependabot::SharedHelpers::HelperSubprocessFailed)
|
|
50
|
+
.returns(T.nilable(Dependabot::DependencyChecksumMismatch))
|
|
51
|
+
end
|
|
52
|
+
def self.error_for(error)
|
|
53
|
+
return nil unless error.error_class == ERROR_CLASS
|
|
54
|
+
|
|
55
|
+
parsed = parse(error.message)
|
|
56
|
+
return Dependabot::DependencyChecksumMismatch.new(GENERIC_MESSAGE) unless parsed
|
|
57
|
+
|
|
58
|
+
# A mismatch on Bundler itself comes from the Bundler installed in the
|
|
59
|
+
# runner, not from the user's files, so leave it as an unknown error.
|
|
60
|
+
return nil if parsed.lock_name.start_with?(BUNDLER_LOCK_NAME_PREFIX)
|
|
61
|
+
|
|
62
|
+
Dependabot::DependencyChecksumMismatch.new(
|
|
63
|
+
build_message(parsed),
|
|
64
|
+
dependency_name: parsed.lock_name
|
|
65
|
+
)
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
# Expected shape (each side may list several sources joined by "and"):
|
|
69
|
+
#
|
|
70
|
+
# Bundler found mismatched checksums. This is a potential security risk.
|
|
71
|
+
# rack (2.2.3) sha256=aaa...
|
|
72
|
+
# from the lockfile CHECKSUMS at Gemfile.lock:16:16
|
|
73
|
+
# rack (2.2.3) sha256=bbb...
|
|
74
|
+
# from the API at https://rubygems.org/
|
|
75
|
+
sig { params(message: String).returns(T.nilable(ParsedMismatch)) }
|
|
76
|
+
def self.parse(message)
|
|
77
|
+
entries = parse_entries(mismatch_lines(message))
|
|
78
|
+
return nil unless entries && entries.size == 2
|
|
79
|
+
return nil unless entries.map(&:lock_name).uniq.size == 1
|
|
80
|
+
return nil if entries.any? { |entry| entry.sources.empty? }
|
|
81
|
+
|
|
82
|
+
ParsedMismatch.new(lock_name: T.must(entries.first).lock_name, entries: entries)
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
# The lines between the header and the first blank line. The advice that
|
|
86
|
+
# follows differs between Bundler versions, so it isn't parsed.
|
|
87
|
+
sig { params(message: String).returns(T.nilable(T::Array[String])) }
|
|
88
|
+
def self.mismatch_lines(message)
|
|
89
|
+
lines = message.lines.map(&:chomp)
|
|
90
|
+
header_index = lines.index { |line| line.start_with?(HEADER) }
|
|
91
|
+
return nil unless header_index
|
|
92
|
+
|
|
93
|
+
lines.drop(header_index + 1).take_while { |line| !line.strip.empty? }
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
sig { params(lines: T.nilable(T::Array[String])).returns(T.nilable(T::Array[ChecksumEntry])) }
|
|
97
|
+
def self.parse_entries(lines)
|
|
98
|
+
return nil unless lines
|
|
99
|
+
|
|
100
|
+
entries = T.let([], T::Array[ChecksumEntry])
|
|
101
|
+
lines.each do |line|
|
|
102
|
+
if (entry = ENTRY_LINE.match(line))
|
|
103
|
+
entries << ChecksumEntry.new(
|
|
104
|
+
lock_name: T.must(entry[:lock_name]),
|
|
105
|
+
checksum: T.must(entry[:checksum]),
|
|
106
|
+
sources: []
|
|
107
|
+
)
|
|
108
|
+
elsif (source = SOURCE_LINE.match(line)) && (last_entry = entries.last)
|
|
109
|
+
last_entry.sources << T.must(source[:source])
|
|
110
|
+
else
|
|
111
|
+
return nil
|
|
112
|
+
end
|
|
113
|
+
end
|
|
114
|
+
entries
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
sig { params(parsed: ParsedMismatch).returns(String) }
|
|
118
|
+
def self.build_message(parsed)
|
|
119
|
+
first, second = parsed.entries
|
|
120
|
+
"Bundler found mismatched checksums for #{parsed.lock_name}: " \
|
|
121
|
+
"#{describe(T.must(first))}, but #{describe(T.must(second))}. " \
|
|
122
|
+
"#{resolution_advice(parsed)}"
|
|
123
|
+
end
|
|
124
|
+
|
|
125
|
+
sig { params(entry: ChecksumEntry).returns(String) }
|
|
126
|
+
def self.describe(entry)
|
|
127
|
+
"#{entry.checksum} from #{entry.sources.map { |source| describe_source(source) }.join(' and ')}"
|
|
128
|
+
end
|
|
129
|
+
|
|
130
|
+
sig { params(source: String).returns(String) }
|
|
131
|
+
def self.describe_source(source)
|
|
132
|
+
return describe_api_source(source) if source.start_with?(API_SOURCE_PREFIX)
|
|
133
|
+
# Only show file names: full paths are locations inside the runner.
|
|
134
|
+
if source.start_with?(LOCKFILE_SOURCE_PREFIX)
|
|
135
|
+
return "#{LOCKFILE_SOURCE_PREFIX}#{File.basename(source.delete_prefix(LOCKFILE_SOURCE_PREFIX))}"
|
|
136
|
+
end
|
|
137
|
+
return "the gem file #{File.basename(source.delete_prefix(GEM_SOURCE_PREFIX))}" if
|
|
138
|
+
source.start_with?(GEM_SOURCE_PREFIX)
|
|
139
|
+
|
|
140
|
+
"another source"
|
|
141
|
+
end
|
|
142
|
+
|
|
143
|
+
# Only show the registry's scheme, host and port. Bundler removes user
|
|
144
|
+
# info, but some registries (e.g. Gemfury) put a token in the path.
|
|
145
|
+
sig { params(source: String).returns(String) }
|
|
146
|
+
def self.describe_api_source(source)
|
|
147
|
+
uri = URI.parse(source.delete_prefix(API_SOURCE_PREFIX))
|
|
148
|
+
host = uri.host
|
|
149
|
+
return "a registry" unless uri.scheme && host
|
|
150
|
+
|
|
151
|
+
default_port = T.let(uri.default_port, T.nilable(Integer))
|
|
152
|
+
port = uri.port == default_port ? "" : ":#{uri.port}"
|
|
153
|
+
"#{API_SOURCE_PREFIX}#{uri.scheme}://#{host}#{port}"
|
|
154
|
+
rescue URI::InvalidURIError
|
|
155
|
+
"a registry"
|
|
156
|
+
end
|
|
157
|
+
|
|
158
|
+
sig { params(parsed: ParsedMismatch).returns(String) }
|
|
159
|
+
def self.resolution_advice(parsed)
|
|
160
|
+
from_lockfile = parsed.entries.any? do |entry|
|
|
161
|
+
entry.sources.any? { |source| source.start_with?(LOCKFILE_SOURCE_PREFIX) }
|
|
162
|
+
end
|
|
163
|
+
|
|
164
|
+
if from_lockfile
|
|
165
|
+
"Dependabot can't update this lockfile until they match. Check which copy of the " \
|
|
166
|
+
"gem is correct. If the registry's copy is correct, remove the #{parsed.lock_name} " \
|
|
167
|
+
"entry from the CHECKSUMS section of your lockfile (and any stale copy of the gem in " \
|
|
168
|
+
"vendor/cache), then run `bundle lock`. " \
|
|
169
|
+
"Otherwise, republish the gem so the registry serves the expected file."
|
|
170
|
+
else
|
|
171
|
+
"Dependabot can't update this lockfile until they match. Check that the gem " \
|
|
172
|
+
"served by your registry is the one you expect."
|
|
173
|
+
end
|
|
174
|
+
end
|
|
175
|
+
|
|
176
|
+
private_class_method :parse,
|
|
177
|
+
:mismatch_lines,
|
|
178
|
+
:parse_entries,
|
|
179
|
+
:build_message,
|
|
180
|
+
:describe,
|
|
181
|
+
:describe_source,
|
|
182
|
+
:describe_api_source,
|
|
183
|
+
:resolution_advice
|
|
184
|
+
end
|
|
185
|
+
end
|
|
186
|
+
end
|
|
@@ -8,6 +8,7 @@ require "dependabot/shared_helpers"
|
|
|
8
8
|
require "dependabot/errors"
|
|
9
9
|
require "dependabot/bundler/file_updater"
|
|
10
10
|
require "dependabot/bundler/cached_lockfile_parser"
|
|
11
|
+
require "dependabot/bundler/checksum_mismatch"
|
|
11
12
|
require "dependabot/bundler/native_helpers"
|
|
12
13
|
require "dependabot/bundler/helpers"
|
|
13
14
|
|
|
@@ -125,6 +126,9 @@ module Dependabot
|
|
|
125
126
|
rescue SharedHelpers::HelperSubprocessFailed => e
|
|
126
127
|
raise Dependabot::DependencyFileNotResolvable, e.message if e.error_class == "Bundler::SolveFailure"
|
|
127
128
|
|
|
129
|
+
checksum_mismatch = ChecksumMismatch.error_for(e)
|
|
130
|
+
raise checksum_mismatch if checksum_mismatch
|
|
131
|
+
|
|
128
132
|
raise
|
|
129
133
|
end
|
|
130
134
|
|
|
@@ -121,6 +121,8 @@ module Dependabot
|
|
|
121
121
|
)
|
|
122
122
|
dependencies_from(updated_deps, specs)
|
|
123
123
|
rescue SharedHelpers::HelperSubprocessFailed => e
|
|
124
|
+
raise_if_checksum_mismatch(e)
|
|
125
|
+
|
|
124
126
|
msg = e.error_class + " with message: " + e.message
|
|
125
127
|
raise Dependabot::DependencyFileNotResolvable, msg
|
|
126
128
|
end
|
|
@@ -6,6 +6,7 @@ require "sorbet-runtime"
|
|
|
6
6
|
require "uri"
|
|
7
7
|
|
|
8
8
|
require "dependabot/bundler/update_checker"
|
|
9
|
+
require "dependabot/bundler/checksum_mismatch"
|
|
9
10
|
require "dependabot/bundler/native_helpers"
|
|
10
11
|
require "dependabot/bundler/helpers"
|
|
11
12
|
require "dependabot/logger"
|
|
@@ -118,6 +119,8 @@ module Dependabot
|
|
|
118
119
|
# rubocop:disable Metrics/MethodLength
|
|
119
120
|
sig { params(error: Dependabot::SharedHelpers::HelperSubprocessFailed).returns(T.noreturn) }
|
|
120
121
|
def handle_bundler_errors(error)
|
|
122
|
+
raise_if_checksum_mismatch(error)
|
|
123
|
+
|
|
121
124
|
if error.error_class == "JSON::ParserError"
|
|
122
125
|
msg = "Error evaluating your dependency files: #{error.message}"
|
|
123
126
|
raise Dependabot::DependencyFileNotEvaluatable, msg
|
|
@@ -206,6 +209,15 @@ module Dependabot
|
|
|
206
209
|
# rubocop:enable Metrics/AbcSize
|
|
207
210
|
# rubocop:enable Metrics/MethodLength
|
|
208
211
|
|
|
212
|
+
sig { params(error: Dependabot::SharedHelpers::HelperSubprocessFailed).void }
|
|
213
|
+
def raise_if_checksum_mismatch(error)
|
|
214
|
+
return unless error.error_class == ChecksumMismatch::ERROR_CLASS
|
|
215
|
+
|
|
216
|
+
# A mismatch that isn't mapped (on Bundler itself) is re-raised as-is,
|
|
217
|
+
# so callers don't mistake it for an ordinary resolution failure.
|
|
218
|
+
raise ChecksumMismatch.error_for(error) || error
|
|
219
|
+
end
|
|
220
|
+
|
|
209
221
|
# When Bundler fails to parse gem metadata served by a registry's compact
|
|
210
222
|
# index, surface it as a private source error (the registry returned bad
|
|
211
223
|
# data) rather than blaming the user's dependency files. Returns nil when
|
|
@@ -177,6 +177,9 @@ module Dependabot
|
|
|
177
177
|
rescue Dependabot::SharedHelpers::HelperSubprocessFailed => e
|
|
178
178
|
raise if e.is_a?(VersionDetails::InvalidResult)
|
|
179
179
|
|
|
180
|
+
# Checked first: the message names other gems, which the heuristics
|
|
181
|
+
# below could mistake for an expected failure.
|
|
182
|
+
raise_if_checksum_mismatch(e)
|
|
180
183
|
return if error_due_to_restrictive_upper_bound?(e)
|
|
181
184
|
return if circular_dependency_at_new_version?(e)
|
|
182
185
|
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: dependabot-bundler
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.402.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Dependabot
|
|
@@ -15,14 +15,14 @@ dependencies:
|
|
|
15
15
|
requirements:
|
|
16
16
|
- - '='
|
|
17
17
|
- !ruby/object:Gem::Version
|
|
18
|
-
version: 0.
|
|
18
|
+
version: 0.402.0
|
|
19
19
|
type: :runtime
|
|
20
20
|
prerelease: false
|
|
21
21
|
version_requirements: !ruby/object:Gem::Requirement
|
|
22
22
|
requirements:
|
|
23
23
|
- - '='
|
|
24
24
|
- !ruby/object:Gem::Version
|
|
25
|
-
version: 0.
|
|
25
|
+
version: 0.402.0
|
|
26
26
|
- !ruby/object:Gem::Dependency
|
|
27
27
|
name: parallel
|
|
28
28
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -318,6 +318,7 @@ files:
|
|
|
318
318
|
- helpers/v4/spec/shared_contexts.rb
|
|
319
319
|
- lib/dependabot/bundler.rb
|
|
320
320
|
- lib/dependabot/bundler/cached_lockfile_parser.rb
|
|
321
|
+
- lib/dependabot/bundler/checksum_mismatch.rb
|
|
321
322
|
- lib/dependabot/bundler/file_fetcher.rb
|
|
322
323
|
- lib/dependabot/bundler/file_fetcher/child_gemfile_finder.rb
|
|
323
324
|
- lib/dependabot/bundler/file_fetcher/gemspec_finder.rb
|
|
@@ -362,7 +363,7 @@ licenses:
|
|
|
362
363
|
- MIT
|
|
363
364
|
metadata:
|
|
364
365
|
bug_tracker_uri: https://github.com/dependabot/dependabot-core/issues
|
|
365
|
-
changelog_uri: https://github.com/dependabot/dependabot-core/releases/tag/v0.
|
|
366
|
+
changelog_uri: https://github.com/dependabot/dependabot-core/releases/tag/v0.402.0
|
|
366
367
|
rdoc_options: []
|
|
367
368
|
require_paths:
|
|
368
369
|
- lib
|