-
-
Notifications
You must be signed in to change notification settings - Fork 29
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
Windows: Program a
, a.<ext>
should not resolve to current working directory
#164
Comments
How is the behavior of cmd.exe and powershell in this regard? If they do pick the cwd binary I'd say let's not break this behavior maybe since this may cause issues for existing users? |
Thanks for the comment and concern, yes, let's explore it!
So why did Microsoft make this change in PowerShell?TLDR: Security If I try to run
Interesting part:
If I run the suggested
So why does ProcessBuilder behave the way it does on Windows?I have not read the JDK source, but I it is an abstraction over CreateProcess which is lower level. Perhaps relevant:
What should babashka/process do on Windows?It attempts to compensate for executable extension resolution (.i.e., it will resolve But for directory resolution, here are the options I currently see: Option 1: Mimic CMD Shell and ProcessBuilder behaviourPro: consistent with CMD Shell Option 2: Mimic PowerShell (and macOS/Linux) behaviourPro: could be considered more secure ProposalSince babashka process does not handle resolving from the cwd consistently today and would require fixes to do so, and for the pros listed above, I would recommend Option 2. If a user really wants a CMD Shell-type resolution, they can always provide their own This proposal includes clarifications of program resolution behaviour on Windows in README. Whaddya think? |
OK, option 2 it is! |
After [some careful study](https://github.com/lread/info-process-builder/blob/main/README.adoc#program-resolution), I now understand the underlying behaviour of ProcessBuilder on Windows. It has some nuances: - it resolves from the current dir before PATH (which CMD Shell does too - but PowerShell opted not to do for security reasons) - it only resolves `a` to `a.exe` - and has what seem to be bugs wrt to resolving when a `directory` working dir is specified These oddities were sometimes leaking through to babashka process when run from Windows. We now entirely take over the program resolution for Windows in our default `:program-resolver` which now matches the behaviour of PowerShell (with the exception of launching `.ps1` files, we do not do that), macOS and Linux. Note that the default `:program-resolver` is also employed for `exec` on all OSes. Because it matches macOS/Linux behaviour this does not present any problems. Tests now thoroughly exercise program resolution via explicitly constructed scenarios instead of awkwardly relying on what happens to be on the PATH. See new test-resources dir README for some details. Bb tasks adjusted accordingly to setup the `PATH` for tests. New `dev:bb` and `dev:jvm` tasks added to launch nREPLs with this same setup. README is updated with new section on Program Resolution. Closes babashka#163 Closes babashka#164
Default `BABASHKA_TEST_ENV` to `jvm` for libtests CI already understands this need, but defaulting in-script avoids having devs to understand/remember it too. Alter PATH as required for new babashka.process tests. In support of babashka/process#163, babashka/process#164
Default `BABASHKA_TEST_ENV` to `jvm` for libtests CI already understands this need, but defaulting in-script avoids having devs to understand/remember it too. Alter PATH as required for new babashka.process tests. In support of babashka/process#163, babashka/process#164
Setup
On Windows, using clj-msi, from a CMD shell, from an empty dir, create
a.bat
with the following content in the current directory:@echo off echo hello
then launch a REPL:
Base Repro
Expected Behaviour
Should throw an exception for file not found.
Unless the current working directory is on the PATH, invoking
a.bat
should require a path prefix, for example:Note that invoking
a
for this scenario throws as expected:Repro Twist
If we add
a.exe
to the current working directory.a.go
source:Built with:
As with
a.bat
,a.exe
errantly resolves:But the twist is that
a
no longer throws and resolves toa.exe
:Next Steps
I'll handle this with #163
The text was updated successfully, but these errors were encountered: