aboutsummaryrefslogtreecommitdiff
path: root/background/main.js
diff options
context:
space:
mode:
Diffstat (limited to 'background/main.js')
-rw-r--r--background/main.js33
1 files changed, 29 insertions, 4 deletions
diff --git a/background/main.js b/background/main.js
index 2e9fa50..03cd5d7 100644
--- a/background/main.js
+++ b/background/main.js
@@ -9,6 +9,7 @@
* IMPORTS_START
* IMPORT TYPE_PREFIX
* IMPORT get_storage
+ * IMPORT light_storage
* IMPORT start_storage_server
* IMPORT start_page_actions_server
* IMPORT browser
@@ -17,6 +18,7 @@
* IMPORT gen_nonce
* IMPORT inject_csp_headers
* IMPORT apply_stream_filter
+ * IMPORT filter_cookie_headers
* IMPORT is_chrome
* IMPORTS_END
*/
@@ -49,6 +51,7 @@ browser.runtime.onInstalled.addListener(init_ext);
let storage;
+let policy_observable = {};
function on_headers_received(details)
{
@@ -58,7 +61,8 @@ function on_headers_received(details)
const [pattern, settings] = query_best(storage, details.url);
const has_payload = !!(settings && settings.components);
- const allow = !has_payload && !!(settings && settings.allow);
+ const allow = !has_payload &&
+ !!(settings ? settings.allow : policy_observable.value);
const nonce = gen_nonce();
const policy = {allow, url, nonce, has_payload};
@@ -70,7 +74,7 @@ function on_headers_received(details)
skip = true;
}
- headers = inject_csp_headers(details, headers, policy);
+ headers = inject_csp_headers(headers, policy);
skip = skip || (details.statusCode >= 300 && details.statusCode < 400);
if (!skip) {
@@ -82,19 +86,40 @@ function on_headers_received(details)
return {responseHeaders: headers};
}
+function on_before_send_headers(details)
+{
+ let headers = details.requestHeaders;
+ headers = filter_cookie_headers(headers);
+ return {requestHeaders: headers};
+}
+
+const all_types = [
+ "main_frame", "sub_frame", "stylesheet", "script", "image", "font",
+ "object", "xmlhttprequest", "ping", "csp_report", "media", "websocket",
+ "other", "main_frame", "sub_frame"
+];
+
async function start_webRequest_operations()
{
storage = await get_storage();
- const extra_opts = ["blocking", "responseHeaders"];
+ const extra_opts = ["blocking"];
if (is_chrome)
extra_opts.push("extraHeaders");
browser.webRequest.onHeadersReceived.addListener(
on_headers_received,
{urls: ["<all_urls>"], types: ["main_frame", "sub_frame"]},
- extra_opts
+ extra_opts.concat("responseHeaders")
);
+
+ browser.webRequest.onBeforeSendHeaders.addListener(
+ on_before_send_headers,
+ {urls: ["<all_urls>"], types: all_types},
+ extra_opts.concat("requestHeaders")
+ );
+
+ policy_observable = await light_storage.observe_var("default_allow");
}
start_webRequest_operations();