#!/bin/sh # Known vulnerabilities in a Python project's dependencies VENV="/srv/myapp/.venv" PIP_AUDIT="pip-audit" # Use the full path if pip-audit isn't in root's PATH, or "/usr/bin/uv tool run pip-audit" (adjust the path to uv) to run it without installing command -v "${PIP_AUDIT%% *}" > /dev/null 2>&1 || { echo "${PIP_AUDIT%% *} not found" >&2; exit 1; } # pip-audit exits with status 1 when it finds vulnerabilities, so judge by its output instead report=$($PIP_AUDIT --path "$VENV"/lib/python3*/site-packages --format json --progress-spinner off 2> /dev/null) [ -n "$report" ] || { echo "pip-audit failed" >&2; exit 1; } echo "$report" | python3 -c ' import json, sys vulnerable = [d for d in json.load(sys.stdin)["dependencies"] if d.get("vulns")] items = ["%s %s (%s)" % (d["name"], d["version"], ", ".join(v["id"] for v in d["vulns"])) for d in vulnerable] print("%d vulnerable: %s" % (len(items), ", ".join(items)) if items else "No known vulnerabilities") '