Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: inject.preload.js

Issue 29586710: Issue 5382 - Wrap DOM mutation APIs to protect frames (Closed) Base URL: https://hg.adblockplus.org/adblockpluschrome/
Patch Set: Created Oct. 23, 2017, 10:09 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * This file is part of Adblock Plus <https://adblockplus.org/>, 2 * This file is part of Adblock Plus <https://adblockplus.org/>,
3 * Copyright (C) 2006-present eyeo GmbH 3 * Copyright (C) 2006-present eyeo GmbH
4 * 4 *
5 * Adblock Plus is free software: you can redistribute it and/or modify 5 * Adblock Plus is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as 6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
8 * 8 *
9 * Adblock Plus is distributed in the hope that it will be useful, 9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 contentWindow[eventName] = checkRequest; 65 contentWindow[eventName] = checkRequest;
66 contentWindow.eval( 66 contentWindow.eval(
67 "(" + injectedToString() + ")('" + eventName + "', true);" 67 "(" + injectedToString() + ")('" + eventName + "', true);"
68 ); 68 );
69 delete contentWindow[eventName]; 69 delete contentWindow[eventName];
70 } 70 }
71 catch (e) {} 71 catch (e) {}
72 } 72 }
73 } 73 }
74 74
75 function wrapAPIForIFrame(object, api)
76 {
77 let func = object[api];
78 object[api] = function(...args)
79 {
80 let returnValue = func.apply(this, args);
81 for (let i = 0; i < window.length; i++)
82 injectIntoContentWindow(window[i]);
83 return returnValue;
84 };
85 }
86
87 function wrapPropertyAPIForIFrame(object, api)
88 {
89 let descriptor = Object.getOwnPropertyDescriptor(object, api);
90 wrapAPIForIFrame(descriptor, "set");
91 Object.defineProperty(object, api, descriptor);
92 }
93
94 wrapAPIForIFrame(Node.prototype, "appendChild");
95 wrapAPIForIFrame(Node.prototype, "insertBefore");
96 wrapAPIForIFrame(Node.prototype, "replaceChild");
97
98 wrapPropertyAPIForIFrame(Element.prototype, "innerHTML");
99
75 for (let element of [HTMLFrameElement, HTMLIFrameElement, HTMLObjectElement]) 100 for (let element of [HTMLFrameElement, HTMLIFrameElement, HTMLObjectElement])
76 { 101 {
77 let contentDocumentDesc = Object.getOwnPropertyDescriptor( 102 let contentDocumentDesc = Object.getOwnPropertyDescriptor(
78 element.prototype, "contentDocument" 103 element.prototype, "contentDocument"
79 ); 104 );
80 let contentWindowDesc = Object.getOwnPropertyDescriptor( 105 let contentWindowDesc = Object.getOwnPropertyDescriptor(
81 element.prototype, "contentWindow" 106 element.prototype, "contentWindow"
82 ); 107 );
83 108
84 // Apparently in HTMLObjectElement.prototype.contentWindow does not exist 109 // Apparently in HTMLObjectElement.prototype.contentWindow does not exist
(...skipping 311 matching lines...) Expand 10 before | Expand all | Expand 10 after
396 if (typeof sandbox != "string" || /(^|\s)allow-scripts(\s|$)/i.test(sandbox)) 421 if (typeof sandbox != "string" || /(^|\s)allow-scripts(\s|$)/i.test(sandbox))
397 { 422 {
398 let script = document.createElement("script"); 423 let script = document.createElement("script");
399 script.type = "application/javascript"; 424 script.type = "application/javascript";
400 script.async = false; 425 script.async = false;
401 script.textContent = "(" + injected + ")('" + randomEventName + "');"; 426 script.textContent = "(" + injected + ")('" + randomEventName + "');";
402 document.documentElement.appendChild(script); 427 document.documentElement.appendChild(script);
403 document.documentElement.removeChild(script); 428 document.documentElement.removeChild(script);
404 } 429 }
405 } 430 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld