Learning center

Does an advisory that matched your package by name actually apply to it?

Only if the advisory's affected package has your package-URL type, namespace and name; a matching name alone can belong to another ecosystem. Compare the purl from your SBOM with each affected entry in the advisory. A cross-ecosystem name match can still apply when both packages ship the same code, and the advisory or the source files show that.

What identifies a package#

A package-URL (purl) names a package by its ecosystem as well as its name. The purl specification README at v1.1.1 gives the form scheme:type/namespace/name@version?qualifiers#subpath and defines the parts that matter here. type is "The package "type" or package "protocol" such as maven, npm, nuget, gem, pypi, etc." namespace is "A name prefix such as a Maven groupid, a Docker image owner, a GitHub user or organization. Namespace is type-specific." name is "The name of the package."

Each type also sets its own naming rules. The pypi type definition says the namespace is prohibited ("there is no namespace") and that the name is case-insensitive, with the rules "The name shall be lowercase." and "Replace runs of consecutive dash '-', underscore '_', or dot '.' characters with a single dash '-'". The npm type definition makes the name case-sensitive and uses the namespace for a scope: "The namespace is used for the scope of a scoped NPM package."

So pkg:pypi/bcrypt and pkg:npm/bcrypt are two different identifiers. A scanner that keys on the bare name bcrypt, or on a product string that several ecosystems share, can attach one package's advisory to the other.

Two unrelated packages named bcrypt#

The public registries show that the two bcrypt packages come from different projects:

$ npm view bcrypt name version repository.url --json
{
  "name": "bcrypt",
  "version": "6.0.0",
  "repository.url": "git+https://github.com/kelektiv/node.bcrypt.js.git"
}
$ curl -s https://pypi.org/pypi/bcrypt/4.3.0/json | python3 -c '...print name, version, project_urls...'
bcrypt 4.3.0 {'homepage': 'https://github.com/pyca/bcrypt/'}

The GitHub Advisory Database entry GHSA-5wg4-74h6-q47v (CVE-2020-7689) affects {"ecosystem": "npm", "name": "bcrypt"} with the range introduced 0, fixed 5.0.0, and says: "In bcrypt (npm package) before version 5.0.0, data is truncated wrong when its length is greater than 255 bytes." The same database has a third bcrypt, a RubyGems package, with its own advisory GHSA-f27w-vcwj-c954.

A Python service that pins bcrypt==4.3.0 matches that npm advisory on name, and 4.3.0 is below 5.0.0, so it matches on version too. A matcher keyed on names checks nothing else.

Compare purls, not names#

This constructed check uses real inputs. The SBOM comes from cyclonedx-bom 9.0.0 (cyclonedx-py requirements requirements.txt) for a requirements file pinning bcrypt==4.3.0 and OpenCC==1.1.9; note that it writes the PyPI name OpenCC as pkg:pypi/opencc, following the pypi normalization rule. The advisories are the three JSON files from the GitHub Advisory Database at commit 5a9de96. match.py maps each affected entry's ecosystem to a purl type (npm to npm, PyPI to pypi, RubyGems to gem), parses purls with packageurl-python 0.17.6 and reports two tests: name plus version range, and full purl type, namespace and name:

$ python3 match.py sbom.cdx.json adv/*.json
pkg:pypi/opencc@1.1.9    GHSA-7fqq-q52p-2jjg  advisory=pkg:npm/opencc   name+version=match  purl=no
pkg:pypi/opencc@1.1.9    GHSA-7fqq-q52p-2jjg  advisory=pkg:pypi/opencc  name+version=match  purl=match
pkg:pypi/bcrypt@4.3.0    GHSA-5wg4-74h6-q47v  advisory=pkg:npm/bcrypt   name+version=match  purl=no
pkg:pypi/bcrypt@4.3.0    GHSA-f27w-vcwj-c954  advisory=pkg:gem/bcrypt   name+version=no  purl=no

For bcrypt, the only affected entry that matches by name and version is pkg:npm/bcrypt, and its type is not pypi. That is the evidence for dismissing the finding: record the component's purl, the advisory's affected package and the registry metadata showing different source repositories.

An ecosystem-aware tool agrees. pip-audit 2.10.1, which queries PyPI's vulnerability data for PyPI packages only, flags one of the two:

$ pip-audit --no-deps --progress-spinner off -r requirements.txt
Found 1 known vulnerability in 1 package
Name   Version ID                  Fix Versions
------ ------- ------------------- ------------
opencc 1.1.9   GHSA-7fqq-q52p-2jjg 1.2.0

When the same name is the same project#

The OpenCC rows are the disconfirmation. Its advisory, GHSA-7fqq-q52p-2jjg, lists two affected packages, {"ecosystem": "npm", "name": "opencc"} and {"ecosystem": "PyPI", "name": "OpenCC"}, both fixed in 1.2.0, and reports "two CWE-125: Out-of-bounds Read issues caused by length validation failures in UTF-8 processing", one of them in MaxMatchSegmentation::Segment. If a reviewer saw only the npm entry beside a Python service and dismissed it as another ecosystem's package, they would dismiss a real finding.

Two facts show why the names match. Both registries point at one repository:

$ npm view opencc name version repository.url --json
{
  "name": "opencc",
  "version": "1.4.2",
  "repository.url": "git+https://github.com/BYVoid/OpenCC.git"
}
$ curl -s https://pypi.org/pypi/OpenCC/json | python3 -c '...print name, version, project_urls, home_page...'
OpenCC 1.4.2 {'Homepage': 'https://github.com/BYVoid/OpenCC'} https://github.com/BYVoid/OpenCC

And both packages ship the C++ file the advisory names. The npm tarball for opencc@1.1.3 and the PyPI source distribution for OpenCC==1.1.9, both below the fixed version, contain byte-identical copies:

$ sha256sum npm/package/src/MaxMatchSegmentation.cpp pypi/opencc-1.1.9/src/MaxMatchSegmentation.cpp
fb008d70321c...39e8a8a97127  npm/package/src/MaxMatchSegmentation.cpp
fb008d70321c...39e8a8a97127  pypi/opencc-1.1.9/src/MaxMatchSegmentation.cpp

The Python and Node packages are bindings over one native library, so a bug in that library reaches both. Here the advisory already lists the PyPI package, and the purl comparison confirms the match. When an advisory lists only one binding, the shared source file is the evidence for applying it to the other, and the right response is to upgrade and to ask the advisory's maintainers to add the missing package.

Decide from the purl and the source#

What the finding saysEvidence to collectDecision
Advisory matched by name; affected entry has another purl typeYour SBOM purl, the advisory's affected[].package, both registries' repository URLsDismiss when the repositories differ; record all three
Affected entry has your type but another namespacenpm scope or Maven group in both purlsDismiss; a scoped package is a different package
Affected entry matches type, namespace and normalized nameVersion against the advisory's rangesFix if the version is in range
Different type, same repository, shared native codeRegistry repository URLs and the vulnerable source file in both packagesApply the advisory; upgrade the binding you ship
Scanner gives a product string or CPE, no purlThe advisory's affected package list in a database that records ecosystemsCollect the purl mapping before deciding

When the package matches and the remaining question is which installed copy runs, the guide to duplicate package versions covers npm's nested copies. The hub guide to automated finding evidence lists the other kinds of finding this collection covers.

One month of free code review.

New organizations get one calendar month of hosted code review for private and public GitHub repositories. No card or cloud connection required. Eligibility and fair-use terms.

Start free with GitHub

Related reading