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

Side by Side Diff: lib/csp.js

Issue 29378831: Issue 4953 - Ensure website isn't whitelisted before injecting CSP (Closed)
Patch Set: Created March 8, 2017, 1:40 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-2016 Eyeo GmbH 3 * Copyright (C) 2006-2016 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
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details. 12 * GNU General Public License for more details.
13 * 13 *
14 * You should have received a copy of the GNU General Public License 14 * You should have received a copy of the GNU General Public License
15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
16 */ 16 */
17 17
18 "use strict"; 18 "use strict";
19 19
20 const {defaultMatcher} = require("matcher"); 20 const {defaultMatcher} = require("matcher");
21 const {BlockingFilter, RegExpFilter} = require("filterClasses"); 21 const {BlockingFilter, RegExpFilter} = require("filterClasses");
22 const {getDecodedHostname} = require("url"); 22 const {getDecodedHostname} = require("url");
23 const {checkWhitelisted} = require("whitelisting");
23 24
24 chrome.webRequest.onHeadersReceived.addListener(details => 25 chrome.webRequest.onHeadersReceived.addListener(details =>
25 { 26 {
26 let hostname = getDecodedHostname(new URL(details.url)); 27 let hostname = getDecodedHostname(new URL(details.url));
27 let match = defaultMatcher.matchesAny("", RegExpFilter.typeMap.WEBSOCKET, 28 let match = defaultMatcher.matchesAny("", RegExpFilter.typeMap.WEBSOCKET,
28 hostname, false, null, true); 29 hostname, false, null, true);
29 if (match instanceof BlockingFilter) 30 if (match instanceof BlockingFilter &&
31 !checkWhitelisted(new ext.Page({id: details.tabId}),
32 ext.getFrame(details.tabId, details.frameId)))
30 { 33 {
31 details.responseHeaders.push({ 34 details.responseHeaders.push({
32 name: "Content-Security-Policy", 35 name: "Content-Security-Policy",
33 // We're blocking WebSockets here by adding a connect-src restriction 36 // We're blocking WebSockets here by adding a connect-src restriction
34 // since the Chrome extension API does not allow us to intercept them. 37 // since the Chrome extension API does not allow us to intercept them.
35 // https://bugs.chromium.org/p/chromium/issues/detail?id=129353 38 // https://bugs.chromium.org/p/chromium/issues/detail?id=129353
36 // 39 //
37 // We also need the frame-src and object-src restrictions since CSPs are 40 // We also need the frame-src and object-src restrictions since CSPs are
38 // not inherited from the parent for documents with data: and blob: URLs. 41 // not inherited from the parent for documents with data: and blob: URLs.
39 // https://bugs.chromium.org/p/chromium/issues/detail?id=513860 42 // https://bugs.chromium.org/p/chromium/issues/detail?id=513860
40 // 43 //
41 // We must use the deprecated child-src directive instead of worker-src 44 // We must use the deprecated child-src directive instead of worker-src
42 // since that's not supported yet (as of Chrome 56.) 45 // since that's not supported yet (as of Chrome 56.)
43 // 46 //
44 // "http:" also includes "https:" implictly. 47 // "http:" also includes "https:" implictly.
45 // https://www.chromestatus.com/feature/6653486812889088 48 // https://www.chromestatus.com/feature/6653486812889088
46 value: "connect-src http:; child-src http:; frame-src http:; object-src ht tp:" 49 value: "connect-src http:; child-src http:; frame-src http:; object-src ht tp:"
47 }); 50 });
48 return {responseHeaders: details.responseHeaders}; 51 return {responseHeaders: details.responseHeaders};
49 } 52 }
50 }, { 53 }, {
51 urls: ["http://*/*", "https://*/*"], 54 urls: ["http://*/*", "https://*/*"],
52 // We must also intercept script requests since otherwise Web Workers can 55 // We must also intercept script requests since otherwise Web Workers can
53 // be abused to execute scripts for which our Content Security Policy 56 // be abused to execute scripts for which our Content Security Policy
54 // won't be injected. 57 // won't be injected.
55 // https://github.com/gorhill/uBO-Extra/issues/19 58 // https://github.com/gorhill/uBO-Extra/issues/19
56 types: ["main_frame", "sub_frame", "script"] 59 types: ["main_frame", "sub_frame", "script"]
57 }, ["blocking", "responseHeaders"]); 60 }, ["blocking", "responseHeaders"]);
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