Skip to content
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

Merged

Conversation

mctofu
Copy link
Contributor

@mctofu mctofu commented Oct 5, 2022

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

return record_security_update_ignored(checker) unless job.allowed_update?(dependency)

Part of the allowed update check is to see if the dependency is actually still vulnerable:

security_update = update_type == "security" || security_updates_only?
next false if security_update && !vulnerable?(dependency)

I considered removing this check as it's a duplicate of this check in the create pr flow:

if job.security_updates_only?
unless checker.vulnerable?

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:

if job.security_updates_only? &&
dependencies.none? { |d| job.allowed_update?(d) }

@mctofu mctofu force-pushed the mctofu/2855-vuln-multi-version branch from fcb97a8 to e1d3cc4 Compare October 6, 2022 15:53
@mctofu mctofu marked this pull request as ready for review October 6, 2022 19:03
@mctofu mctofu requested a review from a team as a code owner October 6, 2022 19:03
Copy link
Contributor

@bdragon bdragon left a 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
Copy link
Contributor

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) } }
Copy link
Contributor

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

Copy link
Contributor Author

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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good thinking

@mctofu mctofu merged commit 742fe5b into bdragon/2855-vuln-multi-version Oct 6, 2022
@mctofu mctofu deleted the mctofu/2855-vuln-multi-version branch October 6, 2022 22:52
@pavera pavera mentioned this pull request Oct 31, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants