-
-
Notifications
You must be signed in to change notification settings - Fork 17.3k
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
res.download building a wrong path when root options is set #4834
Comments
Hello, and thank you. It looks like this is primarily an issue with the documentation; As for accepting a |
Thank you for your response. I just have two questions out of curiosity: removed Enhancement or bugCurrently the library concatenates two absolute paths which I think is always not intended. To prevent this in the future one would either have to
Even if |
Hi @Fischerfredl I have to go to sleep (3am in my time zone), so I cannot respond to your questions right away, but just wanted to say I did remove a part regarding security, as if you believe there is a vulnerability here, please submit it through our security procedure so we can evaluate it. The best I can comment is that from the initial report, the changes made were acceptable to the original researcher, but if you know of additional issues, please report it to us using the security procedure so we can evaluate 👍 |
Also, I did take the time to fix the res.download documentation on expressjs.com today if you would like to review and make any pull requests if you think there is still something missing. As far as the root being prepended, it looks like this is also a bug in the old So it seems like yes, there is a bug here indeed, as well as a feature request. |
Wow, thanks for the quick reply. I am sorry if the wording of my comment triggered any alarm at your side and woke you up. Also thanks for the quick action. The documentation looks good to me! |
@dougwilson Hey man, thanks for all the hardwork. I wanted to contribute to help with the issues too. I started trying to resolve this bug, still I am not as experienced as you are so you got any suggestions where should I start from? |
Okay yeah I think did repro the same issue, @Fischerfredl is this what you meant? with res.download = Here is the example: https://stackblitz.com/edit/node-83jh6f?file=index.js |
Hello everyone!
I just ran into a bug in
res.download
which is also an inconsistency betweenres.download
andres.sendFile
.The bug
res.download
breaks for relative paths when specifying a root in the options argument. Express tries to access the following path:{options.root}/{process.cwd()}/{path}
. Expected is{options.root}/{path}
Example
In the example below I try to access the file
/dev/null
. The following Error is raised when navigating to/download
res.sendFile
works as expected.Expectation
My assumption that
res.download
should behave likeres.sendFile
is based on the following line of the documentationCause
Problematic is the following line in res.download: /lib/response.js:575:
The resolve method is imported from the 'path' module: https://nodejs.org/api/path.html#pathresolvepaths This is where the current working directory gets added. Anyway
res.sendFile
won't allow relative paths at all without a root specified. So I suggest to leave out thepath.resolve
call at all for a breaking release. For a non breaking fix one could only callpath.resolve
if root is not set in options.Research
I have only looked briefly but have not found this fixed in the 5.x branch.
The text was updated successfully, but these errors were encountered: