mirror of
https://github.com/kkapsner/CanvasBlocker
synced 2025-01-03 10:31:54 +01:00
Preventing double interception
This commit is contained in:
parent
95bb415f86
commit
79a9034051
52
lib/frame.js
52
lib/frame.js
@ -7,7 +7,7 @@
|
|||||||
const settings = require("./settings");
|
const settings = require("./settings");
|
||||||
const {preIntercept: intercept} = require("./intercept");
|
const {preIntercept: intercept} = require("./intercept");
|
||||||
const {ask} = require("./askForPermission");
|
const {ask} = require("./askForPermission");
|
||||||
const lists = require("./lists");
|
const {sha256String: hashing} = require("./hash");
|
||||||
const {check: originalCheck, checkStack: originalCheckStack} = require("./check");
|
const {check: originalCheck, checkStack: originalCheckStack} = require("./check");
|
||||||
const {getWrapped} = require("./modifiedAPIFunctions");
|
const {getWrapped} = require("./modifiedAPIFunctions");
|
||||||
const extension = require("./extension");
|
const extension = require("./extension");
|
||||||
@ -44,6 +44,33 @@
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let extensionSecret;
|
||||||
|
function computeExtensionSecret(){
|
||||||
|
function hashString(string){
|
||||||
|
return hashing(new Uint16Array(
|
||||||
|
string.split("").map(function(c){
|
||||||
|
return c.charCodeAt(0);
|
||||||
|
})
|
||||||
|
));
|
||||||
|
}
|
||||||
|
const now = new Date();
|
||||||
|
const lastTenMinutes = Math.floor(now.getMinutes() / 10) * 10;
|
||||||
|
const nextRun = new Date(
|
||||||
|
now.getFullYear(), now.getMonth(), now.getDate(),
|
||||||
|
now.getHours(), lastTenMinutes + 10, 0, 0
|
||||||
|
);
|
||||||
|
window.setTimeout(
|
||||||
|
computeExtensionSecret,
|
||||||
|
nextRun .getTime() - now.getTime()
|
||||||
|
);
|
||||||
|
|
||||||
|
let string =
|
||||||
|
extension.extensionID +
|
||||||
|
`${now.getFullYear()}-${now.getMonth() + 1}-${now.getDate()} ${now.getHours()}:${lastTenMinutes}`;
|
||||||
|
extensionSecret = [hashString("input" + string), hashString(string + "output")];
|
||||||
|
}
|
||||||
|
computeExtensionSecret();
|
||||||
|
|
||||||
message("open port to background script");
|
message("open port to background script");
|
||||||
var port = browser.runtime.connect();
|
var port = browser.runtime.connect();
|
||||||
if (window === window.top){
|
if (window === window.top){
|
||||||
@ -106,8 +133,13 @@
|
|||||||
warning("NOT intercepting window due to SOP", window);
|
warning("NOT intercepting window due to SOP", window);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
const wrappedWindow = getWrapped(window);
|
||||||
|
|
||||||
if (!enabled || interceptedWindows.get(getWrapped(window))){
|
if (!enabled || interceptedWindows.get(wrappedWindow)){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (wrappedWindow.matchMedia(extensionSecret[0]) === extensionSecret[1]){
|
||||||
|
interceptedWindows.set(wrappedWindow, true);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -153,7 +185,21 @@
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
interceptedWindows.set(getWrapped(window), true);
|
const matchMediaDescriptor = Object.getOwnPropertyDescriptor(wrappedWindow, "matchMedia");
|
||||||
|
const originalMatchMedia = matchMediaDescriptor.value;
|
||||||
|
matchMediaDescriptor.value = exportFunction(function matchMedia(query){
|
||||||
|
if (query === extensionSecret[0]){
|
||||||
|
return extensionSecret[1];
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return arguments.length > 1?
|
||||||
|
originalMatchMedia.apply(this, wrappedWindow.Array.from(arguments)):
|
||||||
|
originalMatchMedia.call(this, query);
|
||||||
|
}
|
||||||
|
}, window);
|
||||||
|
Object.defineProperty(wrappedWindow, "matchMedia", matchMediaDescriptor);
|
||||||
|
|
||||||
|
interceptedWindows.set(wrappedWindow, true);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -23,6 +23,7 @@ Version 0.5.9:
|
|||||||
- fixed description for "show notifications"
|
- fixed description for "show notifications"
|
||||||
- improved DOMRect performance
|
- improved DOMRect performance
|
||||||
- improved general performance when stack list is disabled
|
- improved general performance when stack list is disabled
|
||||||
|
- preventing double interception (increased performance and reduced detectability)
|
||||||
|
|
||||||
known issues:
|
known issues:
|
||||||
- if a data URL is blocked the page action button does not appear
|
- if a data URL is blocked the page action button does not appear
|
||||||
|
Loading…
x
Reference in New Issue
Block a user