Left: | ||
Right: |
OLD | NEW |
---|---|
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-2017 eyeo GmbH | 3 * Copyright (C) 2006-2017 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 if (!("WEBSOCKET" in chrome.webRequest.ResourceType)) |
kzar
2017/03/28 05:38:13
Mind adding a comment to explain why you're making
Jon Sonesen
2017/03/28 13:03:14
Acknowledged.
| |
21 const {BlockingFilter, RegExpFilter} = require("filterClasses"); | 21 { |
22 const {getDecodedHostname} = require("url"); | 22 const {defaultMatcher} = require("matcher"); |
23 const {checkWhitelisted} = require("whitelisting"); | 23 const {BlockingFilter, RegExpFilter} = require("filterClasses"); |
24 const {getDecodedHostname} = require("url"); | |
25 const {checkWhitelisted} = require("whitelisting"); | |
24 | 26 |
25 chrome.webRequest.onHeadersReceived.addListener(details => | 27 chrome.webRequest.onHeadersReceived.addListener(details => |
26 { | |
27 let hostname = getDecodedHostname(new URL(details.url)); | |
28 let match = defaultMatcher.matchesAny("", RegExpFilter.typeMap.WEBSOCKET, | |
29 hostname, false, null, true); | |
30 if (match instanceof BlockingFilter && | |
31 !checkWhitelisted(new ext.Page({id: details.tabId}), | |
32 ext.getFrame(details.tabId, details.frameId))) | |
33 { | 28 { |
34 details.responseHeaders.push({ | 29 let hostname = getDecodedHostname(new URL(details.url)); |
35 name: "Content-Security-Policy", | 30 let match = defaultMatcher.matchesAny("", RegExpFilter.typeMap.WEBSOCKET, |
36 // We're blocking WebSockets here by adding a connect-src restriction | 31 hostname, false, null, true); |
37 // since the Chrome extension API does not allow us to intercept them. | 32 if (match instanceof BlockingFilter && |
38 // https://bugs.chromium.org/p/chromium/issues/detail?id=129353 | 33 !checkWhitelisted(new ext.Page({id: details.tabId}), |
39 // | 34 ext.getFrame(details.tabId, details.frameId))) |
40 // We also need the frame-src and object-src restrictions since CSPs are | 35 { |
41 // not inherited from the parent for documents with data: and blob: URLs. | 36 details.responseHeaders.push({ |
42 // https://bugs.chromium.org/p/chromium/issues/detail?id=513860 | 37 name: "Content-Security-Policy", |
43 // | 38 // We're blocking WebSockets here by adding a connect-src restriction |
44 // We must use the deprecated child-src directive instead of worker-src | 39 // since the Chrome extension API does not allow us to intercept them. |
45 // since that's not supported yet (as of Chrome 56.) | 40 // https://bugs.chromium.org/p/chromium/issues/detail?id=129353 |
46 // | 41 // |
47 // "http:" also includes "https:" implictly. | 42 // We also need the frame-src and object-src restrictions since CSPs are |
48 // https://www.chromestatus.com/feature/6653486812889088 | 43 // not inherited from the parent for documents with data: and blob: URLs . |
kzar
2017/03/28 05:38:13
Please run ESLint on your changes to catch over-lo
Jon Sonesen
2017/03/28 13:03:14
No problem, additionally what is the opinion on th
Sebastian Noack
2017/03/28 13:48:08
Without the colons, I find this rather confusing.
| |
49 value: "connect-src http:; child-src http:; frame-src http:; object-src ht tp:" | 44 // https://bugs.chromium.org/p/chromium/issues/detail?id=513860 |
50 }); | 45 // |
51 return {responseHeaders: details.responseHeaders}; | 46 // We must use the deprecated child-src directive instead of worker-src |
52 } | 47 // since that's not supported yet (as of Chrome 56.) |
53 }, { | 48 // |
54 urls: ["http://*/*", "https://*/*"], | 49 // "http:" also includes "https:" implictly. |
55 // We must also intercept script requests since otherwise Web Workers can | 50 // https://www.chromestatus.com/feature/6653486812889088 |
56 // be abused to execute scripts for which our Content Security Policy | 51 value: "connect-src http:; child-src http:; frame-src http:; object-src http:" |
57 // won't be injected. | 52 }); |
58 // https://github.com/gorhill/uBO-Extra/issues/19 | 53 return {responseHeaders: details.responseHeaders}; |
59 types: ["main_frame", "sub_frame", "script"] | 54 } |
60 }, ["blocking", "responseHeaders"]); | 55 }, { |
56 urls: ["http://*/*", "https://*/*"], | |
57 // We must also intercept script requests since otherwise Web Workers can | |
58 // be abused to execute scripts for which our Content Security Policy | |
59 // won't be injected. | |
60 // https://github.com/gorhill/uBO-Extra/issues/19 | |
61 types: ["main_frame", "sub_frame", "script"] | |
62 }, ["blocking", "responseHeaders"]); | |
63 } | |
OLD | NEW |