[Pkg-javascript-commits] [node-static] 51/151: FIX: Root Jail rejected all requests with 'Access denied'

Tonnerre Lombard tonnerre-guest at moszumanska.debian.org
Tue Jan 7 23:17:58 UTC 2014


This is an automated email from the git hooks/post-receive script.

tonnerre-guest pushed a commit to branch master
in repository node-static.

commit 09788551b5ece0380f3439a69519c577ebd002aa
Author: cimnine <mail at cimnine.ch>
Date:   Thu Aug 11 20:30:34 2011 +0200

    FIX: Root Jail rejected all requests with 'Access denied'
    
    The comparison between the root path and the filepath did reject all
    files. (At least if you .server('.') ). Fixed by resolving each path to
    an absolute path with path.resolve() and comparing absolute paths. In
    addition, this seems to me to be a saver comparison. Possibly reduces
    the cache memory footprint as the key is now the full path. (Is only
    true if previously multiple relative paths lead to the same absolute
    path.)
---
 lib/node-static.js | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/lib/node-static.js b/lib/node-static.js
index 0bed25b..c1fa5e7 100644
--- a/lib/node-static.js
+++ b/lib/node-static.js
@@ -20,7 +20,7 @@ this.indexStore = {};
 this.Server = function (root, options) {
     if (root && (typeof(root) === 'object')) { options = root, root = null }
 
-    this.root    = path.normalize(root || '.');
+    this.root    = path.resolve(root || '.');
     this.options = options || {};
     this.cache   = 3600;
 
@@ -77,7 +77,7 @@ this.Server.prototype.serveFile = function (pathname, status, headers, req, res)
     var that = this;
     var promise = new(events.EventEmitter);
 
-    pathname = this.normalize(pathname);
+    pathname = this.resolve(pathname);
 
     fs.stat(pathname, function (e, stat) {
         if (e) {
@@ -124,7 +124,7 @@ this.Server.prototype.servePath = function (pathname, status, headers, req, res,
     var that = this,
         promise = new(events.EventEmitter);
 
-    pathname = this.normalize(pathname);
+    pathname = this.resolve(pathname);
 
     // Only allow GET and HEAD requests
     if (req.method !== 'GET' && req.method !== 'HEAD') {
@@ -152,8 +152,8 @@ this.Server.prototype.servePath = function (pathname, status, headers, req, res,
     }
     return promise;
 };
-this.Server.prototype.normalize = function (pathname) {
-    return path.normalize(path.join(this.root, pathname));
+this.Server.prototype.resolve = function (pathname) {
+    return path.resolve(path.join(this.root, pathname));
 };
 this.Server.prototype.serve = function (req, res, callback) {
     var that = this,

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-static.git



More information about the Pkg-javascript-commits mailing list