Nathaniel Smith <n...@pobox.com> added the comment:

@ncoghlan: The comparison I'm worried about is specifically this one: IIUC, 
right now it's safe to run 'pip --version' in an arbitrary directory, but it's 
not safe to run 'python -m pip --version' in an arbitrary directory. Am I 
wrong? (I actually couldn't convince either version to execute arbitrary code 
in 2 minutes of trying, but that's my understanding of the discussion so far.)

If that's correct, then I don't think this is like... the hugest security bug 
ever, but... I also think that it's irresponsible for e.g. packaging.python.org 
to be recommending people run 'python -m pip' the way it does now, and we need 
to find some way to change things so our beginner docs aren't triggering 
arbitrary code execution in a rare and subtle case.

We could add a bunch of warnings to packaging.python.org, explaining about how 
the code execution can be triggered, but that seems unsatisfactory given how 
those docs are targeted at beginners, plus there are so many places around the 
internet that recommend 'python -m pip' we'd never find them all.

We could update all those docs to instead recommend 'python -Im pip', but that 
has the same problems: no-one will understand, and people won't do it.

We could stop recommending 'python -m pip' entirely, but that runs into all the 
problems that have motivated this in the first place.

So I think we should find a way to make it so 'python -m pip' *never* executes 
code from the current directory (modulo the usual caveats, like the user 
explicitly setting PYTHONPATH to an insecure value etc.).

If 'python -m mypkg.myscript' is important, maybe we can make it 'PYTHONPATH=. 
python -m mypkg.myscript', or 'python -M mypkg.myscript', or making 'python 
mypkg/myscript.py' DTRT, or... something?

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue33053>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to