-
Notifications
You must be signed in to change notification settings - Fork 146
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
More complete fix against prototype pollution
first addressed in #384
- Loading branch information
Showing
2 changed files
with
48 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
'use strict' | ||
|
||
const convict = require('../') | ||
|
||
describe('Convict prototype pollution resistance', function() { | ||
|
||
test('against __proto__', function() { | ||
const obj = {} | ||
const config = convict(obj) | ||
|
||
config.set('__proto__.polluted_proto_root', 'Polluted!') | ||
expect({}).not.toHaveProperty('polluted_proto_root') | ||
|
||
config.set('__proto__.nested.polluted_proto_nested', 'Polluted!') | ||
expect({}).not.toHaveProperty('nested') | ||
expect({}).not.toHaveProperty('nested.polluted_proto_nested') | ||
}) | ||
|
||
test('against this.constructor.prototype', function() { | ||
const obj = {} | ||
const config = convict(obj) | ||
|
||
config.set('this.constructor.prototype.polluted_constructor_prototype_root', 'Polluted!') | ||
expect({}).not.toHaveProperty('polluted_constructor_prototype_root') | ||
|
||
config.set('this.constructor.prototype.nested.polluted_constructor_prototype_nested', 'Polluted!') | ||
expect({}).not.toHaveProperty('nested') | ||
expect({}).not.toHaveProperty('nested.polluted_constructor_prototype_nested') | ||
}) | ||
|
||
}) |