summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorhackademix2020-01-09 21:42:03 +0100
committerhackademix2020-01-09 21:42:03 +0100
commitd18138c15218b4a7220207db96df18c1ac2baa33 (patch)
tree72a25b3d3e9aaa32efe6ce058f23f82676bc08b2
parent9569a4010726c1691cc9470533528b9b27138d42 (diff)
downloadnoscript-d18138c15218b4a7220207db96df18c1ac2baa33.tar.gz
noscript-d18138c15218b4a7220207db96df18c1ac2baa33.tar.xz
noscript-d18138c15218b4a7220207db96df18c1ac2baa33.zip
[Chromium] Fix SyncMessage broken by feature-policy headers.
-rw-r--r--src/lib/SyncMessage.js39
1 files changed, 31 insertions, 8 deletions
diff --git a/src/lib/SyncMessage.js b/src/lib/SyncMessage.js
index 698822c..98fe6cd 100644
--- a/src/lib/SyncMessage.js
+++ b/src/lib/SyncMessage.js
@@ -1,7 +1,7 @@
"use strict";
(() => {
- //let ENDPOINT_PREFIX = `https://sync-messages.invalid/${browser.extension.getURL("")}?`;
- let ENDPOINT_PREFIX = `https://255.255.255.255/${browser.extension.getURL("")}?`;
+ let ENDPOINT_ORIGIN = "https://255.255.255.255";
+ let ENDPOINT_PREFIX = `${ENDPOINT_ORIGIN}/${browser.extension.getURL("")}?`;
let MOZILLA = "mozSystem" in XMLHttpRequest.prototype;
if (browser.webRequest) {
@@ -45,8 +45,7 @@
let {TAB_ID_NONE} = browser.tabs;
- let obrListener = request => {
- try {
+ let onBeforeRequest = request => { try {
let {url, tabId} = request;
let params = new URLSearchParams(url.split("?")[1]);
let msgId = params.get("id");
@@ -122,6 +121,20 @@
return CANCEL;
} };
+ let onHeaderReceived = request => {
+ let replaced = "";
+ let {responseHeaders} = request;
+ for (let h of request.responseHeaders) {
+ if (h.name === "feature-policy") {
+ h.value = h.value.replace(/\b(sync-xhr\s+)([^*][^;]*)/g,
+ (all, m1, m2) => replaced =
+ `${m1}${m2.replace(/'none'/, '')} 'self'`
+ );
+ }
+ }
+ return replaced ? {responseHeaders} : null;
+ };
+
let ret = r => ({redirectUrl: `data:application/json,${JSON.stringify(r)}`})
let asyncRet = msgId => {
let result = asyncResults.get(msgId);
@@ -148,17 +161,27 @@
addListener(l) {
listeners.add(l);
if (listeners.size === 1) {
- browser.webRequest.onBeforeRequest.addListener(obrListener,
- {urls: [`${ENDPOINT_PREFIX}*`],
- types: ["xmlhttprequest"]},
+ browser.webRequest.onBeforeRequest.addListener(onBeforeRequest,
+ {
+ urls: [`${ENDPOINT_PREFIX}*`],
+ types: ["xmlhttprequest"]
+ },
["blocking"]
);
+ browser.webRequest.onHeadersReceived.addListener(onHeaderReceived,
+ {
+ urls: ["<all_urls>"],
+ types: ["main_frame", "sub_frame"]
+ },
+ ["blocking", "responseHeaders"]
+ );
}
},
removeListener(l) {
listeners.remove(l);
if (listeners.size === 0) {
- browser.webRequest.onBeforeRequest.removeListener(obrListener);
+ browser.webRequest.onBeforeRequest.removeListener(onBeforeRequest);
+ browser.webRequest.onHeadersReceived.removeListener(onHeadersReceived);
}
},
hasListener(l) {