-
-
Notifications
You must be signed in to change notification settings - Fork 814
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
fd is vulnerable to filenames with leading dashes #760
Comments
You could use the |
Certainly; the problem is with a third user who may be unaware of the leading dash issue. If |
Thank you for reporting this. I agree that we should fix this somehow. Unfortunately, this will cause breaking changes, as some people probably rely on the current format of passing arguments (I certainly do). Using absolute paths would be an easy way out, but I don't think it's desirable, especially for commands where the user sees the paths. I'd rather try to follow |
BTW, in such cases I like to link to a superb article by David A. Wheeler about dangerous filenames and managing the problem. If there is place for a "further reading" link I propose to add this one. |
The same problem actually appears with how to (safely) reproduce: > mkdir /tmp/issue-760; cd /tmp/issue-760
> touch -- '-e' 'foo.txt'
> fd -X echo
foo.txt # <-- should include '-e' as well
> fd -0 | xargs -0 echo
foo.txt # <-- same
> fd -a -X echo # workaround
/tmp/issue-760/-e /tmp/issue-760/foo.txt I think we could fix this by:
This way, we can leave the normal (interactive console) |
I'm messing around with some changes for this, The same behavior should apply to Windows, assuming it's not a path that already starts with a |
yes. whenever it's a relative path (I guess). Might make sense to validate that the same bug appears on Windows as well. |
#538 describes what I was missing, will try testing some more* |
Prepending This is my test tree:
These are my test commands:
If If no search path is provided, then the search path is Perhaps this
should instead do this:
Should Off topicI am currently writing a script for
and
(People accidentally check in I picked dash as the leading character because it has the lowest reasonable ASCII value that should belong in a file name, and therefore the files sort before all others, including
I didn't think about the Though the "random" string, above |
It is tough to get
(Though it can be done with BSD's |
I didn't know that. I will experiment. I guess I was wondering which is more desirable, this actual output:
or this imaginary output:
|
Apparently this is the way to do it:
This was helpful to figure that out: |
|
It would be quite pleasing for
|
These seem to be working:
These, IMO, are not working:
Still vulnerable?Test tree:
Actual:
Expected:
|
Maybe it is working as expected, it's not for me to decide. FilesThe most important case, file names with leading dashes, is covered in this actual output:
though my preferred expected output would be:
DirectoriesIs it worth worrying about directory names with leading dashes? Maybe not, but it seems like the next logical step to me. And, as I mentioned in an earlier comment, the following would be my preferred expected output, and I haven't (so far) thought of any downsides:
|
I suppose if you're scripting and you do something like while read i
do
fd ... "$i" ... | xargs process "$i"
done then you might want Perhaps the |
I think the goals of this issue have been achieved, and my preferred expected output should probably be a separate issue. With no search path specified, the output is protected:
When the search path is specified, then the output is not protected, but the output is what is explicitly requested:
And the output can be explicitly protected as well, by prefixing the search path with
|
Ok, thank you for the summary. I think I would consider this closed indeed. |
It got introduced since fd v8.3.0 sharkdp/fd#760
Describe the bug you encountered: When piping relative paths from
fd
to utilities likexargs
, the program does not return paths, but rather file names. For instance, in a directory containingfoo.txt
, the commandfd -t f -0 | xargs -0 -I% rm %
passesfoo.txt
to xargs rather than./foo.txt
.If the directory contains files with leading dashes, such as the file
-rf
, commands likerm
interpret this as options rather than a valid path. Certain commands have the end-of-options--
parameter, but not all do, and the burden falls on the user to use--
.find
fixes this problem by always returning absolute or relative paths; returning./-rf
would not pose a problem for further processing.Filenames with dashes are not limited to deliberately malicious constructs. I have found program-generated files in
.config
folders full of leading dashes, as well as media files saved by id, whose id happened to have a leading dash.Describe what you expected to happen: when searching by relative paths,
fd
should return paths, i.e. filenames prefixed by./
to avoid problems like the above; especially when the output offd
is in a pipeline.What version of
fd
are you using?fd 8.2.1
Which operating system / distribution are you on?
Linux 5.11.12-arch1-1 x86_64
LSB Version: 1.4
Distributor ID: Arch
Description: Arch Linux
Release: rolling
Codename: n/a
The text was updated successfully, but these errors were encountered: