-
Notifications
You must be signed in to change notification settings - Fork 253
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Preventing prototype pollution vulnerabilities (#2115)
* Preventing prototype pollution vulnerabilities * added changelog.md * changed changelog * added each in tests * fixed test description * fixed vulnerability for add method * fixed tests and changelog as suggested
- Loading branch information
1 parent
be1ea1d
commit f1a2167
Showing
3 changed files
with
69 additions
and
0 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
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,58 @@ | ||
import { add, clear } from '../lib/metadata-delegate' | ||
|
||
// it doesn't seem easy or even impossible to check whether __proto__ keys can be overwritten | ||
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/proto | ||
// so tests are only for prototype and constructor | ||
|
||
describe('metadata delegate', () => { | ||
describe('add', () => { | ||
it.each([ | ||
{ | ||
key: 'constructor', | ||
expected: {} | ||
}, | ||
{ | ||
key: 'prototype', | ||
expected: {} | ||
} | ||
])('should not add $key keys', ({ key, expected }) => { | ||
const state = {} | ||
add(state, key, 'foo', 'bar') | ||
expect(state).toEqual(expected) | ||
}) | ||
}) | ||
|
||
describe('clear', () => { | ||
it.each([ | ||
{ | ||
key: 'constructor', | ||
state: { | ||
constructor: { | ||
foo: 'bar' | ||
} | ||
}, | ||
expected: { | ||
constructor: { | ||
foo: 'bar' | ||
} | ||
} | ||
}, | ||
{ | ||
key: 'prototype', | ||
state: { | ||
prototype: { | ||
foo: 'bar' | ||
} | ||
}, | ||
expected: { | ||
prototype: { | ||
foo: 'bar' | ||
} | ||
} | ||
} | ||
])('should not overwrite $key keys', ({ key, state, expected }) => { | ||
clear(state, key, 'foo') | ||
expect(state).toEqual(expected) | ||
}) | ||
}) | ||
}) |