This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Review usage of environment variables in the stdlib
Type: security Stage:
Components: Library (Lib) Versions: Python 3.8, Python 3.7, Python 3.6
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: alex, benjamin.peterson, christian.heimes, pitrou
Priority: normal Keywords:

Created on 2018-03-07 19:07 by pitrou, last changed 2022-04-11 14:58 by admin.

Messages (5)
msg313393 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2018-03-07 19:07
Python supports a mode where the interpreter ignores environment variables such as PYTHONPATH, etc.

However, there are places in the stdlib where environment-sensitive decisions are made, without regard for the ignore-environment flag.

Examples include:
- ssl.get_default_verify_paths() queries SSL_CERT_FILE and SSL_CERT_DIR
- shutil.which() queries PATH
- the tempfile module queries TMPDIR, TEMP, TMP to select the defaut directory for temporary files

Do you think those need to be sanitized?
msg313395 - (view) Author: Christian Heimes (christian.heimes) * (Python committer) Date: 2018-03-07 19:16
External libraries like sqlite may also use env vars. I know for sure OpenSSL uses SSL_CERT_FILE and SSL_CERT_DIR to override default verify locations.
msg313404 - (view) Author: Benjamin Peterson (benjamin.peterson) * (Python committer) Date: 2018-03-07 22:40
I don't think -E is a security feature. Even if the stdlib was fixed, there's tons of 3rdparty Python code that consumes os.environ.

It seems like if you really cared about not letting the environment influence a Python application, you'd just wrap python in a script that cleans out the environment before execing.
msg313405 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2018-03-07 22:41
I may be mistaken, what's the use of -E if not for security?
msg313425 - (view) Author: Benjamin Peterson (benjamin.peterson) * (Python committer) Date: 2018-03-08 07:27
It's useful if you want to hide the fact that a command is implemented in Python and don't want it to malfunction if the user has PYTHONPATH set for some reason.
History
Date User Action Args
2022-04-11 14:58:58adminsetgithub: 77200
2018-03-08 07:27:45benjamin.petersonsetmessages: + msg313425
2018-03-07 22:41:28pitrousetmessages: + msg313405
2018-03-07 22:40:11benjamin.petersonsetmessages: + msg313404
2018-03-07 22:09:30pitrousetnosy: + benjamin.peterson
2018-03-07 19:16:45christian.heimessetmessages: + msg313395
2018-03-07 19:07:32pitroucreate