Skip to content

Commit

Permalink
Fixed parent directory access hole.
Browse files Browse the repository at this point in the history
The parent directory regex was not strict enough.
Added unit test.
  • Loading branch information
psanford committed Sep 20, 2010
1 parent 288afdd commit a400cff
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/antinode.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ function map_request_to_local_file(req, resp) {
//if the parsed url doesn't have a pathname, default to '/'
var pathname = (url.pathname || '/');
var clean_pathname = pathname.
replace(/\.\.\//g,''). //disallow parent directory access
replace(/\.\.\.*\/\/*/g,''). //disallow parent directory access
replace(/\%20/g,' '); //convert spaces

function select_vhost() {
Expand Down
18 changes: 18 additions & 0 deletions tests/test-path-security.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
require('./common');

exports["don't allow access to files outside of basedir"] = function (test) {
antinode.start(settings, function() {
test_http(test, {
'method':'GET',
'pathname':'/....//scripthost.js',
'headers': { 'host' : 'default-host' }
}, {
'statusCode': 404,
'body':''
},
function () {
antinode.stop();
test.done();
});
});
};

0 comments on commit a400cff

Please sign in to comment.