1
0
mirror of https://github.com/kkapsner/CanvasBlocker synced 2024-05-29 09:28:06 +02:00

respect RFP setting in isPointInPath and isPointInStroke

Fixes #189
This commit is contained in:
kkapsner 2018-05-26 15:36:55 +02:00
parent f02246128e
commit 52e44e0eb2
4 changed files with 44 additions and 15 deletions

View File

@ -316,9 +316,14 @@
return function isPointInPath(x, y){ return function isPointInPath(x, y){
var rng = randomSupply.getRng(1, window); var rng = randomSupply.getRng(1, window);
var originalValue = original.apply(this, window.Array.from(arguments)); var originalValue = original.apply(this, window.Array.from(arguments));
var value = rng(originalValue, x + this.width * y); if ((typeof originalValue) === "boolean"){
notify.call(this, "fakedReadout"); notify.call(this, "fakedReadout");
return !!(value & 1); var index = x + this.width * y;
return original.call(this, rng(x, index), rng(y, index));
}
else {
return originalValue;
}
}; };
} }
}, },
@ -334,9 +339,14 @@
return function isPointInStroke(x, y){ return function isPointInStroke(x, y){
var rng = randomSupply.getRng(1, window); var rng = randomSupply.getRng(1, window);
var originalValue = original.apply(this, window.Array.from(arguments)); var originalValue = original.apply(this, window.Array.from(arguments));
var value = rng(originalValue, x + this.width * y); if ((typeof originalValue) === "boolean"){
notify.call(this, "fakedReadout"); notify.call(this, "fakedReadout");
return !!(value & 1); var index = x + this.width * y;
return original.call(this, rng(x, index), rng(y, index));
}
else {
return originalValue;
}
}; };
} }
}, },

View File

@ -6,7 +6,7 @@ Version 0.4.6:
- Added setting to whitelist parts of the canvas API - Added setting to whitelist parts of the canvas API
fixes: fixes:
- - respect resistFingerPrinting setting in isPointInPath and isPointInStroke
Version 0.4.5b: Version 0.4.5b:
known issues: known issues:

View File

@ -8,13 +8,13 @@
<div id="top"> <div id="top">
<h1>top Test</h1> <h1>top Test</h1>
<img class="display"><br> <img class="display"><br>
Hash: <span class="hash"></span> Hash: <span class="hash"></span> (isPointInPath: <span class="isPointInPath"></span>)
<button>refresh</button> <button>refresh</button>
</div> </div>
<div id="iframe"> <div id="iframe">
<h1>iFrame Test. Thanks to DocumentRoot.</h1> <h1>iFrame Test. Thanks to DocumentRoot.</h1>
<img class="display"><br> <img class="display"><br>
Hash: <span class="hash"></span> Hash: <span class="hash"></span> (isPointInPath: <span class="isPointInPath"></span>)
<iframe sandbox="allow-same-origin" style="display:none"></iframe> <iframe sandbox="allow-same-origin" style="display:none"></iframe>
<button>refresh</button> <button>refresh</button>
</div> </div>
@ -22,7 +22,7 @@
<div id="iframe2"> <div id="iframe2">
<h1>iFrame Test 2 - with URL</h1> <h1>iFrame Test 2 - with URL</h1>
<img class="display"><br> <img class="display"><br>
Hash: <span class="hash"></span> Hash: <span class="hash"></span> (isPointInPath: <span class="isPointInPath"></span>)
<iframe src="?" sandbox="allow-same-origin" style="display:none"></iframe> <iframe src="?" sandbox="allow-same-origin" style="display:none"></iframe>
<button>refresh</button> <button>refresh</button>
</div> </div>
@ -30,7 +30,7 @@
<div id="iframe3"> <div id="iframe3">
<h1>iFrame Test 3 - violating SOP</h1> <h1>iFrame Test 3 - violating SOP</h1>
<img class="display"><br> <img class="display"><br>
Hash: <span class="hash"></span> Hash: <span class="hash"></span> (isPointInPath: <span class="isPointInPath"></span>)
<iframe src="http://example.org" style="display:none"></iframe> <iframe src="http://example.org" style="display:none"></iframe>
<button>refresh</button> <button>refresh</button>
</div> </div>

View File

@ -2,7 +2,7 @@
(function(){ (function(){
"use strict"; "use strict";
function show(container, url){ function show(container, {url, isPointInPath}){
var display = container.querySelector(".display"); var display = container.querySelector(".display");
display.src = url; display.src = url;
display.title = url; display.title = url;
@ -16,6 +16,7 @@
return "0".repeat(8 - chunk.length) + chunk; return "0".repeat(8 - chunk.length) + chunk;
}).join(""); }).join("");
}); });
container.querySelector(".isPointInPath").textContent = isPointInPath;
} }
if (location.search !== "?notInitial"){ if (location.search !== "?notInitial"){
@ -64,14 +65,29 @@ function draw(canvas){
return ctx; return ctx;
} }
function getIsPointInPath(ctx){
"use strict";
ctx.beginPath();
ctx.moveTo(20, 19);
ctx.lineTo(40, 19);
ctx.lineTo(30, 30);
ctx.closePath();
ctx.stroke();
return ctx.isPointInPath(30, 19);
}
function topTest(){ function topTest(){
"use strict"; "use strict";
// create window canvas // create window canvas
var canvas = document.createElement("canvas"); var canvas = document.createElement("canvas");
// draw image in window canvas // draw image in window canvas
draw(canvas); var ctx = draw(canvas);
return canvas.toDataURL(); return {
url: canvas.toDataURL(),
isPointInPath: getIsPointInPath(ctx)
};
} }
function iframeTest(iframe){ function iframeTest(iframe){
@ -92,5 +108,8 @@ function iframeTest(iframe){
// copy image from window canvas to iframe ctx // copy image from window canvas to iframe ctx
iframe_ctx.drawImage(canvas, 0, 0); iframe_ctx.drawImage(canvas, 0, 0);
return iframe_canvas.toDataURL(); return {
url: iframe_canvas.toDataURL(),
isPointInPath: getIsPointInPath(iframe_ctx)
};
} }