Skip to content

fix(cvedb): deduplicate EPSS metrics on upgrade - #6190

Open
MegharajPN wants to merge 1 commit into
ossf:mainfrom
MegharajPN:fix/5490-duplicate-epss
Open

MegharajPN wants to merge 1 commit into
ossf:mainfrom
MegharajPN:fix/5490-duplicate-epss

Conversation

@MegharajPN

Copy link
Copy Markdown

Summary

  • Add the missing comma in the cve_metrics table definition.
  • Add an idempotent migration that removes duplicate (cve_number, metric_id) rows, keeping the most recently inserted value, and creates a unique index when one is missing.
  • Run the migration from init_database() and get_cvelist_if_stale().

Root cause

cve_metrics was defined without an enforced unique key in older databases (CREATE TABLE IF NOT EXISTS/latest_schema() never upgraded it), so INSERT OR REPLACE appended a new EPSS row on every refresh instead of replacing the previous value.

Tests

  • test_cve_metrics_keep_only_latest_value
  • test_init_database_deduplicates_legacy_cve_metrics (fails on the base commit)
  • pytest test/test_cvedb.py test/test_source_epss.py -q -> 27 passed, 2 skipped
  • black --check, isort --check-only, flake8, and git diff --check pass

Fixes #5490

Existing databases created before cve_metrics had a primary key could accumulate duplicate rows for the same CVE and metric. CREATE TABLE IF NOT EXISTS and latest_schema() never upgraded those tables, so INSERT OR REPLACE kept appending new EPSS scores.

Add the missing comma in the table definition, add an idempotent migration that keeps the newest row per (cve_number, metric_id) and creates a unique index if needed, and run it during database init and CVE list refresh.

Fixes ossf#5490

Signed-off-by: MegharajPN <meghrajdvg.pn253@gmail.com>

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.

fix:Duplicated EPSS data in database

1 participant