-
Notifications
You must be signed in to change notification settings - Fork 17.9k
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
os/exec: on Windows use NeedCurrentDirectoryForExePathW for LookPath behavior #43947
Comments
Side note: Windows has multiple ways of resolving application paths. The one that |
Sounds reasonable. |
Huh, interesting rabbit hole here. One thing I noticed is that
As an aside from the specific proposal here, this makes me wonder if instead of having exec.Command use LookPath, it should instead use that behavior of CreateProcess, and then we always do what windows does. With regards to NeedCurrentDirectoryForExePath, here's what kernelbase.dll is doing on Windows 10, translated from the x86 into Go: if strings.Index(exePath, `\`) != -1 { return true }
_, ok := os.Environ()["NoDefaultCurrentDirectoryInExePath"]
return !ok So when you write:
I'm not sure that this is actually true. Are there other versions of Windows you think I should look at? |
Is it just me or does this sound really reckless? This entire proposal arose exactly from the necessity to mitigate the risk of malicious code execution that may lurk in a current working directory (#38736, #42420, #42950 and #43724). The fact that Microsoft did stupid sh...tuff (and still does, and have been doing for ages), really does not mean we or anyone else should ape them in that, ever (again). Convenience should not take precedence over security. |
I hadn't seen #43724. I was thinking that Go wouldn't want a behavior change, and would want to keep os/exec using the defaults of whatever operating system and environment it's using. But it looks like #43724 changes that. So this issue here, I suppose, becomes one of "how can we tell when Windows is going to do something bad?" And I take it that @dolmen's suggestion is to use |
In summary: Except for the error in #43724, LookPath aims to match Windows cmd.exe. This seems unobjectionable. There was some discussion above arising from confusion about what exactly is being proposed, but that seems to have been resolved. Does anyone object to this proposal? |
Based on the discussion above, this proposal seems like a likely accept. |
No change in consensus, so accepted. 🎉 |
Change https://golang.org/cl/381374 mentions this issue: |
@rsc wrote:
This is not what this proposal is about because the case where the configuration setting is in the registry and not in the environment is not handled. This proposal is about using So CL381374 is not a correct implementation of this proposal because it only uses the environment variable. |
The above CL broke |
Change https://go.dev/cl/403058 mentions this issue: |
…ctory" This reverts CL 381374. Reason for revert: broke tests for x/sys/execabs. Updates #43724. Updates #43947. Change-Id: I9eb3adb5728dead66dbd20f6afe1e7a77e2a26f1 Reviewed-on: https://go-review.googlesource.com/c/go/+/403058 Reviewed-by: Dmitri Shuralyov <[email protected]> Run-TryBot: Dmitri Shuralyov <[email protected]> Reviewed-by: Dmitri Shuralyov <[email protected]> Auto-Submit: Dmitri Shuralyov <[email protected]> TryBot-Result: Gopher Robot <[email protected]> Auto-Submit: Bryan Mills <[email protected]>
Change https://go.dev/cl/403694 mentions this issue: |
Fixes #52666. Updates #43724. Updates #43947. Change-Id: I72cb585036b7e93cd7adbff318b400586ea97bd5 Reviewed-on: https://go-review.googlesource.com/c/go/+/403694 Reviewed-by: Russ Cox <[email protected]> Run-TryBot: Bryan Mills <[email protected]> TryBot-Result: Gopher Robot <[email protected]> Auto-Submit: Bryan Mills <[email protected]>
This appears to be done. Please comment if you disagree. |
In os/exec.LookPath use Windows function
NeedCurrentDirectoryForExePathW
to check if the environment is hardened to protect against resolution of command path in the current directory.Note that this proposal is different from just looking at the existence of a
NoDefaultCurrentDirectoryInExePath
environment variable because the function doesn't just look in the process environment variables but might also look in registry settings.This is related to:
Credit goes to @KalleOlaviNiemitalo for his/her comment in #38736.
The text was updated successfully, but these errors were encountered: