1
0
mirror of https://github.com/kkapsner/CanvasBlocker synced 2024-12-22 12:50:36 +01:00

Updated DOMRect protection

This commit is contained in:
kkapsner 2020-11-02 13:49:42 +01:00
parent d5417cf807
commit 701eb979ed
5 changed files with 123 additions and 31 deletions

View File

@ -5,6 +5,7 @@
"Blockiermodus", "Blockiermodus",
"Captcha", "Captcha",
"Coord", "Coord",
"Fenix",
"Funktionalitätstest", "Funktionalitätstest",
"Funktionalitätstests", "Funktionalitätstests",
"Hyrp", "Hyrp",

View File

@ -50,22 +50,18 @@
} }
const cache = {}; const cache = {};
const valueCache = [{}, {}, {}, {}, {}]; const valueCache = [{}, {}, {}, {}, {}, {}, {}];
scope.cache = { scope.cache = {
valueCache, valueCache,
X: 0, X: 0,
Y: 1, Y: 1,
WIDTH: 2, WIDTH: 2,
HEIGHT: 3, HEIGHT: 3,
OTHER: 4 OTHER: 4,
Z: 5,
W: 6,
}; };
function getFakeDomRect(window, domRect, prefs, notify){ function getFakeValue(value, i, {window, prefs, rng}){
const hash = getHash(domRect);
let cached = cache[hash];
if (!cached){
notify("fakedDOMRectReadout");
const rng = randomSupply.getRng(4, window);
const getFakeValue = function getFakeValue(value, i){
const valueHash = getValueHash(value); const valueHash = getValueHash(value);
const cache = valueCache[i]; const cache = valueCache[i];
let cachedValue = cache[valueHash]; let cachedValue = cache[valueHash];
@ -83,18 +79,50 @@
cache[fakedHash] = fakedValue; cache[fakedHash] = fakedValue;
return fakedValue; return fakedValue;
} }
}; }
cached = new domRect.constructor( scope.getFakeValue = getFakeValue;
getFakeValue(domRect.x, 0), function getFakeDomRect(window, domRect, prefs, notify){
getFakeValue(domRect.y, 1), const hash = getHash(domRect);
getFakeValue(domRect.width, 2), let cached = cache[hash];
getFakeValue(domRect.height, 3) if (!cached){
notify("fakedDOMRectReadout");
const rng = randomSupply.getRng(4, window);
const env = {window, prefs, rng};
cached = new (domRect instanceof window.SVGRect? window.DOMRectReadOnly: domRect.constructor)(
getFakeValue(domRect.x, 0, env),
getFakeValue(domRect.y, 1, env),
getFakeValue(domRect.width, 2, env),
getFakeValue(domRect.height, 3, env)
); );
cache[hash] = cached; cache[hash] = cached;
cache[getHash(cached)] = cached; cache[getHash(cached)] = cached;
} }
return cached; return cached;
} }
function getFakeDOMPoint(window, domPoint, prefs){
const env = {window, prefs, rng: randomSupply.getRng(7, window)};
return new domPoint.constructor(
getFakeValue(domPoint.x, 0, env),
getFakeValue(domPoint.y, 1, env),
getFakeValue(domPoint.z, 5, env),
getFakeValue(domPoint.w, 6, env)
);
}
function getFakeSVGPoint(window, svgPoint, prefs){
const env = {window, prefs, rng: randomSupply.getRng(2, window)};
svgPoint.x = getFakeValue(svgPoint.x, 0, env);
svgPoint.y = getFakeValue(svgPoint.y, 1, env);
return svgPoint;
}
function getFakeDOMQuad(window, domQuad, prefs, notify){
notify("fakedDOMRectReadout");
return new domQuad.constructor(
getFakeDOMPoint(window, domQuad.p1, prefs),
getFakeDOMPoint(window, domQuad.p2, prefs),
getFakeDOMPoint(window, domQuad.p3, prefs),
getFakeDOMPoint(window, domQuad.p4, prefs)
);
}
function registerCallback(args, check){ function registerCallback(args, check){
const {prefs, notify, window, original} = check; const {prefs, notify, window, original} = check;
@ -105,6 +133,18 @@
return originalValue; return originalValue;
} }
function fakePointCallback(args, check){
const {prefs, notify, window, original} = check;
const ret = args.length? original.call(this, ...args): original.call(this);
notify("fakedDOMRectReadout");
if (ret instanceof window.SVGPoint){
return getFakeSVGPoint(window, ret, prefs);
}
else {
return getFakeDOMPoint(window, ret, prefs);
}
}
scope.changedFunctions = { scope.changedFunctions = {
getClientRects: { getClientRects: {
object: ["Range", "Element"], object: ["Range", "Element"],
@ -130,14 +170,31 @@
} }
}, },
getBounds: { getBoxQuads: {
object: ["DOMQuad"], object: ["Document", "Element", "Text", "CSSPseudoElement"],
fakeGenerator: function(checker){ fakeGenerator: function(checker){
return function getBounds(){ return function getBoxQuads(){
return checkerWrapper(checker, this, arguments, registerCallback); return checkerWrapper(checker, this, arguments, function(args, check){
const {prefs, notify, window, original} = check;
const ret = args.length? original.call(this, ...args): original.call(this);
for (let i = 0; i < ret.length; i += 1){
ret[i] = getFakeDOMQuad(window, ret[i], prefs, notify);
}
return ret;
});
}; };
} }
}, },
// It seems only getBoxQuads creates a DOMQuad and this method is behind a flag.
// So the only way to create one is manually by the constructor and then no fingerprinting is possible.
// getBounds: {
// object: ["DOMQuad"],
// fakeGenerator: function(checker){
// return function getBounds(){
// return checkerWrapper(checker, this, arguments, registerCallback);
// };
// }
// },
getBBox: { getBBox: {
object: ["SVGGraphicsElement"], object: ["SVGGraphicsElement"],
fakeGenerator: function(checker){ fakeGenerator: function(checker){
@ -146,6 +203,23 @@
}; };
} }
}, },
getStartPositionOfChar: {
object: ["SVGTextContentElement"],
fakeGenerator: function(checker){
return function getStartOfChar(){
return checkerWrapper(checker, this, arguments, fakePointCallback);
};
}
},
getEndPositionOfChar: {
object: ["SVGTextContentElement"],
fakeGenerator: function(checker){
return function getEndOfChar(){
return checkerWrapper(checker, this, arguments, fakePointCallback);
};
}
},
getExtentOfChar: { getExtentOfChar: {
object: ["SVGTextContentElement"], object: ["SVGTextContentElement"],
fakeGenerator: function(checker){ fakeGenerator: function(checker){
@ -154,6 +228,14 @@
}; };
} }
}, },
getPointAtLength: {
object: ["SVGGeometryElement", "SVGPathElement"],
fakeGenerator: function(checker){
return function getPointAtLength(){
return checkerWrapper(checker, this, arguments, fakePointCallback);
};
}
},
}; };
function generateChangedDOMRectPropertyGetter(property, readonly = false){ function generateChangedDOMRectPropertyGetter(property, readonly = false){
@ -164,6 +246,7 @@
]: ]:
[ [
function(window){return window.DOMRect && window.DOMRect.prototype;}, function(window){return window.DOMRect && window.DOMRect.prototype;},
function(window){return window.SVGRect && window.SVGRect.prototype;},
function(window){return window.DOMRectReadOnly && window.DOMRectReadOnly.prototype;} function(window){return window.DOMRectReadOnly && window.DOMRectReadOnly.prototype;}
], ],
name: property, name: property,

View File

@ -114,9 +114,13 @@
{name: "DOMRect-API", level: 1}, {name: "DOMRect-API", level: 1},
"getClientRects @ domRect", "getClientRects @ domRect",
"getBoundingClientRect @ domRect", "getBoundingClientRect @ domRect",
"getBoxQuads @ domRect",
"getBounds @ domRect", "getBounds @ domRect",
"getBBox @ domRect", "getBBox @ domRect",
"getStartPositionOfChar @ domRect",
"getEndPositionOfChar @ domRect",
"getExtentOfChar @ domRect", "getExtentOfChar @ domRect",
"getPointAtLength @ domRect",
"intersectionRect @ domRect", "intersectionRect @ domRect",
"boundingClientRect @ domRect", "boundingClientRect @ domRect",
"rootBounds @ domRect", "rootBounds @ domRect",

View File

@ -1,6 +1,6 @@
Version 1.4: Version 1.4:
changes: changes:
- - updated DOMRect protection
new features: new features:
- -

View File

@ -145,6 +145,10 @@
{ {
"version": "1.4Alpha20200607", "version": "1.4Alpha20200607",
"update_link": "https://canvasblocker.kkapsner.de/versions/canvasblocker_beta-1.4Alpha20200607-an+fx.xpi" "update_link": "https://canvasblocker.kkapsner.de/versions/canvasblocker_beta-1.4Alpha20200607-an+fx.xpi"
},
{
"version": "1.4Alpha20201102",
"update_link": "https://canvasblocker.kkapsner.de/versions/canvasblocker_beta-1.4Alpha20201102-an+fx.xpi"
} }
] ]
} }