vulnerablecode
vulnerablecode copied to clipboard
Affected-by-advisories v2 page returns 500 for a purl with no matching package
Visiting the affected-by-advisories v2 page for a package that is not in the database returns a 500 instead of an empty result list.
Steps to reproduce
- Open
/affected-by-advisories/v2/pkg:pypi/[email protected](after the Altcha challenge). - The page returns HTTP 500.
What happens
AffectedByAdvisoriesListView.get_context_data looks the purl up with PackageV2.objects.for_purl(purl).first(), which returns None when there is no matching package, and passes it straight to get_fixed_package_details(). That helper dereferences package.affected_in_impacts, so it raises:
AttributeError: 'NoneType' object has no attribute 'affected_in_impacts'
(vulnerabilities/views.py:441)
Expected behaviour
The page should render with zero results, the same as any other purl with no affecting advisories. A mistyped or not-yet-imported package link should not 500.
Notes
- The same helper is also used by
PackageV2Details, but thereself.objectis neverNone(the detail view 404s first), so only this list view is affected. - The fix is a
Noneguard inget_fixed_package_details()returning an empty mapping, which the template already handles through theget_itemfilter.