| 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-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 let {defaultMatcher} = require("matcher"); | 20 let {defaultMatcher} = require("matcher"); |
| 21 let {BlockingFilter, RegExpFilter} = require("filterClasses"); | 21 let {BlockingFilter, RegExpFilter} = require("filterClasses"); |
| 22 let {getDecodedHostname} = require("url"); | 22 let {getDecodedHostname} = require("url"); |
| 23 | 23 |
| 24 chrome.webRequest.onHeadersReceived.addListener(function(details) | 24 chrome.webRequest.onHeadersReceived.addListener(details => |
| 25 { | 25 { |
| 26 let hostname = getDecodedHostname(new URL(details.url)); | 26 let hostname = getDecodedHostname(new URL(details.url)); |
| 27 let match = defaultMatcher.matchesAny("", RegExpFilter.typeMap.WEBSOCKET, | 27 let match = defaultMatcher.matchesAny("", RegExpFilter.typeMap.WEBSOCKET, |
| 28 hostname, false, null, true); | 28 hostname, false, null, true); |
| 29 if (match instanceof BlockingFilter) | 29 if (match instanceof BlockingFilter) |
| 30 { | 30 { |
| 31 details.responseHeaders.push({ | 31 details.responseHeaders.push({ |
| 32 name: "Content-Security-Policy", | 32 name: "Content-Security-Policy", |
| 33 // We're blocking WebSockets here by adding a connect-src restriction | 33 // We're blocking WebSockets here by adding a connect-src restriction |
| 34 // since the Chrome extension API does not allow us to intercept them. | 34 // since the Chrome extension API does not allow us to intercept them. |
| 35 // https://bugs.chromium.org/p/chromium/issues/detail?id=129353 | 35 // https://bugs.chromium.org/p/chromium/issues/detail?id=129353 |
| 36 // | 36 // |
| 37 // We also need the child-src and object-src restrictions since CSPs are | 37 // We also need the child-src and object-src restrictions since CSPs are |
| 38 // not inherited from the parent for documents with data: and blob: URLs. | 38 // not inherited from the parent for documents with data: and blob: URLs. |
| 39 // https://bugs.chromium.org/p/chromium/issues/detail?id=513860 | 39 // https://bugs.chromium.org/p/chromium/issues/detail?id=513860 |
| 40 // | 40 // |
| 41 // "http:" also includes "https:" implictly. | 41 // "http:" also includes "https:" implictly. |
| 42 // https://www.chromestatus.com/feature/6653486812889088 | 42 // https://www.chromestatus.com/feature/6653486812889088 |
| 43 value: "connect-src http:; child-src http:; object-src http:" | 43 value: "connect-src http:; child-src http:; object-src http:" |
| 44 }); | 44 }); |
| 45 return {responseHeaders: details.responseHeaders}; | 45 return {responseHeaders: details.responseHeaders}; |
| 46 } | 46 } |
| 47 }, { | 47 }, { |
| 48 urls: ["http://*/*", "https://*/*"], | 48 urls: ["http://*/*", "https://*/*"], |
| 49 types: ["main_frame", "sub_frame"] | 49 types: ["main_frame", "sub_frame"] |
| 50 }, ["blocking", "responseHeaders"]); | 50 }, ["blocking", "responseHeaders"]); |
| OLD | NEW |