Skip to content

Commit

Permalink
Merge pull request #699 from phanect/v13-security
Browse files Browse the repository at this point in the history
Prevent directory traversal for static file
  • Loading branch information
phanect committed Jul 27, 2015
2 parents 75a7a9f + c0e2ab9 commit 2de63b6
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
2 changes: 2 additions & 0 deletions .travis.yml
@@ -1,6 +1,8 @@
language: node_js
node_js:
- "0.12"
- "0.10"
- "iojs"

before_install:
- npm update -g npm
Expand Down
9 changes: 8 additions & 1 deletion lib/app/index.js
Expand Up @@ -176,7 +176,14 @@ var App = function () {


// Get the path to the file, decoding the request URI
staticPath = this.config.staticFilePath + decodeURIComponent(reqUrl);
staticPath = path.resolve(path.join(this.config.staticFilePath, decodeURIComponent(reqUrl)));

// Prevent directory traversal
if (staticPath.indexOf(this.config.staticFilePath) !== 0) {
this.handleNotFound(reqUrl, params, reqObj, respObj);
return;
}

// Ignore querystring
staticPath = staticPath.split('?')[0];

Expand Down
4 changes: 2 additions & 2 deletions package.json
Expand Up @@ -8,7 +8,7 @@
"MVC",
"realtime"
],
"version": "13.0.7",
"version": "13.0.8",
"author": "Matthew Eernisse <mde@fleegix.org> (http://fleegix.org)",
"dependencies": {
"barista": "0.2.x",
Expand Down Expand Up @@ -43,4 +43,4 @@
"engines": {
"node": "*"
}
}
}

0 comments on commit 2de63b6

Please sign in to comment.