Skip to content

Compute valid CVSS scores from vectors in GitLab importer (#2330) - #2430

Open
hardikkaurani wants to merge 1 commit into
aboutcode-org:mainfrom
hardikkaurani:fix/gitlab-cvss-score-2330
Open

Compute valid CVSS scores from vectors in GitLab importer (#2330)#2430
hardikkaurani wants to merge 1 commit into
aboutcode-org:mainfrom
hardikkaurani:fix/gitlab-cvss-score-2330

Conversation

@hardikkaurani

Copy link
Copy Markdown

Problem

GitLab advisories provide CVSS vectors in cvss_v2 and cvss_v3 fields, but vulnerabilities/pipelines/v2_importers/gitlab_importer.py previously initialized VulnerabilitySeverity with value=None. Because downstream package risk calculation (vulnerabilities/risk.py:48) requires a populated score (if not vul_score: continue), GitLab CVSS vectors were skipped, producing a 0.0 risk score for affected packages.

Root Cause

The importer parsed vector strings into scoring_elements without invoking the corresponding scoring system calculators.

Implementation Summary

Following the precedent in vulnerabilities/pipes/osv_v2.py:277-283:

  1. Stripped vector strings to prevent parsing failures on stray whitespace.
  2. Computed base score via SCORING_SYSTEMS["cvssv2"].compute(cvss_v2_clean).
  3. Checked for "CVSS:3.1/" prefix to select SCORING_SYSTEMS["cvssv3.1"] vs. SCORING_SYSTEMS["cvssv3"], computing the base score accordingly.
  4. Caught (CVSS2MalformedError, CVSS3MalformedError), logging an error with the invalid vector while preserving the raw vector with value="" so the pipeline never halts on malformed upstream data.

Tests Performed

  • test_parse_gitlab_advisory_computes_cvss_scores: Validated that pypi.yaml vectors produce expected scores (5.0 and 7.5).
  • test_parse_gitlab_advisory_cvss_v31_scoring_system: Validated CVSS 3.1 system dispatch and calculation (9.8).
  • test_parse_gitlab_advisory_malformed_cvss_vectors: Validated that malformed vectors are logged as errors without crashing and retain empty string values.
  • Ran targeted test suite: pytest vulnerabilities/tests/pipelines/v2_importers/test_gitlab_importer_v2.py (11 passed).
  • Formatted with black and isort.

Fixes #2330

Copilot AI lite review requested due to automatic review settings September 13, 2026 20:18

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

Resolves aboutcode-org#2330:
- Use Cvssv2ScoringSystem and Cvssv3ScoringSystem to compute numeric base scores from GitLab cvss_v2 and cvss_v3 vectors
- Support CVSS 3.0 and CVSS 3.1 scoring systems
- Handle malformed vectors gracefully via CVSS2MalformedError and CVSS3MalformedError without interrupting importer execution
- Add regression tests verifying score computation and malformed vector handling

Signed-off-by: Hardik Kaurani <hardikkaurani1@gmail.com>
@hardikkaurani
hardikkaurani force-pushed the fix/gitlab-cvss-score-2330 branch from 2c0b5eb to ed78fbc Compare September 13, 2026 20:19
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.

Incorrect CVSS scores in GitLab v2 advisories

2 participants