Skip to content

fix(cvss): reject a vector that repeats a metric with a conflicting value - #197

Merged
vsn411 merged 1 commit into
secfoo-com:mainfrom
nabeelbaghoor:fix/cvss-parser-silently-keeps-the-last-value-wh
Nov 26, 2026
Merged

vsn411 merged 1 commit into
secfoo-com:mainfrom
nabeelbaghoor:fix/cvss-parser-silently-keeps-the-last-value-wh

Conversation

@nabeelbaghoor

Copy link
Copy Markdown
Contributor

What does this change, and why?

parse_vector() says it raises CvssError when a metric is "duplicated with conflicting values", but it never checked: each segment overwrote the previous one, so the last value won. A SAST finding whose vector came back as AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H/AV:P was stored with a score of 6.8 (physical access) instead of being treated as a malformed vector, and the dashboard's "External" badge (cvss_network_reachable) read the same wrong AV. That is the "wrong, confidently-displayed score" the module's CvssError docstring says it should never produce.

Now a metric that appears twice with different values raises CvssError, naming the metric and both values. A metric repeated with the same value is still accepted. Both callers (runner.py when storing SAST findings, and cvss_network_reachable in web/templating.py) already catch CvssError and fall back to "no score" / not external, so no other code changes.

How to reproduce on main:

from secfoo.cvss import base_score
base_score("AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H/AV:P")  # 6.8 before, CvssError after

Testing

  • pytest tests passes: 2262 passed, 10 failed. The same 10 fail on main in my environment (Rich wrapping CLI tables at a narrow terminal width, mermaid not vendored for the architecture pages, and the Claude capture subprocess test); none touch CVSS.
  • ruff check . passes on the changed files (ruff check src/secfoo/cvss.py tests/test_cvss.py); the repo-wide run reports the same 109 findings on main as with this change.
  • Added/updated tests for the behavior change: test_parse_vector_rejects_metric_repeated_with_a_conflicting_value fails on main (DID NOT RAISE) and passes here; test_parse_vector_accepts_metric_repeated_with_the_same_value pins that an identical repeat still parses.

@vsn411
vsn411 merged commit 5019e59 into secfoo-com:main Nov 26, 2026
9 checks passed
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