-
-
Notifications
You must be signed in to change notification settings - Fork 564
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
Python sys.path security risk #13579
Comments
This comment has been minimized.
This comment has been minimized.
comment:3
Attachment: 13579_secure_tmp.patch.gz Oops, looks like we did it at the same time. |
comment:4
I'm fine with your patch. All doctests pass with both patches applied. |
Reviewer: Volker Braun, Jeroen Demeyer |
This comment has been minimized.
This comment has been minimized.
Author: Jeroen Demeyer, Volker Braun |
This comment has been minimized.
This comment has been minimized.
comment:6
I'd say that the function Why not simply put
inside the doctest? |
comment:7
In the doctests there is also the case where you check that you can read from the current dir, so you need to create a file in the tmp dir and execute in the same dir. Hence its important that the name is cached in |
comment:8
Replying to @vbraun:
I don't think we should supply an explicit working directory in There are various other things which I'd like to change, so I'll prepare a reviewer patch. |
comment:9
I'm against including a function that is unsafe by default, thats just asking for trouble. |
comment:10
Replying to @vbraun:
The insecurity is not because of |
comment:11
Its pretty difficult to reliably determine if others have write access to the directory. Your system might not use the traditional u/g/o security model but rely on one of the SELinux ACMs, or even a completely different security model. I'm in favor of removing cwd from
|
comment:12
Replying to @vbraun:
How about checking that the script is owned by the same user as the directory it is contained in? I think that would work pretty well.
I disagree. I think |
comment:13
Replying to @jdemeyer:
I think all systems on which Sage runs have at least the classic unix security model. Additions like SELinux mostly affect system services, and normally have no impact on normal users. As far as Python or Sage is concerned, I think we can still check the standard Unix permissions. |
comment:14
Well |
comment:15
I think this should be reported upstream to Python. Volker, do you intend to do this or shall I? |
Upstream: Not yet reported upstream; Will do shortly. |
comment:16
CPython handles this already, cwd is not in the path if it is run non-interactively:
CPython doesn't check for permissions of the script directory, though arguably you want the script directory in the path if you put the script there in the first place. |
comment:17
Replying to @vbraun:
The script directory ( |
comment:18
Replying to @vbraun:
I think it is very unexpected (to me at least) that CPython suddenly reads other files in the directory where the script lives. If I create a shell script in |
comment:19
Python programs often consist of multiple files that need to be imported, whereas shell scripts don't. So you can't really compare the two cases. I'm not saying that I'm entirely happy with how Python handles this, but it shows that upstream is aware of the issue and thats how they decided to deal with it. |
comment:71
I thought that file had existed before. Anyway, it looks fine, so I'll give a positive review. |
comment:72
Volker, I hope you can be happy with these patches. I know |
This comment has been minimized.
This comment has been minimized.
Attachment: 13579_sagelib.patch.gz All Sage library patches folded |
Merged: sage-5.4.rc2 |
comment:75
Replying to @jdemeyer:
I did this many times. (But of course I grew up with an idea that the worst thing that can happen to your program is that the stack of punchcards it is contained in is dropped on the floor and messed up :-)) |
comment:76
The patch breaks my patchbot, even though it is running in a safe directory. Details at #13631 |
comment:77
Yo, dudes, you missed a place for temp files.
in animate.py wasn't enough - see this ask.sagemath.org question. I've opened #13807 for this. |
comment:78
Copy-pasted from sage-release:
|
comment:79
As Volker explained, that's a feature, not a bug. |
comment:80
Replying to @jdemeyer:
Nope, the doctest shouldn't put files there (which isn't safe for simultaneous testing anyway). |
comment:81
Replying to @nexttime:
The latter four tests failed. |
comment:82
You'll always be able to make doctests fail if you point |
comment:83
Replying to @vbraun:
That's unrelated. It's IMHO pretty ok to have The test just shouldn't write the script into that directory, but instead into a "safe" subdir, just where all other doctest scripts end up. Orthogonal to the safety issue, the test could just fail because different test instances (in this case, on different machines, but sharing the test directory) use the same file at the same time. |
This comment has been minimized.
This comment has been minimized.
comment:85
Can we get rid of this patch during the Python 3 upgrade by using Python's isolated mode ( |
comment:86
There is a followup now at #26457. |
test_executable
runs various executables in/tmp
. When running a script, Python puts the directory containing that script insys.path
. Therefore, it is trivial for any user to have code executed by the user running the doctests. For example:test_executable
should securely create a temp directory and run the executable in there.Apply:
local/bin
).Reported upstream: http://bugs.python.org/issue16202
See also: ipython/ipython#7044
Upstream: Reported upstream. No feedback yet.
CC: @jdemeyer
Component: doctest coverage
Author: Jeroen Demeyer, Volker Braun
Reviewer: Volker Braun, Jeroen Demeyer, David Roe
Merged: sage-5.4.rc2
Issue created by migration from https://trac.sagemath.org/ticket/13579
The text was updated successfully, but these errors were encountered: