fix(sarif): ignore negative result ranks

What does this MR do and why?

This MR fixes SARIF severity resolution when result.rank contains a negative value.

According to the SARIF 2.1.0 specification, a missing rank defaults to -1, indicating that the rank is unknown or unset.

Previously, GitLab treated negative ranks as valid because -1 is truthy in Ruby. Consequently, rank_to_severity classified the result as Critical, even when other severity information was available.

This change ignores negative ranks and allows the existing fallback logic to determine severity using:

  1. rule.properties.security-severity
  2. result.properties.security-severity
  3. result.level
  4. rule.defaultConfiguration.level
  5. DEFAULT_SEVERITY

Valid non-negative ranks continue to take precedence over fallback severity values.

References

Screenshots or screen recordings

Before

A SARIF result with rank: -1 was incorrectly assigned Critical severity.

After

Negative ranks are ignored, and severity is resolved using the available fallback properties.

Not applicable — this is a backend parser fix.

How to set up and validate locally

Run the following commands:

`gitlab-check

bundle exec rspec ee/spec/lib/gitlab/security/parsers/sarif_spec.rb`

Validation results:

  • RuboCop: PASS — 2 files inspected, no offenses.
  • RSpec: PASS — 157 examples, 0 failures.
  • Focused SARIF parser spec: PASS — 157 examples, 0 failures.
  • git diff --check: PASS.

MR acceptance checklist

Evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.

  • Regression tests cover negative SARIF ranks.
  • Valid non-negative rank handling is preserved.
  • Existing severity fallback precedence is preserved.
  • Tests cover fallback to rule and result security severity, result level, rule default level, and default severity.
  • RuboCop passes.
  • Focused RSpec tests pass.
  • No whitespace errors.

Merge request reports

Loading
Loading