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

Report transitive dependency vulnerability errors for npm, yarn, and pnpm #10282

Merged
merged 7 commits into from
Aug 2, 2024

Conversation

kbukum1
Copy link
Contributor

@kbukum1 kbukum1 commented Jul 24, 2024

Description:

What are you trying to accomplish?

This PR aims to fix a bug for the npm_and_yarn ecosystem. The changes include:

  1. Implementing accurate reporting for transitive dependencies by returning nil when there are conflicting dependencies and the dependency is not top-level.
  2. Ensuring that the correct security fix version is identified for both top-level and transitive dependencies within the npm_and_yarn ecosystem.

This change is necessary to ensure that our system correctly handles and reports vulnerable transitive dependencies within the npm_and_yarn ecosystem, improving our ability to maintain a clear and accurate dependency relationship.

Anything you want to highlight for special attention from reviewers?

This change specifically addresses the bug related to conflicting transitive dependencies in the npm_and_yarn ecosystem.

How will you know you've accomplished your goal?

  • The system accurately identifies and reports the correct security fix versions for both top-level and transitive dependencies within the npm_and_yarn ecosystem.
  • The method handles cases with conflicting dependencies correctly by returning nil for transitive dependencies with conflicts.
  • Additional tests are added to verify the changes, and all tests pass successfully.

Checklist

  • I have run the complete test suite to ensure all tests and linters pass.
  • I have thoroughly tested my code changes to ensure they work as expected, including adding additional tests for new functionality.
  • I have written clear and descriptive commit messages.
  • I have provided a detailed description of the changes in the pull request, including the problem it addresses, how it fixes the problem, and any relevant details about the implementation.
  • I have ensured that the code is well-documented and easy to understand.

@kbukum1 kbukum1 force-pushed the kamil/fix-unknown-transitive-dependency-errors branch from fee7349 to 3ec3c91 Compare July 25, 2024 15:40
@kbukum1 kbukum1 force-pushed the kamil/fix-unknown-transitive-dependency-errors branch 2 times, most recently from 0030239 to 7cd14f8 Compare July 26, 2024 21:01
@kbukum1 kbukum1 changed the title Add parent dependency for npm lock files and resolve transitive dependency errors Report Transitive Dependency Errors for npm_and_yarn Jul 26, 2024
@kbukum1 kbukum1 changed the title Report Transitive Dependency Errors for npm_and_yarn Report Transitive Dependency Errors for npm, yarn, and pnpm Jul 26, 2024
@kbukum1 kbukum1 changed the title Report Transitive Dependency Errors for npm, yarn, and pnpm Report transitive dependency vulnerability errors for npm, yarn, and pnpm Jul 26, 2024
@kbukum1 kbukum1 force-pushed the kamil/fix-unknown-transitive-dependency-errors branch 6 times, most recently from 577bf65 to 753c586 Compare July 29, 2024 17:29
@kbukum1 kbukum1 marked this pull request as ready for review July 29, 2024 18:07
@kbukum1 kbukum1 requested a review from a team as a code owner July 29, 2024 18:07
@kbukum1 kbukum1 marked this pull request as draft July 29, 2024 18:38
@kbukum1 kbukum1 force-pushed the kamil/fix-unknown-transitive-dependency-errors branch 4 times, most recently from bdb06f9 to e696891 Compare July 31, 2024 19:56
@kbukum1 kbukum1 marked this pull request as ready for review July 31, 2024 19:57
@kbukum1 kbukum1 added the core 🍏 Relates to the dependabot-core library itself label Jul 31, 2024
@kbukum1
Copy link
Contributor Author

kbukum1 commented Jul 31, 2024

@jakecoffman, @jurre

This change affects the core functionality of Dependabot. @abdulapopoola has already approved the PR. It would be greatly appreciated if one of you could also review it to ensure its accuracy and stability before we proceed with merging.

Thank you!

