Skip to content

Commit 3956ef9

Browse files
authored
PEP 829: A few last DPO thread updates (#4911)
1 parent 850f4f7 commit 3956ef9

File tree

1 file changed

+29
-5
lines changed

1 file changed

+29
-5
lines changed

peps/pep-0829.rst

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ have used arbitrary code execution in ``.pth`` files as an attack vector.
3030
This PEP doesn't completely close this vector, but it does propose an
3131
important and useful improvement, by narrowing the attack surface and enabling
3232
a future policy mechanism for controlling which packages are allowed or
33-
prevented from extending the path and executing start up code.
33+
prevented from extending the path and executing start up code. See
34+
:ref:`security` for additional discussion.
3435

3536

3637
Motivation
@@ -90,10 +91,12 @@ This PEP proposes the following:
9091

9192
During the deprecation period, for any ``<name>.pth`` file without a
9293
matching ``<name>.start`` file, the processing of the former is unchanged,
93-
although a warning about ``import`` lines is issued. After the deprecation
94-
period ``import`` lines in ``<name>.pth`` files are ignored and a warning is
95-
issued, regardless of whether there is a matching ``<name>.start`` file or
96-
not.
94+
although a warning about ``import`` lines is issued when ``-v`` (verbose)
95+
flag is given to Python.
96+
97+
After the deprecation period ``import`` lines in ``<name>.pth`` files are
98+
ignored and a warning is issued, regardless of whether there is a matching
99+
``<name>.start`` file or not.
97100

98101
See the :ref:`teach` section for specific migration guidelines.
99102

@@ -113,6 +116,10 @@ both files.
113116
all path extensions, preserving order file-by-file and then by entry
114117
appearance. Duplicates are ignored.
115118

119+
#. During the deprecation period, collect ``import`` lines found from
120+
``<name>.pth`` files. Processing of these lines is deferred until after
121+
``<name>.start`` file scanning.
122+
116123
#. *Future extension:* apply a :ref:`global policy filter <future>` on the
117124
list of path extensions.
118125

@@ -121,6 +128,10 @@ both files.
121128
#. List all ``<name>.start`` files (see :ref:`discovery` for additional
122129
details) and sort them in alphabetical order by filename.
123130

131+
For any ``<name>.start`` that matches a previously scanned ``<name>.pth``
132+
file, discard all ``import`` lines from those matched ``<name>.pth`` files.
133+
See the :ref:`teach` section for more details and rationale.
134+
124135
#. Parse the ``<name>.start`` files in sorted order, keeping a global list of
125136
all entry points, preserving order file-by-file and then by entry
126137
appearance. Duplicates are :ref:`not ignored <duplicate-eps>`.
@@ -290,6 +301,7 @@ utilize the ``import`` line arbitrary code execution feature of current
290301
importable module inside the package, and then name this callable in an entry
291302
point specification inside a ``<name>.start`` file.
292303

304+
.. _security:
293305

294306
Security Implications
295307
=====================
@@ -299,6 +311,10 @@ This PEP improves the security posture of interpreter startup.
299311
* The removal of arbitrary code execution by :func:`exec` with entry point
300312
execution, which is more constrained and auditable.
301313

314+
* Splitting ``sys.path`` extensioni from code execution into two separate
315+
files means that you can tell by listing the files in the site-dir, exactly
316+
where arbitrary code execution occurs.
317+
302318
* Python's import system is used to access and run the entry points, so the
303319
standard audit hooks (:pep:`578`) can provide monitoring.
304320

@@ -414,6 +430,14 @@ Open Issues
414430
Change History
415431
==============
416432

433+
``TBD``
434+
435+
* During the deprecation period, warnings about ``import`` lines in
436+
``<name>.pth`` files with no matching ``<name>.start`` file are only issued
437+
when ``-v`` (verbose) is given.
438+
* Clarify that ``import`` lines in ``<name>.pth`` files where there is a
439+
matching ``<name>.start`` file are ignored.
440+
417441
`13-Apr-2026 <https://discuss.python.org/t/pep-829-structured-startup-configuration-files/106789/69>`__
418442

419443
* Changed the PEP title.

0 commit comments

Comments
 (0)