-
-
Notifications
You must be signed in to change notification settings - Fork 1k
doc: add CPython Threat Model and update security policy (#1803) #1901
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
Closed
nayanraj864-cmyk
wants to merge
3
commits into
python:main
from
nayanraj864-cmyk:doc-threat-model-security-policy
+83
−8
Closed
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
561c5ad
doc: add CPython Threat Model and update security policy (#1803)
nayanraj864-cmyk 32580d5
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] f004588
fix(docs): use double backticks for inline literal in threat-model.rst
nayanraj864-cmyk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,5 +8,6 @@ Security | |
| :maxdepth: 5 | ||
|
|
||
| policy | ||
| threat-model | ||
| psrt | ||
| sbom | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| .. _threat-model: | ||
|
|
||
| ==================== | ||
| CPython Threat Model | ||
| ==================== | ||
|
|
||
| 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. | ||
|
|
||
| All security vulnerability reports submitted to the :ref:`Python Security Response Team (PSRT) <psrt>` must be evaluated against this threat model prior to submission. | ||
|
|
||
|
|
||
| Interpreter Trust Model & Assumptions | ||
| -------------------------------------- | ||
|
|
||
| CPython operates under specific baseline assumptions regarding execution environment, trusted input, and security boundaries. | ||
|
|
||
| Trusted Launch Conditions | ||
| ~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
|
|
||
| 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: | ||
|
|
||
| * **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. | ||
| * **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. | ||
| * **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. | ||
|
|
||
|
|
||
| Sandboxing Untrusted Code | ||
| ~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
|
|
||
| **CPython does not support sandboxing untrusted Python code as a security boundary.** | ||
|
|
||
| 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). | ||
|
|
||
|
|
||
| Multi-Threading & Availability | ||
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
|
|
||
| * **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. | ||
| * **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. | ||
|
|
||
|
|
||
| Standard Library Module Threat Models | ||
| ------------------------------------- | ||
|
|
||
| Certain standard library modules handle untrusted data and have specific security considerations: | ||
|
|
||
| Network & TLS (``ssl``, ``urllib.request``, ``http.client``) | ||
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
|
|
||
| * **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. | ||
| * **Untrusted Data:** Remote server responses or malicious HTTP headers should not crash the interpreter or corrupt memory. | ||
|
|
||
| Data Formats & Parsing (``xml``, ``json``, ``tarfile``, ``zipfile``) | ||
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
|
|
||
| * **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. | ||
| * **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. | ||
|
|
||
|
|
||
| Process Execution (``subprocess``, ``os``) | ||
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
|
|
||
| * **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. | ||
|
|
||
|
|
||
| See Also | ||
| -------- | ||
|
|
||
| * :ref:`security-policy` | ||
| * :ref:`psrt` |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a separate change, not related to the threat model. I also don't see any particular need for it.