Skip to content

fix(pipes): skip OSV aliases longer than the alias column - #2556

Open
sanchit955 wants to merge 1 commit into
aboutcode-org:mainfrom
sanchit955:fix/long-osv-alias-drops-advisory
Open

sanchit955 wants to merge 1 commit into
aboutcode-org:mainfrom
sanchit955:fix/long-osv-alias-drops-advisory

Conversation

@sanchit955

Copy link
Copy Markdown

Fixes #2555

Problem

get_or_create_advisory_aliases bulk-creates every alias with no length check, but AdvisoryAlias.alias is CharField(max_length=50). An alias over 50 chars raises django.db.utils.DataError: value too long for type character varying(50) inside insert_advisory_v2, which has no try/except around the alias step — the base pipeline catches it per-advisory and logs "Failed to import advisory", so the whole advisory is silently dropped from the import.

Evidence

Scanned the OSV bulk exports for 8 ecosystems (62,291 advisories). 12 records carry an alias over 50 chars — 6 distinct SNYK-Golang ids (SNYK ids embed the full uppercase module path, so the class is open-ended):

Reproduced on current main: a minimal AdvisoryDataV2 with the real GHSA-599h-8wpj-75xj aliases raises the DataError from insert_advisory_v2.

Fix

Skip over-long aliases with an error log in get_or_create_advisory_aliases. A truncated alias would be a false identifier, so skipping keeps stored data truthful and lets the advisory import with its other aliases. Widening the column would fix the 6 known ids but a longer SNYK id re-breaks it; the skip closes the class at any length.

The same advisory also flows through the github_osv importer (same parse_advisory_data_v3 path), so one fix covers both.

Caveat: the skipped SNYK alias is genuinely lost from the record (the advisory keeps its CVE + GO aliases). If maintainers prefer a migration widening the column instead, happy to rework.

Tests

  • 2 new tests in vulnerabilities/tests/pipes/test_advisory.py: test_get_or_create_advisory_aliases_skips_overlong_alias and test_insert_advisory_v2_with_overlong_alias (real GHSA-599h aliases; asserts the advisory imports and only CVE-2021-23365 + GO-2022-0906 are stored). Both fail pre-fix with DataError and pass post-fix (verified by reverting the source change only).
  • Full test_advisory.py: 14 passed (PostgreSQL 16).
  • black --check clean on both changed files.

Signed-off-by: Sanchit dev.sanchit955@gmail.com

Over-long aliases (e.g. SNYK ids that embed the full package path)
raise DataError on insert and drop the whole advisory. GHSA-599h-8wpj-75xj
carries a 61-char SNYK alias; skip such aliases with a log instead so the
advisory still imports with its other aliases.

Signed-off-by: Sanchit <dev.sanchit955@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.

Long OSV aliases (>50 chars) break advisory import — whole advisory silently dropped

1 participant