Left: | ||
Right: |
LEFT | RIGHT |
---|---|
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 // Versions of Chrome < 58 the webRequest API does not intercept WebSocket | 20 // Before Chrome 58, the webRequest API did not intercept WebSocket |
Sebastian Noack
2017/03/28 19:32:29
This seems grammatically wrong. This should rather
Jon Sonesen
2017/03/28 20:10:29
Done.
| |
21 // connections see: https://crbug.com/129353 | 21 // connections (see https://crbug.com/129353). Hence we inject CSP headers, |
22 // | 22 // below, as a workaround. |
23 // Hence we inject CSP headers, below, as a workaround. | |
Sebastian Noack
2017/03/28 19:32:29
IMHO, this shouldn't be a new paragraph, as we eve
Jon Sonesen
2017/03/28 20:10:29
Done.
| |
24 if (!("WEBSOCKET" in chrome.webRequest.ResourceType)) | 23 if (!("WEBSOCKET" in chrome.webRequest.ResourceType)) |
25 { | 24 { |
26 const {defaultMatcher} = require("matcher"); | 25 const {defaultMatcher} = require("matcher"); |
27 const {BlockingFilter, RegExpFilter} = require("filterClasses"); | 26 const {BlockingFilter, RegExpFilter} = require("filterClasses"); |
28 const {getDecodedHostname} = require("url"); | 27 const {getDecodedHostname} = require("url"); |
29 const {checkWhitelisted} = require("whitelisting"); | 28 const {checkWhitelisted} = require("whitelisting"); |
30 | 29 |
31 chrome.webRequest.onHeadersReceived.addListener(details => | 30 chrome.webRequest.onHeadersReceived.addListener(details => |
32 { | 31 { |
33 let hostname = getDecodedHostname(new URL(details.url)); | 32 let hostname = getDecodedHostname(new URL(details.url)); |
34 let match = defaultMatcher.matchesAny("", RegExpFilter.typeMap.WEBSOCKET, | 33 let match = defaultMatcher.matchesAny("", RegExpFilter.typeMap.WEBSOCKET, |
35 hostname, false, null, true); | 34 hostname, false, null, true); |
36 if (match instanceof BlockingFilter && | 35 if (match instanceof BlockingFilter && |
37 !checkWhitelisted(new ext.Page({id: details.tabId}), | 36 !checkWhitelisted(new ext.Page({id: details.tabId}), |
38 ext.getFrame(details.tabId, details.frameId))) | 37 ext.getFrame(details.tabId, details.frameId))) |
39 { | 38 { |
40 details.responseHeaders.push({ | 39 details.responseHeaders.push({ |
41 name: "Content-Security-Policy", | 40 name: "Content-Security-Policy", |
42 // We're blocking WebSockets here by adding a connect-src restriction | 41 // We're blocking WebSockets here by adding a connect-src restriction |
43 // since the Chrome extension API does not allow us to intercept them. | 42 // since the Chrome extension API does not allow us to intercept them. |
44 // https://bugs.chromium.org/p/chromium/issues/detail?id=129353 | 43 // https://bugs.chromium.org/p/chromium/issues/detail?id=129353 |
45 // | 44 // |
46 // We also need the frame-src and object-src restrictions since CSPs are | 45 // We also need the frame-src and object-src restrictions since CSPs |
Sebastian Noack
2017/03/28 19:32:29
This line still seems too long.
Jon Sonesen
2017/03/28 20:10:29
Done.
| |
47 // not inherited from the parent for documents with data and blob URLs. | 46 // are not inherited from the parent for documents with data: and blob: |
Sebastian Noack
2017/03/28 19:32:29
As I explained before, please don't remove the col
Jon Sonesen
2017/03/28 20:10:29
Done.
| |
48 // https://bugs.chromium.org/p/chromium/issues/detail?id=513860 | 47 // URLs, see https://crbug.com/513860. |
49 // | 48 // |
50 // We must use the deprecated child-src directive instead of worker-src | 49 // We must use the deprecated child-src directive instead of worker-src |
51 // since that's not supported yet (as of Chrome 56.) | 50 // since that's not supported yet (as of Chrome 56.) |
52 // | 51 // |
53 // "http:" also includes "https:" implictly. | 52 // "http:" also includes "https:" implictly. |
54 // https://www.chromestatus.com/feature/6653486812889088 | 53 // https://www.chromestatus.com/feature/6653486812889088 |
55 value: "connect-src http:; child-src http:; frame-src http:; object-src http:" | 54 value: "connect-src http:; child-src http:; frame-src http:; object-src http:" |
56 }); | 55 }); |
57 return {responseHeaders: details.responseHeaders}; | 56 return {responseHeaders: details.responseHeaders}; |
58 } | 57 } |
59 }, { | 58 }, { |
60 urls: ["http://*/*", "https://*/*"], | 59 urls: ["http://*/*", "https://*/*"], |
61 // We must also intercept script requests since otherwise Web Workers can | 60 // We must also intercept script requests since otherwise Web Workers can |
62 // be abused to execute scripts for which our Content Security Policy | 61 // be abused to execute scripts for which our Content Security Policy |
63 // won't be injected. | 62 // won't be injected. |
64 // https://github.com/gorhill/uBO-Extra/issues/19 | 63 // https://github.com/gorhill/uBO-Extra/issues/19 |
65 types: ["main_frame", "sub_frame", "script"] | 64 types: ["main_frame", "sub_frame", "script"] |
66 }, ["blocking", "responseHeaders"]); | 65 }, ["blocking", "responseHeaders"]); |
67 } | 66 } |
LEFT | RIGHT |