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
10 changes: 8 additions & 2 deletions extensions/amp-analytics/0.1/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -499,8 +499,14 @@ export function mergeObjects(from, to, opt_predefinedVendorConfig) {
opt_predefinedVendorConfig || property != 'iframePing',
'iframePing config is only available to vendor config.'
);
// Only deal with own properties.
if (hasOwn(from, property)) {
// Only deal with own properties, and never let a key reach the prototype
// chain (remote/inline config is attacker reachable).
if (
hasOwn(from, property) &&
property != '__proto__' &&
property != 'constructor' &&
property != 'prototype'
) {
if (isArray(from[property])) {
if (!isArray(to[property])) {
to[property] = [];
Expand Down
14 changes: 14 additions & 0 deletions extensions/amp-analytics/0.1/test/test-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,20 @@ describes.realWin(
'foobar': {'foobar': ['abc', 'def']},
});
});

it('does not pollute the prototype via __proto__', () => {
const from = JSON.parse('{"__proto__": {"polluted": "yes"}}');
mergeObjects(from, {});
expect({}.polluted).to.be.undefined;
});

it('does not pollute the prototype via constructor', () => {
const from = JSON.parse(
'{"constructor": {"prototype": {"polluted": "yes"}}}'
);
mergeObjects(from, {});
expect({}.polluted).to.be.undefined;
});
});

describe('vendor only configs', () => {
Expand Down