safedep / vet

Tool to achieve policy driven vetting of open source dependencies
Apache License 2.0
214 stars 17 forks source link

Add 'advices' field to the generated json report file #215

Closed r0075h3ll closed 4 months ago

r0075h3ll commented 4 months ago

Hi

The --report-json flag in Vet generated a comprehensive json report file. However, it missed a field that was being displayed in the console output - the 'UPDATE TO' column data, that display what version the package should be upgraded to in order to mitigate the risk.

image

This PR, with a few lines of code, adds 'advices' field to the json report suggesting the alternate package version that the vulnerable package should be upgraded to.

{
    "package":
    {
        "ecosystem": "Maven",
        "name": "com.nimbusds:nimbus-jose-jwt",
        "version": "9.22"
    },
    "manifests":
    [
        "2de911f109118e4d"
    ],
    "advices":
    [
        {
            "target_alternate_package_version": "9.39.1"
        }
    ],
    "vulnerabilities":
    [
        {
            "id": "GHSA-gvpg-vgmx-xg6w",
            "title": "Denial of Service in Connect2id Nimbus JOSE+JWT",
            "aliases":
            [
                "CVE-2023-52428"
            ]
        }
    ],
    "licenses":
    [
        {
            "id": "Apache-2.0"
        }
    ]
}

Thanks.

abhisek commented 4 months ago

@r0075h3ll Thank you very much for your contribution. I have added a few review comments.

abhisek commented 4 months ago

@r0075h3ll I have made a small change. I am including the updated version for the package as a remediation advice in the JSON report. I am skipping the helper function from summaryReporter. The reason being, summaryReport formats the version to a form that is meant for human readability. JSON report is meant for machine parsing hence we must include only the version or nothing in case updated version is not available. We should not include strings like - or Not Available in JSON report IMHO.

abhisek commented 4 months ago

@r0075h3ll Thanks for your contribution. I will trigger a release later tonight. You should have this change included in the latest version of vet by tomorrow.

r0075h3ll commented 4 months ago

@abhisek Thanks for this project, it's really helping the community :)