Skip to content

The vulnerability query API performs M*N queries #6129

@grahamc

Description

@grahamc

Current Behavior

This curl command can take 10s of minutes to complete:

curl -v --header 'X-Api-Key: ...' https://dtrack/api/v1/vulnerability/project/uuid-goes-here

it appears to be caused by an M*N query pattern.

On one of my projects I have ~5k components. That API endpoint calls getVulnerabilities, which:

*/
public List<Vulnerability> getVulnerabilities(Project project, boolean includeSuppressed) {
final List<Vulnerability> vulnerabilities = new ArrayList<>();
final List<Component> components = getAllComponents(project);
for (final Component component: components) {
final Collection<Vulnerability> componentVulns = pm.detachCopyAll(
getAllVulnerabilities(component, includeSuppressed)
);
for (final Vulnerability componentVuln: componentVulns) {
componentVuln.setComponents(Collections.singletonList(pm.detachCopy(component)));
componentVuln.setAliases(new ArrayList<>(pm.detachCopyAll(getVulnerabilityAliases(componentVuln))));
}
vulnerabilities.addAll(componentVulns);
}
return vulnerabilities;
}

  1. Queries all the components,
  2. For each component, runs getAllVulnerabilities which:
    a. queries for vulnerabilities
    b. For each matched vulnerability queries for aliased vulnerabilities
  3. For each found component vulnerability, queries for vulnerability aliases again

I'm pretty sure this is performing many tens of thousands of queries, since this process takes tens of minutes to complete on my project with ~5k components and a few hundred identified vulnerabilities.

Steps to Reproduce

  1. Upload a large SBOM (I can provide one privately)
  2. Upload the SBOM again as VEX data and trigger analysis
  3. Query for impacted vulnerabilities

Expected Behavior

I would expect this process to take a second or so under normal circumstances, though even a minute would be a lot better :).

Dependency-Track Version

4.14.2

Dependency-Track Distribution

Container Image

Database Server

PostgreSQL

Database Server Version

17

Browser

N/A

Checklist

Metadata

Metadata

Assignees

No one assigned

    Labels

    defectSomething isn't workingp2Non-critical bugs, and features that help organizations to identify and reduce riskpending releaseperformance

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions