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: 10 additions & 0 deletions extensions/amp-analytics/0.1/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -495,6 +495,16 @@ export function mergeObjects(from, to, opt_predefinedVendorConfig) {
);

for (const property in from) {
// Never merge keys that can reach Object.prototype. A remote or inline
// config returning {"__proto__": {...}} would otherwise recurse into the
// prototype and pollute it for every object on the page.
if (
property === '__proto__' ||
property === 'constructor' ||
property === 'prototype'
) {
continue;
}
userAssert(
opt_predefinedVendorConfig || property != 'iframePing',
'iframePing config is only available to vendor config.'
Expand Down
7 changes: 7 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,13 @@ describes.realWin(
'foobar': {'foobar': ['abc', 'def']},
});
});

it('does not pollute Object.prototype via __proto__', function () {
// JSON.parse produces a real own "__proto__" key, matching a remote
// config response.
mergeObjects(JSON.parse('{"__proto__": {"polluted": "yes"}}'), {});
expect({}.polluted).to.be.undefined;
});
});

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