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

Pull vulnerabilities from GitHub Security Advisory Database #140

Merged
merged 1 commit into from
Apr 27, 2020

Conversation

sourabhsparkala
Copy link
Member

  • Create data model, entry as GitHubAdvisories.java
  • Add associated data model classes
  • Add helper query templates first_run_template and next_page_run_template
  • Add a data provider VulnerabilitiesFromGitHubAdvisories.java

This fixes #90

Copy link
Collaborator

@artem-smotrakov artem-smotrakov left a comment

Choose a reason for hiding this comment

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

Since this is just a PoC, please move everything to com.sap.sgs.phosphor.fosstars.data.github.experimental package.

If you think we're ready to convert it to a real provider, please open a follow-up ticket.

Since it's a PoC, I didn't have a close look at the code. I put some other comments, feel free to address them. Or, you can just link them to the follow-up ticket, and we'll address them later when we work on the real provider. We'll also need to add tests but now it's not required.

@@ -0,0 +1,180 @@
package com.sap.sgs.phosphor.fosstars.data.github;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please move everything to com.sap.sgs.phosphor.fosstars.data.github.experimental package.

public class VulnerabilitiesFromGitHubAdvisories extends CachedSingleFeatureGitHubDataProvider {

/**
* A feature that hold info about vulnerabilities in the GitHub Advisory Database.
Copy link
Collaborator

Choose a reason for hiding this comment

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

hold -> holds


Vulnerabilities vulnerabilities = new Vulnerabilities();

PackageManagers managers = (PackageManagers) packageManagement.fetchValueFor(project).get();
Copy link
Collaborator

Choose a reason for hiding this comment

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

packageManagement needs to be configured with callback and cache:

packageManagement.set(cache).set(callback);


PackageManagers managers = (PackageManagers) packageManagement.fetchValueFor(project).get();
for (PackageManager packageManager : managers.list()) {
if (!PackageManager.MAVEN.equals(packageManager)) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

There may be multiple package managers for a project. The loop should not break here.

private Vulnerability vulnerabilityFrom(Node node) {
Advisory advisory = node.getAdvisory();

String id = advisory.getGhsaId();
Copy link
Collaborator

Choose a reason for hiding this comment

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

If an advisory has a CVE id, then it should be used. Otherwise, it will lead to duplicate vulnerabilities in the OssFeatures.VULNERABILITIES feature once we merge all available vulnerabilities.

public List<Node> advisoriesFor(String ecosystem, String artifact) throws IOException {
List<Node> advisories = new ArrayList<>();
for (Node node : download(ecosystem, artifact)) {
if (!hasCve(node.getAdvisory())) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I am not sure that we should skip advisories with CVE identifiers. For such advisories, we can at least try to extract resolution status.

"permalink", "publishedAt", "references", "severity", "summary", "updatedAt", "withdrawnAt"})
public class Advisory {

@JsonProperty("identifiers")
Copy link
Collaborator

Choose a reason for hiding this comment

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

Let's add an extra line between fields.

@sourabhsparkala sourabhsparkala force-pushed the advisory branch 2 times, most recently from 56fa205 to 420b2d6 Compare April 27, 2020 10:21
@sourabhsparkala
Copy link
Member Author

Thank you for the review @artem-smotrakov.
I have addressed the comments.

- Create data model, entry as GitHubAdvisories.java
- Add associated data model classes
- Add helper query templates first_run_template and next_page_run_template
- Add a data provider VulnerabilitiesFromGitHubAdvisories.java

This fixes SAP#90
Copy link
Collaborator

@artem-smotrakov artem-smotrakov left a comment

Choose a reason for hiding this comment

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

Looks fine. We'll work on this data provider further in #143 and #144.

@artem-smotrakov artem-smotrakov merged commit 7d33612 into SAP:master Apr 27, 2020
@sourabhsparkala sourabhsparkala deleted the advisory branch December 2, 2021 19:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

PoC: GitHub security advisories and vulnerability database
2 participants