Repository navigation
gh-57684: Add -P cmdline option and PYTHONSAFEPATH env var #31542
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
Next
Next commit
gh-57684: Add -P cmdline option and PYTHONSAFEPATH env var
Add the -P command line option and the PYTHONSAFEPATH environment variable to not prepend a potentially unsafe path to sys.path. * Add sys.flags.safe_path flag. * Add PyConfig.safe_path member. * Programs/_bootstrap_python.c uses config.safe_path=0. * Update subprocess._optim_args_from_interpreter_flags() to handle the -P command line option. * Modules/getpath.py sets safe_path to 1 if a "._pth" file is present.
- Loading branch information
commit 33a26d9bea391ebaca0012f4c7cafcd8b4de1a71
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
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 | ||||
|---|---|---|---|---|---|---|
|
|
@@ -257,6 +257,8 @@ Miscellaneous options | |||||
| Ignore all :envvar:`PYTHON*` environment variables, e.g. | ||||||
| :envvar:`PYTHONPATH` and :envvar:`PYTHONHOME`, that might be set. | ||||||
|
|
||||||
| See also the :option:`-P` and :option:`-I` (isolated) options. | ||||||
|
|
||||||
|
|
||||||
| .. cmdoption:: -i | ||||||
|
|
||||||
|
|
@@ -271,7 +273,9 @@ Miscellaneous options | |||||
|
|
||||||
| .. cmdoption:: -I | ||||||
|
|
||||||
| Run Python in isolated mode. This also implies -E and -s. | ||||||
| Run Python in isolated mode. This also implies :option:`-E`, :option:`-P` | ||||||
| and :option:`-s` options. | ||||||
|
|
||||||
| In isolated mode :data:`sys.path` contains neither the script's directory nor | ||||||
| the user's site-packages directory. All :envvar:`PYTHON*` environment | ||||||
| variables are ignored, too. Further restrictions may be imposed to prevent | ||||||
|
|
@@ -301,6 +305,23 @@ Miscellaneous options | |||||
| Modify ``.pyc`` filenames according to :pep:`488`. | ||||||
|
|
||||||
|
|
||||||
| .. cmdoption:: -P | ||||||
|
|
||||||
| Don't prepend a potentially unsafe path to :data:`sys.path`: | ||||||
|
|
||||||
| * ``python -m module`` command line: Don't prepend the current working | ||||||
| directory. | ||||||
| * ``python script.py`` command line: Don't prepend the script path. | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| If it's a symbolic link, resolve symbolic links. | ||||||
| * ``python -c code`` and ``python`` (REPL) command lines: Don't prepend an | ||||||
| empty string. | ||||||
|
|
||||||
| See also the :envvar:`PYTHONSAFEPATH` environment variable, and :option:`-E` | ||||||
| and :option:`-I` (isolated) options. | ||||||
|
|
||||||
| .. versionadded:: 3.11 | ||||||
|
|
||||||
|
|
||||||
| .. cmdoption:: -q | ||||||
|
|
||||||
| Don't display the copyright and version messages even in interactive mode. | ||||||
|
|
@@ -583,6 +604,14 @@ conflict. | |||||
| within a Python program as the variable :data:`sys.path`. | ||||||
|
|
||||||
|
|
||||||
| .. envvar:: PYTHONSAFEPATH | ||||||
|
|
||||||
| If this is set to a non-empty string, don't prepend a potentially unsafe | ||||||
| path to :data:`sys.path`: see the :option:`-P` option for details. | ||||||
|
|
||||||
| .. versionadded:: 3.11 | ||||||
|
|
||||||
|
|
||||||
| .. envvar:: PYTHONPLATLIBDIR | ||||||
|
|
||||||
| If this is set to a non-empty string, it overrides the :data:`sys.platlibdir` | ||||||
|
|
||||||
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
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
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
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
3 changes: 3 additions & 0 deletions
3
Misc/NEWS.d/next/Security/2022-05-04-14-32-24.gh-issue-57684.HrlDrM.rst
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,3 @@ | ||
| Add the :option:`-P` command line option and the :envvar:`PYTHONSAFEPATH` | ||
| environment variable to not prepend a potentially unsafe path to | ||
| :data:`sys.path`. Patch by Victor Stinner. |
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.
Uh oh!
There was an error while loading. Please reload this page.