Skip to content
This repository has been archived by the owner on Jul 11, 2023. It is now read-only.

fix(SearchParameters): ignore invalid parameters #880

Merged
merged 2 commits into from Oct 19, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 8 additions & 2 deletions src/functions/merge.js
Expand Up @@ -21,7 +21,10 @@ function _merge(target, source) {
}

for (var key in source) {
if (!Object.prototype.hasOwnProperty.call(source, key)) {
if (
!Object.prototype.hasOwnProperty.call(source, key) ||
key === '__proto__'
) {
continue;
}

Expand All @@ -32,7 +35,10 @@ function _merge(target, source) {
continue;
}

if (isObjectOrArrayOrFunction(targetVal) && isObjectOrArrayOrFunction(sourceVal)) {
if (
isObjectOrArrayOrFunction(targetVal) &&
isObjectOrArrayOrFunction(sourceVal)
) {
target[key] = _merge(targetVal, sourceVal);
} else {
target[key] = clone(sourceVal);
Expand Down
13 changes: 13 additions & 0 deletions test/spec/functions/defaultsPure.js
Expand Up @@ -92,3 +92,16 @@ it('should keep the keys order when adding facet refinements', function() {
);
expect(Object.keys(actual)).toEqual(['facet1', 'facet2']);
});

it('does not pollute the prototype', () => {
var payload = JSON.parse('{"__proto__": {"polluted": "vulnerable to PP"}}');
var subject = {};

expect(subject.polluted).toBe(undefined);
Haroenv marked this conversation as resolved.
Show resolved Hide resolved

const out = defaults({}, payload);

expect(out).toEqual({});

expect(subject.polluted).toBe(undefined);
Haroenv marked this conversation as resolved.
Show resolved Hide resolved
});
1 change: 0 additions & 1 deletion test/spec/functions/intersection.js
Expand Up @@ -18,4 +18,3 @@ test('it should not produce duplicate primitive values', function() {
'2'
]);
});

13 changes: 13 additions & 0 deletions test/spec/functions/merge.js
Expand Up @@ -170,3 +170,16 @@ it('should not convert strings to arrays when merging arrays of `source`', funct

expect(actual).toStrictEqual({a: ['x', 'y', 'z']});
});

it('does not pollute the prototype', () => {
var payload = JSON.parse('{"__proto__": {"polluted": "vulnerable to PP"}}');
var subject = {};
Haroenv marked this conversation as resolved.
Show resolved Hide resolved

expect(subject.polluted).toBe(undefined);
Haroenv marked this conversation as resolved.
Show resolved Hide resolved

const out = merge({}, payload);

expect(out).toEqual({});

expect(subject.polluted).toBe(undefined);
Haroenv marked this conversation as resolved.
Show resolved Hide resolved
});