-
Notifications
You must be signed in to change notification settings - Fork 983
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
Directory traversal security vulnerability in serveStatic #1910
Comments
node-restify/lib/plugins/static.js Lines 169 to 184 in 839fb4a
Because of the There should be a check if file is below opts.directory. |
The check is there: node-restify/lib/plugins/static.js Lines 92 to 93 in 839fb4a
node-restify/lib/plugins/static.js Lines 194 to 197 in 839fb4a
But the normalization of |
Seems to be also a problem with the check... And the correct error for this case would be not |
And the check could be done faster without RE-matching -> string startsWith(). |
Fixes restify#1910 Added tests to check for traversals. Reworked existing tests for making more sense.
plugins.serveStatic Fixes restifyGH-1864/restifyGH-1910
Restify Version: 8.6.1
Node.js Version: 17.6.0
Expected behaviour
Users can only request files from src/static/.
Actual behaviour
Users can request files in src/ outside of static/ by requesting
/static/../<path>
.Repro case
Imagine this directory structure:
If you want to serve files out of static/, you might write some code like this:
With the above code, an attacker can read app.js by requesting
/static/../app.js
.Note: this is hard to reproduce with curl or a browser, because they typically normalize the request path client-side. I reproduced this locally by running:
Cause
Path normalization occurs in serveStatic, after the request routing has occurred. A request for
/static/../app.js
matches the route for/static/*
.Possible fixes
appendRequestPath: true
Are you willing and able to fix this?
No
The text was updated successfully, but these errors were encountered: