Repository navigation
Description
Current Behavior
As mentioned in #2337 (comment), Compose package repositories also provide vulnerability information for packages.
For some vulnerabilities this is the only way to get those vulnerabilities, for example SA-CONTRIB-2023-052. Neither OSS, NVD, GHSA, Snyk, OSV report this vulnerability. But for companies running lots of Drupal projects, it's important to have visibility of these vulnerabilities.
The composer package repository provides vulnerability information in two places:
- Package meta data response, i.e. https://packages.drupal.org/files/packages/8/p2/drupal/mollie.json
- API https://packagist.org/api/security-advisories/?packages%5B%5D=drupal/mollie
The API part is unclear what the URL for the Drupal 8 composer repository is. The provided example url is from the main packagist repository. This doesn not return the vulnerability.
More info about the API (and other repo functions): https://packagist.org/apidoc#list-security-advisories
Proposed Behavior
There are multiple options Depenendcy Track can do:
-
During metadata processing in
ComposerMetaAnalyzerthe vulnerability information is already returned by the package repository. These vulnerabilities could be stored in Dependency Track and used by the Internal Analyzer. Currently this is not straightforward as meta data analysis runs in parallel with or possibly after vulnerability analysis. Downside is also that it could confuse users that the repository is also a vulnerability source (could be optional flag). -
A new analyzer could be created i.e.
ComposerVulnerabilityAnalyzerthat uses the API to retrieve vulnerabilities. At the time of writing it's unclear if the Drupal specific package repository supports this API.
I am curious about other peoples thoughts.
Please note that the Composer Package Repository doesn't support PURL or CPE. But since Dependency Track already retrieves meta data by just group and name, it should be OK to do the same for vulnerabilities?
I think somewhere here on Slack or Github somebody pointed us towards a library that maps PURL/CPEs to namespace/group/name parts.
I also raised composer/packagist#1497
Checklist
- I have read and understand the contributing guidelines
- I have checked the existing issues for whether this enhancement was already requested
Activity
nscuro commentedon Dec 17, 2024
Agree with this assessment. Also in general the repository meta analysis is a lot slower than vulnerability analysis, since no repository supports batch request (does Composer?). Trying to somehow couple repo meta and vuln analysis is impractical.
I'd say we make this another vulnerability scanner that can be enabled, or is even enabled by default. It is a bit unfortunate that we'd end up querying the API endpoints more than once for the same component, but I don't see a better option.
Is there any rate limiting imposed on this API?
valentijnscholten commentedon Dec 17, 2024
From their docs
In another spot they mention:
Something even more incremental is also possible:
I haven't looked at the DT data model for this yet, but maybe we can store (or deduce) a value for
If-Modified-Sinceto help reduce the load on their side. We could also look at a shared cache between the Meta analyzer and the vulnerability analyzer. A cache would be good anyway because the meta data response contains the metadata for all package versions at once.However, the
.../p2/xxx/yyy.jsonfiles are static files on their end, so it might just be good enough to request those in a new analyzer without any optimizations.nscuro commentedon Dec 17, 2024
If concurrent requests become a requirement, we could look at https://resilience4j.readme.io/docs/bulkhead to rate limit on our end. We already use resilience4j elsewhere for retries etc.
valentijnscholten commentedon Dec 18, 2024
I have looked into this some more and it's not straightforward. The packagist repo has an api to retrieve vulnerabilities:
api/security-advisories. But this URL doesn't seem to be available on the Drupal package repository above. Neither does the Drupal package repository have thelist.jsonthat contains the names of all the packages in the repository. Or maybe it does have it, but on a different URL. We could fall back to the vulnerabities that are returned in the single package metadata response, but I'm not sure if that is reliable/supported by all repositories.A colleague of mine was trying to implement the same functionality in a custom built SCA tool, but ran into the same problems.
Ultimately he resorted to just running
composer auditand use the output from there.composer audithas all the logic implemented to find all applicable vulnerabilities in the composer ecosystem. It uses the FriendsOfPhp advisories and vendor specific advisories such as from the Drupal repo (and probably Magento, Shopware, etc).It also use GitHub Security Advisories to match with packages.
The
AuditorandComposerRepositoryclasses are non-trivial: https://github.com/composer/composer/blob/main/src/Composer/Advisory/Auditor.phpDo we really want to mimic and maintain all this in Dependency Track?
Wouldn't it be a lot easier/more reliable if we could just ingest the output from
composer audit?When looking at the VEX functionality in Dependency Track I noticed that it cannot be used to add new vulnerabilities to DependencyTrack. It can only apply analysises to vulnerabilities already present in Dependency Track and attributed to the Project where the VEX is being applied.
I understand importing/trusting vulnerabilities from outside Dependency Track doesn't really fit in the model of using the SBOM as source of truth and do all scanning inside DependencyTrack. But this way it might impossible to even get the same results as these scanners/audit tools native to the ecosystems.
EDIT: I am not aware of any Composer Repository Proxy / Aggregator that could be used to achieve the same. It looks like Nexus has some support for Composer repositories. I doubt it supports all the vulnerability related stuff. Even if it would, it would be quite an extra requirement for users to have a Nexus install available.
What possibly could work is to make a little wrapper around the
composer auditcommand / code to expose the audit functionality as a web service to be queried by Dependency Track. Similar to running a local Trivy server. The web service would need to be aware of the repositories used/needed by a project. I don't think these are always in the SBOM. Maybe it could work if it just has "all known" composer repositories configured.nscuro commentedon Dec 18, 2024
Usually vulnerableCode is quite extensive with this sort of thing, but it doesn't look like they support PHP / Drupal either: https://github.com/aboutcode-org/vulnerablecode/tree/main/vulnerabilities/importers
Is it possible to download all data, or does the whole thing depend on ad-hoc queries for each package? If the former, you could just write a mirror task similar to the OSV one. Even if it's non-trivial, I feel like it'd still be better than writing a bespoke external service that users would then need to deploy and operate.
It would also fit the agenda of #4122.
We won't be supporting ingest of tool output like Defect Dojo does, but if you were to transform this into a CycloneDX VDR file we could import that, see below.
It doesn't currently work because it simply was not implemented yet, not because we don't want to support it. There's even a placeholder / TODO for it here:
dependency-track/src/main/java/org/dependencytrack/tasks/BomUploadProcessingTask.java
Lines 272 to 276 in 45982a2
That being said, until #4122 lands, we need to be a bit careful when it comes to vulnerability sources. We wouldn't want VDR imports to overwrite CVE data if it has already been mirrored from the NVD. And
Vulnerability#sourceis currentlyenum-based, so we can't allow anysourcevalue either.valentijnscholten commentedon Dec 19, 2024
In theory it should be able to mirror all the vulnerabilities. At least the main packagist.com has APIs to do that incrementally, even providing a feed with new/changed advisories since a certain timestamp that can be provided as a parameter.
But it's unclear if all the third party repositories support this. Some repositories maybe just static files generated by Satis.
I guess we'll have to interpret the
composer auditcode to understand what it's doing before we know.In theory we could also mirror all the metadata for all packages. There is a
changes.jsonfeed where we can do timestamp based mirroring of package metadata. It has to run at least once per 24h.I am currently looking at which vulnerability identifiers we can expect. There will be vulnerabilities that have an ID generated by the composer auditor (example
PKSA-w57n-mhp6-c9sd). An advisory can have multiple "remote" IDs as well, such as CVE, GHSA. But sometimes there are no other identifiers. We could introduce a new sourceCOMPOSERofCOMPOSER_AUDITfor these PKSA vulnerabilities. But there maybe new remote IDs in these vulnerabilities from third parties, for example Drupal advisotries have an ID likeSA-CONTRIB-2023-052(And noPKSAID). I guess this needs to be another new source?There maybe more sources as Magento, Shopware may have their own IDs as well. Every new sources means a new column in the Aliases table unfortunately. As we don't know all possible sources, some of them will have to be stored under
UNKNOWN.valentijnscholten commentedon Dec 19, 2024
Turns out there's a lot of stuff happening in
composerorcomposer auditwe don't really need. Every repository has a metadata file in their root:https://packages.drupal.org/8/packages.json
This specifies where security advisories can be obtained (or not).
https://wpackagist.org/packages.json doesn't provide a security advisory endpoint:
The
available-package-patternsis interesting to us as it can be used to not spam repositories with unrelated queries.Some repositories such as wpackagits also do not provide a metadata endpoint. I haven't looked into that, just focussing on the vulnerability aspects here.
In theory it's possible to use the security advisory API to build a complete mirror. I'm unsure if we can run into problems if we combine the vulnerabilitiy data from multiple repositories into one SOURCE / mirror on the DT side.
valentijnscholten commentedon Dec 19, 2024
The vulnerabilities coming in from the composer repostiories do not have a
PURLor aCPE. Currently the Internal Analyzer in DT only detectsVulnerableSoftwarethat has at least one of those.I also see code in
OsvDownloadTaskandGitHubAdvisoryMirrorTaskpreventing the creation ofVulnerableSoftwareentities without aPURL. Should we try to recreate thePURLas is being done inGitHubAdvisoryMirrorTask?Strange thing is that in my deptrack databases I can see lots of
VulnerableSoftwarewithout aPURLand without aCPE:nscuro commentedon Dec 19, 2024
PURL_TYPE,PURL_NAMESPACE, andPURL_NAMEis what we query on during analysis. Storing the entire PURL mostly just bloats the table, I'm not sure why that column even exists given we also have dedicated columns for qualifiers and subpaths (which are not relevant to any vulnerability source I know of anyway).valentijnscholten commentedon Dec 19, 2024
Ah, I there are rows in my databases that do have the PURL column populated, guess that put me on the wrong foot. It's only 96k rows I checked just now :-)
So what do you think would be the best option @nscuro. Going for a new external analyzer which is easier to implement and can be enabled/disabled or going for a full mirror that is more work and needs more safeguarding to make sure it doesn't fail too often and doesn't miss any vulnerabilities. Currently there's also the downside that once mirrored, the Internal Analyzer will keep detecting/reporting the vulnerabilities, even after the mirroring is disabled.