Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OSV, PyPI: Do not use "details" field for vuln summaries #323

Merged
merged 5 commits into from
Jul 20, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ All versions prior to 0.0.9 are untracked.

## [Unreleased]

### Fixed

* CLI: the `--format=markdown` and `--format=columns` output formats are no
longer broken by long vulnerability descriptions from the OSV and PyPI
vulnerability sources ([#323](https://github.com/trailofbits/pip-audit/pull/323))

## [2.4.1]

### Fixed
Expand Down
4 changes: 0 additions & 4 deletions pip_audit/_service/osv.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,7 @@ def query(self, spec: Dependency) -> Tuple[Dependency, List[VulnerabilityResult]

id = vuln["id"]

# The summary is intended to be shorter, so we prefer it over
# details, if present. However, neither is required.
description = vuln.get("summary")
if description is None:
description = vuln.get("details")
woodruffw marked this conversation as resolved.
Show resolved Hide resolved
if description is None:
description = "N/A"

Expand Down
6 changes: 5 additions & 1 deletion pip_audit/_service/pypi.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,12 @@ def query(self, spec: Dependency) -> Tuple[Dependency, List[VulnerabilityResult]
# The ranges aren't guaranteed to come in chronological order
fix_versions.sort()

description = v.get("summary")
if description is None:
description = "N/A"

results.append(
VulnerabilityResult(v["id"], v["details"], fix_versions, set(v["aliases"]))
VulnerabilityResult(v["id"], description, fix_versions, set(v["aliases"]))
)

return spec, results
10 changes: 4 additions & 6 deletions test/service/test_osv.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,20 +168,18 @@ def test_osv_unsupported_schema_version(monkeypatch, version):


@pytest.mark.parametrize(
["summary", "details", "description"],
["summary", "description"],
[
("fakesummary", "fakedetails", "fakesummary"),
(None, "fakedetails", "fakedetails"),
(None, None, "N/A"),
("fakesummary", "fakesummary"),
(None, "N/A"),
],
)
def test_osv_vuln_description_fallbacks(monkeypatch, summary, details, description):
def test_osv_vuln_description_fallbacks(monkeypatch, summary, description):
payload = {
"vulns": [
{
"id": "fakeid",
"summary": summary,
"details": details,
"affected": [
{
"package": {"name": "foo", "ecosystem": "PyPI"},
Expand Down
2 changes: 1 addition & 1 deletion test/service/test_pypi.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ def json(self):
{
"aliases": ["foo", "bar"],
"id": "VULN-0",
"details": "The first vulnerability",
"summary": "The first vulnerability",
"fixed_in": ["1.1", "1.4"],
}
]
Expand Down