Skip to content

Commit 4eff7e0

Browse files
committed
update
1 parent 66748b5 commit 4eff7e0

File tree

3 files changed

+112
-0
lines changed

3 files changed

+112
-0
lines changed

_toc.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ parts:
2929
- file: security/threatmodel
3030
- file: security/attacklandscape
3131
- file: security/limitations_of_AI
32+
- file: security/tools
33+
sections:
34+
- file: security/pip_audit
3235

3336
- caption: Practical Python Security
3437
chapters:

security/pip_audit.md

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
# pip-audit: Checking a Python Environment
2+
3+
An essential tool to assess your environment for known vulnerable dependencies is vital. A practical Python specific tool for this purpose is `pip-audit`.
4+
5+
6+
`pip-audit` is a tool for scanning Python environments for packages with known vulnerabilities. It uses the Python Packaging Advisory Database (https://github.com/pypa/advisory-database) via the PyPI JSON API as a source of vulnerability reports.
7+
([source](https://pypi.org/project/pip-audit/))
8+
9+
10+
`pip-audit` scans installed Python packages and compares them against publicly disclosed vulnerabilities from trusted advisory databases. It helps you identify packages with known security issues so that you can update, replace, or remediate them as part of your security testing process.
11+
12+
## What pip-audit Does — and Does Not Do
13+
14+
`pip-audit` analyses dependency trees, not source code. It identifies known vulnerabilities in package versions, but it does not perform static code analysis and does not examine your application logic.
15+
16+
It is important to understand its limitations:
17+
18+
* It does **not** protect you from malicious packages.
19+
* It does **not** guarantee that all dependency resolutions can be analysed statically.
20+
* It should not be considered a “secure alternative” to installing dependencies.
21+
* It may not detect vulnerabilities in external components (for example, a vulnerable shared library used by a Python package), particularly where there is no clear version linkage in advisory databases.
22+
* It does not guarantee the detection of every possible transitive exposure if that exposure is not formally associated with the Python package version itself.
23+
24+
`pip-audit` is first and foremost an simple and fast test tool for auditing tool for **known vulnerabilities in Python packages.**
25+
26+
:::{warning}
27+
`pip-audit` is **not** a static code analyser. It analyses dependency trees rather than source code and cannot guarantee complete visibility into all dependency resolution scenarios.
28+
:::
29+
30+
---
31+
32+
## Installation
33+
34+
Install `pip-audit` into your Python environment:
35+
36+
```bash
37+
python -m pip install pip-audit
38+
```
39+
40+
---
41+
42+
## Basic Usage
43+
44+
First, activate your virtual environment (recommended for security testing to avoid contaminating your system environment).
45+
46+
Then run:
47+
48+
```bash
49+
pip-audit
50+
```
51+
52+
This will:
53+
54+
* Inspect all installed packages in the current environment
55+
* Identify known vulnerabilities
56+
* Report affected versions
57+
* Provide information about available fixed versions (where applicable)
58+
59+
---
60+
61+
## Auditing a Requirements File
62+
63+
To audit dependencies defined in a requirements file:
64+
65+
```bash
66+
pip-audit -r requirements.txt
67+
```
68+
69+
This checks the resolved dependency set similarly to installing the requirements, but in an isolated context to minimise conflicts with your current environment.
70+
71+
---
72+
73+
## Using pip-audit in Security Testing
74+
75+
Within a security testing workflow, `pip-audit` should be used:
76+
77+
* During development, to detect vulnerable dependencies early
78+
* In CI/CD pipelines, to prevent introducing known vulnerable packages
79+
* During periodic security reviews of existing projects
80+
* Before release, as part of a security validation checklist
81+
82+
It is best combined with:
83+
84+
* Static code analysis tools
85+
* Dependency pinning and reproducible builds
86+
* Software composition analysis (SCA) processes
87+
* Regular dependency updates
88+
89+
In short, `pip-audit` helps you identify *known* risks in your dependency tree, but it should be part of a broader, defence-in-depth security testing strategy rather than relied upon as a single line of defence.

security/tools.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Python Security Tools
2+
3+
Some tools are essential for enhancing or validating specific aspects of Python security.
4+
5+
When identifying Python-specific vulnerabilities, it is vital to account for the language's unique characteristics. Python-specific security tools often differ fundamentally from generic solutions designed to analyse multiple languages like C, C++, or Java.
6+
7+
General-purpose cybersecurity tools frequently overlook Python-specific vulnerabilities because they fail to account for the language’s distinct syntax, semantics, and constructs.
8+
9+
:::{admonition} Distrust suites claim that can do anything
10+
:class: tip
11+
A “holy grail” tool that integrates every necessary function does not exist.
12+
13+
AI-powered tools leveraging Large Language Models (LLMs) should not be trusted blindly.
14+
:::
15+
16+
17+
Furthermore, maintaining a tool is generally more manageable when its functionality is clearly defined and capped. Without these limits, maintenance often falls behind, and the security tool itself can become a liability—or even a threat—to the codebase it is meant to protect.
18+
19+
```{tableofcontents}
20+
```

0 commit comments

Comments
 (0)