118 points · by walterbell · 10y ago · 33 comments
Here's why: when encountering HTTP->HTTP redirects, wget already ignores the redirected file name and writes to the original file name that was provided in the URL. It was strangely inconsistent that it specifically didn't do this for HTTP->FTP redirects, and at the very least the behavior should be consistent by default. This is clarified in the linked release notes, and also explains why they had no hesitation in considering it a wget bug and fixing it immediately.
As for the question of whether using redirected file names is more expected and intuitive, IMO providing a URL without specifying an output filename is basically a shorthand that merges the two arguments into one.
wget by default uses the latter, appending the QSA (?foo=bar) even when not intended. Same behavior for `curl -O`. You have to use `wget --content-disposition` or `curl -O -J` to explicitly trust the filename send by the server.
e.g. if the url was along the lines of
http://example.com/dl/f3ct4t3c4c3/
what do you expect the file name to be?The path in a URL is defined as the following (https://en.wikipedia.org/wiki/Uniform_Resource_Identifier) :
A path, which contains data, usually organized in hierarchical form,
that appears as a sequence of segments separated by slashes. Such a
sequence may resemble or map exactly to a file system path, but does not
always imply a relation to one.[9] The path must begin with a single slash
(/) if an authority part was present, and may also if one was not, but must
not begin with a double slash.
You can rely on the path to be made up of parts that will not begin with a double slash, and will be separated by slashes, and be defined by a specific character set. URLs also contain a query and a fragment after the path, and the client can choose whether to keep those in the file name or not.Wget has many options which define how file names are created, mainly to better serve in mirroring large complex websites. But in general, whatever the "path" was, the final part of the path will be the file name, or a default one is provided. There are options for enforcing suffixes, creating directory structures recursively, changing accepted character sets for file names, and hundreds more options.
Whether wget prints it out is irrelevant, as it's often used in scripts.
http://lists.gnu.org/archive/html/info-gnu/2016-06/msg00004....
I had never really thought about this attack vector though. Writing to `.bash_profile` is effectively the same as writing executable code.
Though I like the whole "everything is a file" concept (I know this isn't exactly that but...), it seems like we should be striving for something safer. For example, I guess in something like Plan9 you could have wget start playing sound out of your speakers? Crazy.
File handles shouldn't cause RCE vulnerabilities, right?
I suppose sandboxing is one way of dealing with this. Another is having to explicitly "give a file" to wget and co. for editing. None of this "oh, here you go program, write to anything in my home directory".
The Windows registry is just awful, and does not offer any actual protection that the filesystem cannot provide.
Edit: Ignore this. I was blocking AWS.