@kbukum1 kbukum1 force-pushed the kamil/fix-unknown-transitive-dependency-errors branch from 3dedf27 to 6131ffd Compare August 1, 2024 16:49
@kbukum1 kbukum1 requested a review from vluoto August 1, 2024 17:42
@kbukum1 kbukum1 force-pushed the kamil/fix-unknown-transitive-dependency-errors branch from 4f7b82c to 85a6dac Compare August 1, 2024 17:43
@jakecoffman
Copy link
Member

Thanks for working on fixing these NoChangeError exceptions.

This solution looks like you're on the right track, but I think we can push the check for a conflicting transitive dependency down into the ecosystem.

def lowest_resolvable_security_fix_version
raise "Dependency not vulnerable!" unless vulnerable?
# NOTE: we currently don't resolve transitive/sub-dependencies as
# npm/yarn don't provide any control over updating to a specific
# sub-dependency version
return latest_resolvable_transitive_security_fix_version_with_no_unlock unless dependency.top_level?
# TODO: Might want to check resolvability here?
lowest_security_fix_version
end

I tested returning nil from lowest_resolvable_security_fix_version and it responded with

{"data":{"error-type":"security_update_not_possible","error-details":{"conflicting-dependencies":[{"explanation":"dependency@0.2.0 requires webpack@~5.55.1","name":"dependency","requirement":"~5.55.1","version":"0.2.0"},{"dependency_name":"webpack","explanation":"No patched version available for webpack","fix_available":false,"fix_updates":[],"top_level_ancestors":[]}],"dependency-name":"webpack","latest-resolvable-version":"5.55.1","lowest-non-vulnerable-version":"5.76.0"}},"type":"record_update_job_error"}

So we're already setup to report these as expected errors including the conflicting dependency data. I think the root cause here is lowest_resolvable_security_fix_version should not return an unresolvable version.

In summary, you should be able to add something like return nil if !dependency.top_level? && conflicting_dependencies.any? to the lowest_resolvable_security_fix_version to have the same effect, and not have to change the updater code.

@kbukum1
Copy link
Contributor Author

kbukum1 commented Aug 1, 2024

Thanks for working on fixing these NoChangeError exceptions.

This solution looks like you're on the right track, but I think we can push the check for a conflicting transitive dependency down into the ecosystem.

def lowest_resolvable_security_fix_version
raise "Dependency not vulnerable!" unless vulnerable?
# NOTE: we currently don't resolve transitive/sub-dependencies as
# npm/yarn don't provide any control over updating to a specific
# sub-dependency version
return latest_resolvable_transitive_security_fix_version_with_no_unlock unless dependency.top_level?
# TODO: Might want to check resolvability here?
lowest_security_fix_version
end

I tested returning nil from lowest_resolvable_security_fix_version and it responded with

{"data":{"error-type":"security_update_not_possible","error-details":{"conflicting-dependencies":[{"explanation":"dependency@0.2.0 requires webpack@~5.55.1","name":"dependency","requirement":"~5.55.1","version":"0.2.0"},{"dependency_name":"webpack","explanation":"No patched version available for webpack","fix_available":false,"fix_updates":[],"top_level_ancestors":[]}],"dependency-name":"webpack","latest-resolvable-version":"5.55.1","lowest-non-vulnerable-version":"5.76.0"}},"type":"record_update_job_error"}

So we're already setup to report these as expected errors including the conflicting dependency data. I think the root cause here is lowest_resolvable_security_fix_version should not return an unresolvable version.

In summary, you should be able to add something like return nil if !dependency.top_level? && conflicting_dependencies.any? to the lowest_resolvable_security_fix_version to have the same effect, and not have to change the updater code.

Thanks @jakecoffman. I see. I will check it and if it relating this error to the it's main dependency I will make changes. I think here only I have a concern regarding we are trying to create PR for webpack main dependency and we don't need that since it is already up-to-date and not vulnerable. But because another unrelated webpack transitive dependency we are throwing error. If this error shows security update not possible relating it to the main webpack dependency then I think that is not going to work since it is kind of confussion and unrelated error with main webpack dependency. But really thanks for showing that.

@kbukum1
Copy link
Contributor Author

kbukum1 commented Aug 1, 2024

Thank you @jakecoffman. Just checked and the solution is going to work. Just need to tested it. Thank you.

@kbukum1 kbukum1 force-pushed the kamil/fix-unknown-transitive-dependency-errors branch from 969877c to 6f7c0ce Compare August 2, 2024 00:08
@kbukum1
Copy link
Contributor Author

kbukum1 commented Aug 2, 2024

Thank you @jakecoffman. Just checked and the solution is going to work. Just need to tested it. Thank you.

@jakecoffman , @abdulapopoola the problem is fixed in the way mentioned in the comment. It is ready for review.

end

context "when the dependency is not vulnerable" do
before { allow(checker).to receive(:vulnerable?).and_return(false) }
Copy link
Member

Choose a reason for hiding this comment

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

It's a bad practice to mock the class you're testing.

I would suggest looking at another test in this file that uses @dependabot-fixtures. Create a minimal reproduction of the NoChangeError in that org and use it in this test to verify lowest_resolvable_security_fix_version returns nil.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

@kbukum1 kbukum1 force-pushed the kamil/fix-unknown-transitive-dependency-errors branch from e09ee27 to c05f693 Compare August 2, 2024 16:32
@kbukum1 kbukum1 force-pushed the kamil/fix-unknown-transitive-dependency-errors branch from 7506ddf to ca61ec2 Compare August 2, 2024 17:17
@kbukum1 kbukum1 self-assigned this Aug 2, 2024
Copy link
Member

@jakecoffman jakecoffman left a comment

Choose a reason for hiding this comment

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

This is great, nice work!

@kbukum1 kbukum1 force-pushed the kamil/fix-unknown-transitive-dependency-errors branch from ca61ec2 to 5f93e92 Compare August 2, 2024 17:28
@kbukum1
Copy link
Contributor Author

kbukum1 commented Aug 2, 2024

This is great, nice work!

Thanks for all the feedback.

@kbukum1
Copy link
Contributor Author

kbukum1 commented Aug 2, 2024

The error is going to show like following in the log.

2024/08/02 17:34:26 INFO Starting job processing
2024/08/02 17:34:26 INFO Starting security update job for example/repository
2024/08/02 17:34:26 INFO Checking if webpack 5.55.1 needs updating
2024/08/02 17:34:27 INFO Latest version is 5.93.0
2024/08/02 17:34:28 INFO VulnerabilityAuditor: starting audit
2024/08/02 17:34:36 INFO VulnerabilityAuditor: audit result not viable: downgrades_dependencies
2024/08/02 17:34:36 INFO Requirements to unlock update_not_possible
2024/08/02 17:34:36 INFO Requirements update strategy bump_versions_if_necessary
2024/08/02 17:34:38 INFO The latest possible version that can be installed is 5.55.1 because of the following conflicting dependencies:

  parent-dependency@0.2.0 requires webpack@~5.55.1
  No patched version available for webpack
2024/08/02 17:34:38 INFO The earliest fixed version is 5.76.0.
2024/08/02 17:34:38 INFO Finished job processing
2024/08/02 17:34:38 INFO Results:
Dependabot encountered '1' error(s) during execution, please check the logs for more details.
+------------------------------+
|            Errors            |
+------------------------------+
| security_update_not_possible |
+------------------------------+

@kbukum1 kbukum1 merged commit e34c374 into main Aug 2, 2024
65 checks passed
@kbukum1 kbukum1 deleted the kamil/fix-unknown-transitive-dependency-errors branch August 2, 2024 17:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core 🍏 Relates to the dependabot-core library itself L: javascript
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants