Skip to content

fix: detect exploit references when severities are present - #2519

Open
dajiaohuang wants to merge 1 commit into
aboutcode-org:mainfrom
dajiaohuang:fix-exploitability-with-severities
Open

dajiaohuang wants to merge 1 commit into
aboutcode-org:mainfrom
dajiaohuang:fix-exploitability-with-severities

Conversation

@dajiaohuang

Copy link
Copy Markdown

The defect

vulnerabilities/risk.py, get_exploitability_level() (line 85 before this change).

The function decides exploitability in three steps, written as an if / elif / elif chain:

if exploits:          # exploit records (KEV, Exploit-DB, Metasploit)
    exploit_level = 2
elif severities:      # high EPSS
    ...
elif references:      # published exploit / PoC reference
    ...exploit_level = 1

Because the reference branch is an elif, it is only ever reached when an advisory has no severities at all. Almost every advisory carries at least one severity — CVSS, SSVC, EPSS, or a generic textual rating — so in practice the references branch is dead code and a published exploit reference never raises exploitability.

A vulnerability with a published exploit is therefore reported as 0.5 ("no exploit known") rather than 1.

Path

Public entry point → call chain → state → consumer:

  1. Importers store exploit references with reference_type="exploit" (vulnerabilities/pipes/osv_v2.py, vulnerabilities/pipelines/v2_importers/vulnrichment_importer.py, and the ExploitDB improver). Real data carries these: vulnerabilities/tests/test_data/vulnrichment/vulnrichment-data3-expected.json contains a reference with "reference_type": "exploit".
  2. The advisory is persisted with its severities by insert_advisory_v2() → vulnerabilities/pipes/advisory.py:366, which computes risk at import time.
  3. compute_advisory_risk_score() (vulnerabilities/pipes/risk_score.py:89) passes those references and severities to compute_vulnerability_risk_factors() → get_exploitability_level().
  4. The result is stored on AdvisoryV2.exploitability / risk_score and surfaced to users in API v2/v3 (exploitability, risk_score) and in the advisory detail, vulnerability detail and package detail pages.

The v2 improver vulnerabilities/pipelines/v2_improvers/compute_package_risk.py:100 reaches the same helper the same way.

The wrong result

Computed through compute_advisory_risk_score() against real AdvisoryV2 rows in the test database — an advisory with CVSS 7.5 and EPSS 0.10 (below the 0.8 threshold) plus a published exploit reference:

advisory                weighted  exploitability  risk_score
no exploit reference         6.8             0.5         3.4
with exploit ref             6.8             0.5         3.4   <-- identical

The advisory with a known exploit is indistinguishable from one with none, and its risk score is understated by half.

The proof

Same command, same input, base versus branch. The regression test is test_exploitability_level_with_exploit_reference_and_severities in vulnerabilities/tests/test_risk.py.

python -m pytest vulnerabilities/tests/test_risk.py --no-migrations -q

On main (git stash-ed change, i.e. pristine risk.py):

E       assert 0.5 == 1
E        +  where 0.5 = get_exploitability_level(
E              exploits=None,
E              references=<VulnerabilityReferenceQuerySet [<VulnerabilityReference: https://nvd.nist.gov/vuln/detail/CVE-xxxx-xxxx2>]>,
E              severities=<BaseQuerySet [<VulnerabilitySeverity: VulnerabilitySeverity object (1)>]>)
FAILED vulnerabilities/tests/test_risk.py::test_exploitability_level_with_exploit_reference_and_severities
1 failed, 4 passed

With this branch:

.....                                                                    [100%]
5 passed

The same advisory through compute_advisory_risk_score(), before and after:

before: weighted_severity=6.8 exploitability=0.5 risk_score=3.4
after:  weighted_severity=6.8 exploitability=1.0 risk_score=6.8

The change

One line in get_exploitability_level(): the reference branch becomes a separate if guarded by exploit_level == 0.5, instead of an elif on severities.

Existing precedence is preserved exactly — exploit records still yield 2, and a high EPSS score still yields 2 and still wins over a bare exploit reference. The reference check only runs when nothing stronger has been found.

The regression test adds an EPSS severity (0.10, below the threshold) to a vulnerability that already has an exploit reference, and asserts exploitability is 1.

The pre-existing test only passed because its subject had no severities at all, which is why this went unnoticed.

What I validated

  • vulnerabilities/tests/test_risk.py — 5 passed.
  • vulnerabilities/tests/pipelines/test_compute_package_risk.py and vulnerabilities/tests/pipelines/v2_improvers/test_compute_package_risk_v2.py — passed, 7 total with the above.
  • vulnerabilities/tests/pipelines/v2_improvers as a package — 63 passed, 4 failed.

What I did not validate

  • The 4 failures in the v2 improvers package are pre-existing on main and environmental: they need PostgreSQL DISTINCT ON, which SQLite does not support. I re-ran that package with my changes stashed and got the identical 4 failures. They are not related to this change.
  • I ran against SQLite with --no-migrations, because the migration chain itself uses DISTINCT ON. I did not run against PostgreSQL.
  • I did not run the full test suite, the web tests, or the repo's linters (make check is commented out in CI). python -m pytest for the risk modules and make test are the project's own commands; I ran the former at file/package scope only.
  • I did not exercise a live import run or the pipelines' network fetches; the reproduction uses real AdvisoryV2, AdvisorySeverity and AdvisoryReference rows composed the way the importer composes them.

Note on scope

This change is deliberately limited to the reachability bug. It does not reconsider the EPSS 0.8 threshold, the weighting of EPSS into weighted_severity, or the separate open questions in #2371 and #2472 about how EPSS is modelled.

get_exploitability_level() used an elif chain, so the exploit-reference branch
was only evaluated when an advisory had no severities at all. Almost every
advisory carries at least one severity (CVSS, SSVC, EPSS, or a generic textual
rating), so a published exploit reference never raised exploitability: advisories
with a known exploit were reported as 0.5 (no exploit known) instead of 1.

The reference check now runs whenever no exploit record or high EPSS score has
already established a higher level, which keeps the existing precedence (exploit
records and high EPSS still win) while making published exploit references count.

Reported symptom, computed through compute_advisory_risk_score() on an advisory
with CVSS 7.5 and EPSS 0.10 plus an exploit reference:

    before: weighted_severity=6.8 exploitability=0.5 risk_score=3.4
    after:  weighted_severity=6.8 exploitability=1.0 risk_score=6.8

Signed-off-by: dajiaohuang <mikewushuwen@outlook.com>
@dajiaohuang
dajiaohuang marked this pull request as ready for review November 23, 2026 04:15

This branch has not been deployed

No deployments
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.

1 participant