1
0
mirror of https://github.com/kkapsner/CanvasBlocker synced 2024-12-22 21:00:23 +01: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){
var rng = randomSupply.getRng(1, window);
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");
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){
var rng = randomSupply.getRng(1, window);
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");
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
fixes:
-
- respect resistFingerPrinting setting in isPointInPath and isPointInStroke
Version 0.4.5b:
known issues:

View File

@ -8,13 +8,13 @@
<div id="top">
<h1>top Test</h1>
<img class="display"><br>
Hash: <span class="hash"></span>
Hash: <span class="hash"></span> (isPointInPath: <span class="isPointInPath"></span>)
<button>refresh</button>
</div>
<div id="iframe">
<h1>iFrame Test. Thanks to DocumentRoot.</h1>
<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>
<button>refresh</button>
</div>
@ -22,7 +22,7 @@
<div id="iframe2">
<h1>iFrame Test 2 - with URL</h1>
<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>
<button>refresh</button>
</div>
@ -30,7 +30,7 @@
<div id="iframe3">
<h1>iFrame Test 3 - violating SOP</h1>
<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>
<button>refresh</button>
</div>

View File

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