Skip to content

Prevent DoS attack #213

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

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions lib/node-static.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,9 @@ Server.prototype.servePath = function (pathname, status, headers, req, res, fini
pathname = this.resolve(pathname);

// Make sure we're not trying to access a
// file outside of the root.
if (pathname.indexOf(that.root) === 0) {
// file outside of the root or an invalid
// pathname.
if (pathname.indexOf(that.root) === 0 && pathname.indexOf('\u0000') === -1) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if you would do this like this, it should be somehow at least logging that this type of path has been ignored i think.

is there some documentation on this vulnerability and have there been other fixes to this exploit in other open-source codebases?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't log paths like ../ either; I just modeled my code after the existing code.

I'm not aware of documentation of this problem. I became aware of it because someone attacked my server with it.

fs.stat(pathname, function (e, stat) {
if (e) {
finish(404, {});
Expand Down