-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Consider all dependency versions in Job.vulnerable? #5837
Consider all dependency versions in Job.vulnerable? #5837
Conversation
Allows reuse outside of the UpdateChecker
fcb97a8
to
e1d3cc4
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks great!
return [version].compact unless all_versions | ||
|
||
all_versions.filter_map(&:version) | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👌
security_advisories.any? { |a| a.vulnerable?(version) } | ||
all_versions = dependency.all_versions. | ||
filter_map { |v| version_class.new(v) if version_class.correct?(v) } | ||
security_advisories.any? { |a| all_versions.any? { |v| a.vulnerable?(v) } } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've noticed this code
version_class = Utils.version_class_for_package_manager(package_manager)
version_class.new(version) if version_class.correct?(version)
in a lot of places. Looking at it once again here, I'm wondering if it wouldn't make sense to put this in Dependency
. It would be a reasonable argument to say it's too much for that class to know about, but it would remove some boilerplate. Maybe something like this (but probably with better naming)
def correct_version
version_class = Utils.version_class_for_package_manager(package_manager)
version_class.new(version) if version_class.correct?(version)
end
def all_correct_versions
version_class = Utils.version_class_for_package_manager(package_manager)
all_versions.filter_map { |v| version_class.new(v) if version_class.correct?(v) }
end
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, that's a good thought! There's still some future changes needed to get a successful PR through. If that ends up duplicating this again I think that'd be good opportunity to dry it up?
metadata: { foo: 43 } | ||
) | ||
expect(dependency1).to eq(dependency2) | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good thinking
In testing #5801 via the updater we found there's an additional spot we need to consider all versions of a dependency when doing a vulnerability check. This is to prevent Dependabot from returning a confusing error message that all versions have been ignored.
This code path is invoked from the updater at
dependabot-core/updater/lib/dependabot/updater.rb
Line 231 in 97ae98c
Part of the allowed update check is to see if the dependency is actually still vulnerable:
dependabot-core/updater/lib/dependabot/job.rb
Lines 77 to 78 in 97ae98c
I considered removing this check as it's a duplicate of this check in the create pr flow:
dependabot-core/updater/lib/dependabot/updater.rb
Lines 221 to 222 in 97ae98c
However, it's also checked in the update pr flow so it would have taken more changes to try and sort that out so I'm leaving that for a future cleanup:
dependabot-core/updater/lib/dependabot/updater.rb
Lines 140 to 141 in 97ae98c