New submission from Jeroen Demeyer:

There is a serious security problem with Python's default sys.path.  If I 
execute

$ python /tmp/somescript.py

then Python will add /tmp as sys.path[0], such that an "import foobar" will 
cause Python to read /tmp/foobar (or variations).  This vulnerability exists in 
particular in distutils.util.byte_compile() with direct=False.  Since the 
Python test suite calls this function, users running the Python test suite are 
vulnerable.

I think the root of this issue should be fixed: Python should not simply add 
stuff to sys.path without checking.  In prepared a patch for CPython-2.7 which 
only adds sys.path[0] if it seems secure to do so, by looking at file/directory 
permissions and ownership.  In particular, it would never add /tmp to sys.path, 
but it would still keep the current behaviour when running a script in a 
directory owned by the current user with 0755 permissions.  See the patch for 
details.

I realize this goes against documented Python behaviour, but I think that a 
broken spec needs to be fixed.  I also think that in most use cases, nothing is 
going to change because normally one doesn't need to import from /tmp.  In any 
case, users can still manipulate sys.path directly.

Feel free to fix this issue in a different way than my patch, but I hope you at 
least implement the spirit of my patch.  The patch has only been tested on 
Linux systems.

Credit goes to Volker Braun for first discovering this issue in Sage, see 
http://trac.sagemath.org/sage_trac/ticket/13579

----------
components: Interpreter Core
files: sys_path_security.patch
keywords: patch
messages: 172686
nosy: jdemeyer
priority: normal
severity: normal
status: open
title: sys.path[0] security issues
type: security
versions: Python 2.7
Added file: http://bugs.python.org/file27536/sys_path_security.patch

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

Reply via email to