Skip to content
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
"morgan": "1.12.1",
"nyc": "^17.1.0",
"pbkdf2-password": "1.2.1",
"supertest": "^6.3.0",
"supertest": "^7.3.0",
"vhost": "~3.0.2"
},
"engines": {
Expand Down
4 changes: 2 additions & 2 deletions test/acceptance/downloads.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@

var app = require('../../examples/downloads')
, request = require('supertest');
var utils = require('../support/utils');

describe('downloads', function(){
describe('GET /', function(){
Expand Down Expand Up @@ -39,8 +40,7 @@ describe('downloads', function(){

describe('GET /files/../index.js', function () {
it('should respond with 403', function (done) {
request(app)
.get('/files/../index.js')
utils.getRawPath(request(app), '/files/../index.js')
.expect(403, done)
})
})
Expand Down
15 changes: 5 additions & 10 deletions test/express.static.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,7 @@ describe('express.static()', function () {
})

it('should support ../', function (done) {
request(this.app)
.get('/users/../todo.txt')
utils.getRawPath(request(this.app), '/users/../todo.txt')
.expect(200, '- groceries', done)
})

Expand Down Expand Up @@ -269,8 +268,7 @@ describe('express.static()', function () {
})

it('should fall-through when traversing past root', function (done) {
request(this.app)
.get('/users/../../todo.txt')
utils.getRawPath(request(this.app), '/users/../../todo.txt')
.expect(404, 'Not Found', done)
})

Expand Down Expand Up @@ -344,8 +342,7 @@ describe('express.static()', function () {
})

it('should 403 when traversing past root', function (done) {
request(this.app)
.get('/users/../../todo.txt')
utils.getRawPath(request(this.app), '/users/../../todo.txt')
.expect(403, /ForbiddenError/, done)
})

Expand Down Expand Up @@ -578,14 +575,12 @@ describe('express.static()', function () {
})

it('should catch urlencoded ../', function (done) {
request(this.app)
.get('/users/%2e%2e/%2e%2e/todo.txt')
utils.getRawPath(request(this.app), '/users/%2e%2e/%2e%2e/todo.txt')
.expect(403, done)
})

it('should not allow root path disclosure', function (done) {
request(this.app)
.get('/users/../../fixtures/todo.txt')
utils.getRawPath(request(this.app), '/users/../../fixtures/todo.txt')
.expect(403, done)
})
})
Expand Down
15 changes: 15 additions & 0 deletions test/support/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,21 @@ exports.shouldHaveHeader = shouldHaveHeader
exports.shouldNotHaveBody = shouldNotHaveBody
exports.shouldNotHaveHeader = shouldNotHaveHeader;
exports.shouldSkipQuery = shouldSkipQuery
exports.getRawPath = getRawPath

/**
* Send a GET request without URL dot-segment normalization.
*
* @param {object} agent SuperTest request factory
* @param {string} path Request path
* @returns {object} SuperTest request
*/

function getRawPath (agent, path) {
return agent.get(path).on('request', function (test) {
test.req.path = path
})
}

/**
* Assert that a supertest response has a specific body.
Expand Down
Loading