-
Notifications
You must be signed in to change notification settings - Fork 84
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
File permission checks problematic for pipenv projects #152
Comments
Related is I think #149 But I agree, I keep hitting this and its rather irritating! :-) |
I would like to add the following:
I will update the wording in OP a little. |
I actually am also tempted to remove this feature from the plugin. It was something I added early on when I thought it might be useful - but as some others have pointed out there is not much benefit for the complexity it requires to run. |
I think in general this security feature is sensible. I think the problem in the After a recent change, it seems like it re-evaluates the file attributes even if the PWD didn't change. This makes this problem even more annoying, because every time I check out a different branch (where the |
part of the reason why this is not working correctly is that the "lenient" permission matching is not fully correct here:
The problem with this is that running I think a better fix to the problem is either remove this security warning or fix the line I've pointed to :) Would you perhaps like to give it a go? |
Instead of enforcing an arbitrary permission policy, check permissions against current umask. If permissions are changed from the default, this might be a hint that something shady is going on. Resolves MichaelAquilina#152.
@MichaelAquilina here's my take. Code may be a bit wonky and I haven't actually tested it, please let me know if it's going in the right direction though. I could potentially test it, but that would be a bit fiddly because I my experience with ZSH plugins is limited to installing them through a plugin manager. So it would be much appreciated if you could test it. Basically the idea here is to ensure the file permissions match what umask dictates instead of choosing an arbitrary permission policy ourselves. Could potentially be improved to allow default permissions or stronger, but I wanted to keep it simple to convey the idea better. Since |
(Oops, created the PR wrong originally. Added correct PR.) |
Introduction
First of all, thanks a lot for this, it's a great tool and very helpful for me!
Currently, when using
pipenv
, it refuses to switchvirtualenv
if thePipfile
's file permissions are "too weak," which I think serves little purpose. Worse, sincePipfile
is customarily committed to version control, and e.g.git
always checks out files withumask
, which is664
by default,pipenv
users will have tochmod
thePipfile
again after each checkout, which is annoying and potentially dangerous (see below).How to reproduce
Analysis
As far as I can tell, the security issue being addressed with this check was that an attacker could create a new
virtualenv
with a harmful activation script and then change the.venv
file to point to thatvirtualenv
. Withpipenv
, the path of thevirtualenv
is determined by a fixed set of rules, including a SHA256 hash of thePipfile
location and whether a.venv
file or folder exists in the project directory. This leaves an attacker with two choices:.venv
file / folder in the project directory to forcepipenv
to use that insteadvirtualenv
thatpipenv
would useNeither scenario can be protected against with the permission check on the
Pipfile
. And fortunately, if a.venv
file is present, the script already uses it as the file to check instead ofPipfile
.There is another, potentially dangerous side effect. If people get used to just doing
chmod
after each checkout, eventually they will become complacent and just do it automatically without thinking (because that's just what you need to to to get it to work). This is a problem, because the general security concern with.venv
still exists. Now, if there actually is a.venv
file with weak permissions, users may just automatically copy and run thechmod
command as they're used to doing routinely, missing that this time the file name is.venv
and notPipfile
. The.venv
file could have been written to by a malicious actor, but the user would not watch out for this because they did not think that file existed in the first place.Speculation
Does checking the
Pipfile
serve any purpose I'm not aware of, or does it simply happen "on accident" because of the way the script handles different package managers? If it does solve a legitimate purpose, checking only thePipfile
might be a security issue, because an attacker could easily modify thePipfile.lock
instead, completely circumventing the check.Conclusion
Once again, thank you for this useful little thing! I'm grateful for the continued support and that you are looking out for security pitfalls as well! I hope my feedback is helpful to the project.
The text was updated successfully, but these errors were encountered: