Skip to content

Promote CVE canonical as Cve.Id for GHSA findings to fix FK violations#187

Open
ybelMekk wants to merge 6 commits intomainfrom
fix/promote-github-cve-canonical
Open

Promote CVE canonical as Cve.Id for GHSA findings to fix FK violations#187
ybelMekk wants to merge 6 commits intomainfrom
fix/promote-github-cve-canonical

Conversation

@ybelMekk
Copy link
Copy Markdown
Contributor

@ybelMekk ybelMekk commented May 5, 2026

This pull request improves the handling of vulnerability alias promotion for GITHUB-sourced findings in the dependencytrack package. The main change ensures that when a GITHUB finding references multiple CVE aliases, the lexicographically first CVE is promoted to be the primary canonical identifier (Cve.Id), and related references are trimmed to avoid foreign key violations. The test suite is expanded and updated to cover these new behaviors comprehensively.

Vulnerability alias handling improvements:

  • In pkg/dependencytrack/finding.go, added logic to promote the lexicographically first CVE alias to Cve.Id for GITHUB findings with a GHSA- vulnId, ensuring deterministic and FK-safe canonical selection. References are trimmed to only include the promoted CVE.
  • Updated the link for promoted CVEs to point to the NVD page for the canonical CVE, rather than the GitHub advisory.

Test suite enhancements:

  • Expanded and updated test cases in pkg/dependencytracktest/finding_test.go to verify correct promotion of CVE aliases, proper trimming of references, and accurate setting of Cve.Id and Cve.Link for various combinations of GITHUB and NVD findings with aliases. [1] [2] [3] [4] [5] [6] [7]

Internal code maintenance:

  • Added import of the sort package in pkg/dependencytrack/finding.go to support deterministic selection of the canonical CVE alias.

ybelMekk added 2 commits May 5, 2026 23:25
…olations

For GITHUB-sourced findings whose vulnId is a GHSA, promote the
lexicographically first CVE canonical from the references map to
Cve.Id. This ensures v13s upserts a cve row for the canonical,
satisfying the cve_alias_canonical_fkey FK constraint.

- Guard promotion with strings.HasPrefix(vulnId, "GHSA-") to avoid
  overwriting Cve.Id when vulnId is already a CVE
- Trim references to the promoted canonical only; remaining CVE keys
  would have no cve row and would also violate the FK constraint
- Link updated to NVD URL for the promoted canonical
- Add sort.Strings for deterministic behaviour when a GHSA maps to
  multiple CVE IDs
- Add/update 13 test cases covering all promotion and edge case paths
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR updates ParseFinding’s alias handling for Dependency-Track findings so that GITHUB-sourced GHSA vulnerabilities promote a deterministic “canonical” CVE into Cve.Id, avoiding foreign key violations caused by multiple CVE aliases. Tests are expanded to cover promotion behavior, reference trimming, and link selection.

Changes:

  • Promote the lexicographically first alias key to Cve.Id for source == "GITHUB" findings whose vulnId is a GHSA-*, and trim references down to only the promoted canonical.
  • Update promoted findings’ Cve.Link to the NVD CVE detail page.
  • Expand/adjust unit tests to validate Cve.Id, Cve.Link, and References across multiple alias scenarios.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
pkg/dependencytrack/finding.go Adds canonical CVE promotion + reference trimming for GITHUB GHSA findings; updates link for promoted canonicals.
pkg/dependencytracktest/finding_test.go Updates and expands tests to assert promoted Cve.Id, updated link behavior, and trimmed references.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread pkg/dependencytrack/finding.go Outdated
Comment thread pkg/dependencytrack/finding.go Outdated
When trimming references to the promoted canonical, use references[canonical]
rather than vulnId — if the alias entry's ghsaId differs from vulnId the
original association was being silently rewritten.

Add test case: GITHUB finding where ghsaId differs from vulnId.
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread pkg/dependencytrack/finding.go Outdated
Comment thread pkg/dependencytracktest/finding_test.go
ybelMekk added 2 commits May 6, 2026 00:26
cveId was initialised from vulnId (which can be GHSA-prefixed) and only
promoted to a CVE string on the happy path. primaryId makes clear it is
the final Cve.Id value regardless of whether promotion occurred, and
avoids shadowing the alias-field local also named cveId.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants