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: skip results marked as "withdrawn" #386

Merged
merged 5 commits into from
Oct 24, 2022
Merged
Show file tree
Hide file tree
Changes from all 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

* Fixed an issue where audits done with the OSV vulnerability service (`-s osv`)
were not correctly filtered by "withdrawn" status; "withdrawn" vulnerabilities
are now excluded ([#386](https://github.com/pypa/pip-audit/pull/386))

## [2.4.4]

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

id = vuln["id"]

# If the vulnerability has been withdrawn, we skip it entirely.
withdrawn_at = vuln.get("withdrawn")
if withdrawn_at is not None:
logger.debug(f"OSV vuln entry '{id}' marked as withdrawn at {withdrawn_at}")
woodruffw marked this conversation as resolved.
Show resolved Hide resolved
continue

# The summary is intended to be shorter, so we prefer it over
# details, if present. However, neither is required.
description = vuln.get("summary")
Expand Down
33 changes: 33 additions & 0 deletions test/service/test_osv.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,3 +244,36 @@ def test_osv_vuln_affected_missing(monkeypatch):
assert logger.warning.calls == [
pretend.call("OSV vuln entry 'fakeid' is missing 'affected' list")
]


def test_osv_vuln_withdrawn(monkeypatch):
logger = pretend.stub(debug=pretend.call_recorder(lambda s: None))
monkeypatch.setattr(service.osv, "logger", logger)

payload = {
"vulns": [
{
"id": "fakeid",
"withdrawn": "some-datetime",
}
],
}

response = pretend.stub(raise_for_status=lambda: None, json=lambda: payload)
post = pretend.call_recorder(lambda *a, **kw: response)

osv = service.OsvService()
monkeypatch.setattr(osv.session, "post", post)

dep = service.ResolvedDependency("foo", Version("1.0.0"))
results = dict(osv.query_all(iter([dep])))

assert len(results) == 1
assert dep in results

vulns = results[dep]
assert len(vulns) == 0

assert logger.debug.calls == [
pretend.call("OSV vuln entry 'fakeid' marked as withdrawn at some-datetime")
]