Skip to content

Backport: Add option to use Snyk's per-package endpoint when batching is not available - #7362

Merged
nscuro merged 1 commit into
DependencyTrack:5.1.xfrom
nscuro:backport-pr-7195
Sep 20, 2026
Merged

nscuro merged 1 commit into
DependencyTrack:5.1.xfrom
nscuro:backport-pr-7195

Conversation

@nscuro

@nscuro nscuro commented Sep 20, 2026

Copy link
Copy Markdown
Member

Description

Adds option to use Snyk's per-package endpoint when batching is not available.

Addressed Issue

Fixes #7137
Backports #7195

Additional Details

N/A

Checklist

  • I have read and understand the contributing guidelines
  • This PR fixes a defect, and I have provided tests to verify that the fix is effective
  • This PR implements an enhancement, and I have provided tests to verify that it works as intended
  • This PR introduces changes to the database model, and I have updated the migration changelog accordingly
  • This PR introduces new or alters existing behavior, and I have updated the documentation accordingly
  • This PR is a substantial change (per the ADR criteria), and I have added an ADR under docs/adr/

…ailable (DependencyTrack#7195)

* Fall back to the Snyk per-package endpoint when the batch endpoint is forbidden

The batch endpoint POST /rest/orgs/{org}/packages/issues is not available to
all Snyk organizations, and answers 403 for those it is not available to.
Since v5 uses it exclusively, and 403 is not retryable, the analyzer fails for
those organizations. The per-package endpoint used by v4 still works with the
same token.

Fall back to the per-package endpoint when the batch endpoint answers 403. The
fallback sticks for the remainder of the analysis, so a single 403 is not
repeated once per batch, and it is logged, because it means one request per
package rather than one per 100.

Fixes DependencyTrack#7137

Signed-off-by: Arjav <arjavdongaonkar@gmail.com>

* Attribute per-package issues by requested PURL and tolerate unknown packages

Two problems with the fallback as first written.

Issues returned by the per-package endpoint were correlated back to their PURL
through SnykModelConverter.getIssuePurl, which reads a fixed representation
index of the batch response shape. A per-package response does not have to
repeat the package coordinates, since the package is implied by the request
URL. When it does not, every issue is skipped and the PURL is then cached as
having no vulnerabilities, which is a silent false negative and worse than the
failure this is meant to fix. The per-package path already knows the PURL it
asked for, so it now keys results by that directly and does not parse
coordinates at all.

A 404 for a package Snyk does not know also failed the whole analysis. The
batch endpoint simply omits such packages, and v4 logged and carried on, so
treat it as having no issues.

The fallback test now uses a per-package response without package coordinates,
so it fails if correlation regresses to reading them.

Signed-off-by: Arjav <arjavdongaonkar@gmail.com>

* Select the Snyk package endpoint by configuration instead of on 403

A 403 can mean things other than the batch endpoint being unavailable, so
inferring the endpoint from it is guesswork. It also wastes a request per
analysis for organizations without batch access, since the first call always
fails before the fallback kicks in.

Replace it with a batchRequestsEnabled setting, defaulting to true so existing
deployments are unaffected. Organizations without batch access turn it off and
the analyzer uses the per-package endpoint directly.

Also lower the per-package request timeout to 10s, since these requests cover
a single package rather than a batch of 100.

Signed-off-by: Arjav <arjavdongaonkar@gmail.com>

* Default batchRequestsEnabled to true in the schema

Setting the default only on the factory's default config covers new
configurations. Configurations already stored in user databases do not have
the field, so they deserialized to false and would have silently stopped using
the batch endpoint on upgrade.

Signed-off-by: Arjav <arjavdongaonkar@gmail.com>

---------

Signed-off-by: Arjav <arjavdongaonkar@gmail.com>
(cherry picked from commit ec415e3)
Signed-off-by: nscuro <nscuro@protonmail.com>
@nscuro nscuro added this to the 5.1.1 milestone Sep 20, 2026
@nscuro nscuro added defect Something isn't working integration/snyk Related to the Snyk integration labels Sep 20, 2026
@owasp-dt-bot

Copy link
Copy Markdown

✅ Snyk checks have passed. No issues have been found so far.

Status Scan Engine Critical High Medium Low Total (0)
✅ Open Source Security 0 0 0 0 0 issues

💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse.

@codacy-production

codacy-production Bot commented Sep 20, 2026 •

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 12 complexity

Metric Results
Complexity 12

View in Codacy

🟢 Coverage 77.05% diff coverage

Metric Results
Coverage variation Report missing for c44d5141
Diff coverage ✅ 77.05% diff coverage (70.00%)

View coverage diff in Codacy

Coverage variation details
Coverable lines Covered lines Coverage
Common ancestor commit (c44d514) Report Missing Report Missing Report Missing
Head commit (7248701) 44380 38727 87.26%

Coverage variation is the difference between the coverage for the head and common ancestor commits of the pull request branch: <coverage of head commit> - <coverage of common ancestor commit>

Diff coverage details
Coverable lines Covered lines Diff coverage
Pull request (#7362) 61 47 77.05%

Diff coverage is the percentage of lines that are covered by tests out of the coverable lines that the pull request added or modified: <covered lines added or modified>/<coverable lines added or modified> * 100%

1 Codacy didn't receive coverage data for the commit, or there was an error processing the received data. Check your integration for errors and validate that your coverage setup is correct.

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

@nscuro
nscuro merged commit 1c29f40 into DependencyTrack:5.1.x Sep 20, 2026
21 checks passed
@nscuro
nscuro deleted the backport-pr-7195 branch September 20, 2026 14:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

defect Something isn't working integration/snyk Related to the Snyk integration

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants