Skip to content

Commit 561c5ad

Browse files
doc: add CPython Threat Model and update security policy (#1803)
1 parent 9d481ef commit 561c5ad

3 files changed

Lines changed: 83 additions & 8 deletions

File tree

security/index.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,7 @@ Security
88
:maxdepth: 5
99

1010
policy
11+
threat-model
1112
psrt
1213
sbom
14+

security/policy.rst

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1+
.. _security-policy:
2+
13
===============
24
Security policy
35
===============
46

7+
58
.. important::
69

710
:ref:`Python Security Response Team <psrt>` (PSRT) members balance this work
@@ -16,11 +19,11 @@ What types of bugs are vulnerabilities?
1619
**Not all bugs are vulnerabilities.**
1720

1821
To avoid causing duplicate work for PSRT members, **all potential** reports
19-
must be evaluated against the relevant threat models
22+
must be evaluated against the :ref:`CPython Threat Model <threat-model>`
2023
prior to being submitted to the PSRT.
21-
Where possible, cite the relevant threat model to show that
22-
the latter has been considered while determining whether
23-
to report a bug as a vulnerability.
24+
Reporters must cite the relevant section of the threat model to show that
25+
it has been considered while determining whether to report a bug as a vulnerability.
26+
2427

2528
Vulnerabilities must be exploitable from code, configurations,
2629
pre-conditions, or deployments that may exist in the real world.
@@ -106,10 +109,11 @@ be formatted correctly:
106109
a proof-of-concept script that reproduces the issue and provides a clear
107110
indication of whether the vulnerability is still present (such as exiting with
108111
``1`` if vulnerable and ``0`` if not vulnerable).
109-
* When reporting large numbers or "batches" of vulnerabilities or
110-
searching for potential vulnerabilities using an LLM, you as a reporter must
111-
verify the factual validity (such as whether APIs have been hallucinated)
112-
of the content in all reports prior to submission to the PSRT.
112+
* When reporting vulnerabilities found or written using an LLM (Large Language Model),
113+
you must explicitly disclose which LLM model was used. You must also cross-check
114+
all potential findings against the :ref:`threat-model` and verify factual validity
115+
(ensuring no hallucinated APIs or false behaviors) prior to submission.
116+
113117
* Do not include severity or CVSS information in your initial report,
114118
this information will be determined by the PSRT.
115119
* Ideally, include a minimal patch with the mitigation for the report.

security/threat-model.rst

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
.. _threat-model:
2+
3+
====================
4+
CPython Threat Model
5+
====================
6+
7+
This document describes the threat model for the CPython reference implementation of the Python programming language. It defines the security boundaries, trusted capabilities, and assumptions under which CPython operates.
8+
9+
All security vulnerability reports submitted to the :ref:`Python Security Response Team (PSRT) <psrt>` must be evaluated against this threat model prior to submission.
10+
11+
12+
Interpreter Trust Model & Assumptions
13+
--------------------------------------
14+
15+
CPython operates under specific baseline assumptions regarding execution environment, trusted input, and security boundaries.
16+
17+
Trusted Launch Conditions
18+
~~~~~~~~~~~~~~~~~~~~~~~~~
19+
20+
CPython assumes that the execution environment at interpreter startup is trusted and controlled by the legitimate system user or operator. The following are **not** considered attack vectors or security vulnerabilities:
21+
22+
* **Command-Line Flags & Environment Variables:** Manipulating environment variables (such as ``PYTHONPATH``, ``PYTHONHOME``, ``PYTHONSTARTUP``) or command-line arguments is assumed to be an execution privilege of the running user.
23+
* **Local Filesystem Permissions:** Modifying installed Python packages, standard library C-extensions, or system shared libraries is an OS-level file permission issue, not a CPython vulnerability.
24+
* **Process Memory & C API:** The C-API and extensions (e.g., :mod:`ctypes`) permit direct memory access and modification. CPython does not enforce internal isolation between C extensions or Python code running in the same process.
25+
26+
27+
Sandboxing Untrusted Code
28+
~~~~~~~~~~~~~~~~~~~~~~~~~
29+
30+
**CPython does not support sandboxing untrusted Python code as a security boundary.**
31+
32+
Features intended to execute arbitrary code (such as :func:`eval`, :func:`exec`, :mod:`pickle`, :mod:`marshal`, :mod:`shelve`, and :mod:`code`) are explicitly designed to execute Python code as supplied. Escaping a Python-based sandbox or abusing documented reflection and code execution features is not a CPython vulnerability. If sandboxing is required, it must be enforced at the OS level (e.g., via containers, seccomp, or WebAssembly).
33+
34+
35+
Multi-Threading & Availability
36+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
37+
38+
* **Resource Exhaustion:** Denial of service (DoS), memory exhaustion, or CPU consumption must be triggerable with reasonably sized inputs for normal application use cases. High memory consumption resulting from processing gigabytes of data is expected.
39+
* **Race Conditions:** Thread-safety issues are bugs, but only constitute security vulnerabilities if they lead to unexpected privilege escalation or memory corruption in standard non-sandboxed operations.
40+
41+
42+
Standard Library Module Threat Models
43+
-------------------------------------
44+
45+
Certain standard library modules handle untrusted data and have specific security considerations:
46+
47+
Network & TLS (``ssl``, ``urllib.request``, ``http.client``)
48+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
49+
50+
* **Security Boundary:** The :mod:`ssl` module relies on the system's underlying OpenSSL/ LibreSSL installation. Improper TLS certificate validation or hostname verification failures are treated as security issues.
51+
* **Untrusted Data:** Remote server responses or malicious HTTP headers should not crash the interpreter or corrupt memory.
52+
53+
Data Formats & Parsing (``xml``, ``json``, ``tarfile``, ``zipfile``)
54+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
55+
56+
* **XML Parsing:** Standard :mod:`xml.etree.ElementTree` and :mod:`xml.dom.minidom` are vulnerable to XML entity expansion attacks (Billion Laughs) when parsing untrusted inputs. Users requiring secure XML parsing must use defusedxml.
57+
* **Archive Files:** Extracting untrusted archives using :mod:`tarfile` or :mod:`zipfile` without explicit path sanitization (e.g., using `filter='data'` in Python 3.12+) can overwrite arbitrary files.
58+
59+
Process Execution (``subprocess``, ``os``)
60+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
61+
62+
* **Shell Injection:** Using ``shell=True`` in :mod:`subprocess` with unsanitized user inputs exposes applications to shell injection. Passing arguments as a list with ``shell=False`` is the intended secure usage.
63+
64+
65+
See Also
66+
--------
67+
68+
* :ref:`security-policy`
69+
* :ref:`psrt`

0 commit comments

Comments
 (0)