From 52b7659af7d5b9777b0f74f09151cddcd5065651 Mon Sep 17 00:00:00 2001 From: Sanchit Date: Mon, 30 Nov 2026 06:26:03 +0000 Subject: [PATCH] fix(pipes): skip OSV aliases longer than the alias column 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 --- vulnerabilities/pipes/advisory.py | 15 +++++++- vulnerabilities/tests/pipes/test_advisory.py | 36 ++++++++++++++++++++ 2 files changed, 50 insertions(+), 1 deletion(-) diff --git a/vulnerabilities/pipes/advisory.py b/vulnerabilities/pipes/advisory.py index fec72e66f..2b3a74972 100644 --- a/vulnerabilities/pipes/advisory.py +++ b/vulnerabilities/pipes/advisory.py @@ -50,6 +50,8 @@ from vulnerabilities.pipes.risk_score import compute_advisory_risk_score from vulnerabilities.pipes.univers_utils import get_exact_purls_v2 +logger = logging.getLogger(__name__) + def get_or_create_aliases(aliases: List) -> QuerySet: for alias in aliases: @@ -61,7 +63,18 @@ def get_or_create_advisory_aliases(aliases: List[str]) -> List[AdvisoryAlias]: existing = AdvisoryAlias.objects.filter(alias__in=aliases) existing_aliases = {a.alias for a in existing} - to_create = [AdvisoryAlias(alias=alias) for alias in aliases if alias not in existing_aliases] + max_alias_length = AdvisoryAlias._meta.get_field("alias").max_length + to_create = [] + for alias in aliases: + if alias in existing_aliases: + continue + if len(alias) > max_alias_length: + # Some OSV aliases embed the full package path (e.g. SNYK ids) + # and exceed the column; storing a truncated id would be a + # false identifier, so skip it and keep importing the advisory. + logger.error(f"Skipping alias longer than {max_alias_length} characters: {alias!r}") + continue + to_create.append(AdvisoryAlias(alias=alias)) AdvisoryAlias.objects.bulk_create(to_create, ignore_conflicts=True) return list(AdvisoryAlias.objects.filter(alias__in=aliases)) diff --git a/vulnerabilities/tests/pipes/test_advisory.py b/vulnerabilities/tests/pipes/test_advisory.py index ad98e915a..77e5ed067 100644 --- a/vulnerabilities/tests/pipes/test_advisory.py +++ b/vulnerabilities/tests/pipes/test_advisory.py @@ -226,6 +226,42 @@ def test_get_or_create_advisory_aliases(advisory_aliases): assert alias_obj.alias in advisory_aliases +@pytest.mark.django_db +def test_get_or_create_advisory_aliases_skips_overlong_alias(): + # Real OSV alias from GHSA-599h-8wpj-75xj (61 chars, over the 50-char column) + long_alias = "SNYK-GOLANG-GITHUBCOMTYKTECHNOLOGIESTYKIDENTITYBROKER-1089720" + assert len(long_alias) > 50 + aliases = get_or_create_advisory_aliases(["CVE-2021-23365", long_alias]) + assert [alias_obj.alias for alias_obj in aliases] == ["CVE-2021-23365"] + assert not AdvisoryAlias.objects.filter(alias=long_alias).exists() + + +@pytest.mark.django_db +def test_insert_advisory_v2_with_overlong_alias(): + # GHSA-599h-8wpj-75xj carries a 61-char SNYK alias; the advisory must + # still import with its other aliases instead of failing the insert. + advisory = AdvisoryDataV2( + advisory_id="GHSA-599h-8wpj-75xj", + aliases=[ + "CVE-2021-23365", + "GO-2022-0906", + "SNYK-GOLANG-GITHUBCOMTYKTECHNOLOGIESTYKIDENTITYBROKER-1089720", + ], + summary="Authentication Bypass in tyk-identity-broker", + references=[], + url="https://github.com/github/advisory-database/blob/main/advisories/github-reviewed/2022/08/GHSA-599h-8wpj-75xj/GHSA-599h-8wpj-75xj.json", + ) + obj = insert_advisory_v2( + advisory=advisory, + pipeline_id="test_pipeline_v2", + logger=TestLogger().write, + datasource_id="test", + ) + assert obj is not None + stored_aliases = sorted(a.alias for a in obj.aliases.all()) + assert stored_aliases == ["CVE-2021-23365", "GO-2022-0906"] + + @pytest.mark.django_db def test_get_or_create_advisory_references(advisory_references): refs = get_or_create_advisory_references(advisory_references)