-
Notifications
You must be signed in to change notification settings - Fork 18k
proposal: os/exec: return ErrDot from LookPath when argument is relative path #62572
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
Comments
If I execute a command containing a slash, then by definition the
Since this would technically be a breaking change, I think we need a high bar for making the proposed change. Is there a concrete security issue today? All of that said, is there a real use case for passing a name containing a slash to |
Yes, the LookPath documentation makes this point:
but then contradicts itself in the second paragraph:
the package documentation then makes this more confusing with:
Which makes the operation of the function extremely confusing. If you pass a relative path, it will be tried directly, but will it be returned with ErrDot, or without? I think we can just fix the documentation here, but I personally find the operation of the API to be divergent from its (seeming) intended function. In practice it seems like most people assume LookPath is either only consulting PATH, or trying absolute paths directly, but not consulting paths relative to the current directory. We've seen this multiple times where the input to LookPath is not properly sanitized as the developer expects it will not return things relative to the current directory, resulting in security issues where a tool maybe execute an arbitrary program based on the directory structure it is executed in (this was at least partially responsible for #62198). |
@rolandshoemaker The package documentation is correct as-is. It is not "using an implicit or explicit path entry relative to the current directory" because it is not using a path entry (i.e., the I will also point out that even if you make this change, developers still have to know to use With regards to the linked issue, I question whether even allowing an absolute path is really intended. To that end, it seems like the true problem isn't so much a need for |
I think this interpretation is putting a huge amount of weight on the reader properly understanding that in "this package will not resolve a program" the word resolve refers to the usage of the PATH lookup algorithm, and not simply that it will not return a relative path at all.
How would this cause divergence? Command only uses LookPath if the "name contains no path separators", i.e only if it is passed a bare program name. I think the strongest argument against my proposal is that this diverges from the semantics of most Linux shell implementations and the Windows command prompt.
This seems like a significantly more serious breaking change, no? |
The next two sentences explain further.
And later it explicitly mentions that a relative path is not an error.
So I feel the existing docs are quite clear. But it should probably have said "$PATH entry" instead of "path entry" to reinforce what it means.
Because if I pass a command name like "./go" to
You are already going to break everyone that passes a relative path to |
The package documentation for os/exec and the function documentation for LookPath detail security properties of LookPath which attempt to reduce issues around discovery of binaries in the current directory, and say that LookPath will not resolve a program "using an implicit or explicit path entry relative to the current directory" without also returning ErrDot. This is currently not entirely true.
If you are in a directory with contains a child directory,
bin
, which itself contains an executable,prog
, and you callexec.LookPath("bin/prog")
it will return"bin/prog", nil
. On the face this seems reasonable, you asked for a path relative to the current directory, and it gave it to you. The problem is this is not immediately obvious given the described security properties of LookPath, and as such makes it somewhat dangerous to make assumptions about its properties which do not hold.Based on an informal survey of a few developers, none correctly guessed the result of the example described above, with the majority assuming the result would be
"bin/prog", ErrDot
, which I think is the reasonable assumption.I propose we either make LookPath always return ErrDot if the path it is returning is not absolute (which I believe is in line with the current documentation), or update the documentation to be explicit that it will not return ErrDot if you explicitly pass a relative path (I have a somewhat strong preference for the former, but could be convinced otherwise).
The text was updated successfully, but these errors were encountered: