
Most Python projects today run on a stack they did not fully choose. You install a web framework, and it pulls in twenty transitive packages. Each of those packages pulls in more. A typical Django or Flask application can end up with 60 to 150 installed distributions once you count everything, and most developers have never read the source of more than a handful of them. When one of those packages is compromised, the vulnerability does not announce itself. It simply ships to your production server on the next deploy. That is the problem open source python security tools exist to solve. The good news is that the ecosystem is mature in 2026. You can scan for known CVEs, detect malicious packages before they are installed, check your lockfiles for drift, and run static analysis on your own code, all without paying a license fee. The harder part is knowing which tool answers which question, and where each one falls short. Many teams run one scanner, feel covered, and miss entire categories of risk. This article walks through the tools I actually use on client and personal projects, explains what each one catches and what it misses, and gives you a practical audit workflow you can run this afternoon. I will include a worked example with real numbers so you can see what a first scan usually turns up. Along the way I will point to a few LionScripts resources where they fit naturally, because the same audit discipline applies to WordPress plugins, browser extensions, and the other software sitting on your machines.
Key Takeaways
- Audit at two layers: known vulnerabilities in your dependency tree, and the integrity of the packages themselves (typosquatting, hijacked releases, malicious install scripts).
- No single open source scanner covers everything. Pair
pip-auditor OSV-based tooling withBanditfor code issues and a secrets scanner likedetect-secretsorgitleaks.- Pin exact versions with a lockfile and hash verification (
pip-toolsoruvwith--require-hashes). Unpinned dependencies make every scan a snapshot of a moving target.- Scan on three triggers: every pull request, every scheduled run (weekly is a sane default), and before every production deploy.
- Treat a clean scan as a statement about known issues only. Zero findings does not mean zero risk.
- Give every finding an owner and a disposition: upgrade, mitigate, accept with an expiry date, or ignore with a written reason.
What Does a Python Dependency Security Audit Actually Check?
A dependency audit answers three questions: are any of my installed packages affected by a publicly known vulnerability, are any of them malicious or impostors, and are my installs reproducible and tamper-evident. Each question needs different tooling. Conflating them is the most common mistake I see in teams that say they "do security scanning."
Here is how I break the work down:
- Known vulnerability matching. Compare installed versions against advisory databases such as the OSV database, PyPA advisories, and NVD entries. This is what most people mean by "scanning."
- Package integrity and supply chain risk. Detect typosquatted names (for example,
reqeustsinstead ofrequests), packages with suspicious install-time code, maintainers who changed recently, and releases that do not match the source repository. - Reproducibility. Confirm that what you tested is what you deployed. This means lockfiles, pinned hashes, and no unpinned transitive surprises.
- First-party code issues. Static analysis of your own code for injection, unsafe deserialization, weak cryptography, and hardcoded secrets. Dependencies are only part of your attack surface.
Which Open Source Python Security Tools Should You Use?
The table below compares the tools I have used most in production audits. The criteria are the ones that actually changed my decisions: what data source the tool uses, whether it reads lockfiles or only the live environment, how well it handles transitive dependencies, whether it can run offline or in air-gapped CI, how noisy its output is, and how active the project is.
| Tool | Primary purpose | Data source | Transitive deps | Offline / air-gapped | Typical noise level |
|---|---|---|---|---|---|
pip-audit (PyPA) |
Known CVE matching for Python environments and requirements files | PyPI JSON API and OSV | Yes, resolves full tree | Partial (can use a local vulnerability cache) | Low to moderate |
safety (open source CLI) |
CVE checks with a curated database | Safety DB (free tier has a delay on newest advisories) | Yes | Limited | Moderate |
osv-scanner (Google) |
Multi-ecosystem vulnerability scanning against OSV | OSV database | Yes, from lockfiles | Yes, with downloaded data | Low |
Bandit |
Static security linting of your own Python code | Local AST analysis | Not applicable | Fully offline | Moderate, needs tuning |
detect-secrets / gitleaks |
Finding committed credentials and API keys | Local pattern and entropy rules | Not applicable | Fully offline | Low with a baseline file |
My default stack for a typical web service is pip-audit plus osv-scanner for vulnerability matching (they use overlapping but not identical data, and the disagreements are informative), Bandit for first-party code, and detect-secrets with a committed baseline. For a single-maintainer project, that is enough to catch the vast majority of issues that would realistically bite you.
Why run two vulnerability scanners?
Advisory databases differ in coverage and timeliness. In one audit last year, pip-audit flagged a vulnerable version of a templating dependency that osv-scanner did not yet have in its local snapshot, and the reverse happened for a different package. Running both costs you five extra minutes in CI and occasionally catches something real. If you can only run one, use the tool that reads your lockfile directly, because environment-based scans miss packages that are declared but not installed.
How Do You Run a Full Python Dependency Audit? (Step-by-Step)
The following walkthrough works on a Linux or macOS machine with Python 3.11 or newer. Windows users can run the same commands inside WSL or PowerShell with minor path changes.
- Create an isolated environment. Run
python -m venv .audit-venvand activate it. Install the scanners there so they do not contaminate your project environment:pip install pip-audit bandit detect-secrets. - Export a clean dependency list. If you use
pip-tools, compile frompyproject.tomlorrequirements.inwithpip-compile --generate-hashes. If you useuv, runuv export --format requirements-txt --no-hashes > audit-reqs.txt. The key is that the file lists every transitive package with an exact version. - Run the vulnerability scan against the lockfile. Execute
pip-audit -r requirements.txt --format json -o pip-audit-report.json. The JSON output is easier to diff across runs than the table view. - Run a second vulnerability scanner. Execute
osv-scanner --lockfile=requirements.txt --format json --output osv-report.json. Compare the two reports. Any CVE present in one and absent from the other deserves a manual check against the advisory page. - Check the installed environment for drift. Create a fresh venv, install from the lockfile with
pip install --require-hashes -r requirements.txt, then runpip-auditwithout arguments. This catches cases where the lockfile says one thing and the real environment says another, which happens more often than teams admit. - Scan first-party code. Run
bandit -r src/ -f json -o bandit-report.json. Ignore the low-severity findings on your first pass. Focus on high-severity items such assubprocesscalls withshell=Truebuilt from user input,pickle.loadson untrusted data, andyaml.loadwithout a safe loader. - Look for committed secrets. Run
detect-secrets scan > .secrets.baselineon the first run to record existing findings, thendetect-secrets-hookin pre-commit so new secrets are blocked. Review the baseline by hand and rotate anything real. - Triage every finding. For each item, record one of four dispositions: upgrade (preferred), mitigate (for example, the vulnerable function is not reachable from your code), accept with an expiry date (say, 60 days), or ignore with a written reason. Store these decisions in a file such as
SECURITY-EXCEPTIONS.mdso the next auditor knows what was decided and why.
Worked Example: What a First Scan Usually Finds
Consider a mid-sized internal API. It has 14 direct dependencies declared in pyproject.toml. After resolution, the lockfile contains 71 packages. The team had never run a scanner before.
Here is a realistic breakdown of what a first scan might return, based on the pattern I see in most audits of projects that are a few years old:
- 71 packages scanned, 9 with at least one known advisory.
- Of those 9, 6 are transitive dependencies that the team never named directly. Two of the six were fixed in releases that the direct dependency had not yet picked up.
- 3 findings are high severity. One is in a YAML parser used only in a config loader, which the team can mitigate by enforcing safe loading. One is in an HTTP client with a request smuggling issue that requires a specific proxy setup; the team confirms they do not run behind that proxy and records an accepted-risk exception with a 90-day expiry. One is a clear upgrade.
- Bandit flags 22 items. After triage, 4 are real: one
shell=Truecall that interpolates a filename from an upload, oneMD5used for something that is actually a security token, and two debug endpoints left enabled. - detect-secrets finds one committed staging database password in an old commit. Rotating it takes ten minutes. The rest of the cleanup is the git history rewrite decision, which the team defers.
The total effort to go from "never scanned" to "triaged and tracked" was roughly two
Cover image: Software by I.Gouss, licensed under BY-SA 2.0 via Openverse.








