Skip to content
Open
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 index.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ function createError () {
}

for (var key in props) {
if (key !== 'status' && key !== 'statusCode') {
if (key !== 'status' && key !== 'statusCode' && key !== '__proto__') {
err[key] = props[key]
}
}
Expand Down
15 changes: 15 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,21 @@ describe('createError(status)', function () {

assert.strictEqual(httpError, nativeError)
})

it('should not allow a __proto__ property to alter the prototype', function () {
var nativeError = new Error('This is a test error')

var httpError = createError(404, nativeError, JSON.parse('{"__proto__":{"evil":true}}'))

assert.strictEqual(httpError.status, 404)
assert.strictEqual(httpError.evil, undefined)

assert(httpError instanceof Error)

assert.strictEqual(Object.getPrototypeOf(httpError), Error.prototype)

assert.strictEqual(httpError, nativeError)
})
})

describe('when status 300', function () {
Expand Down