CanvasBlocker icon indicating copy to clipboard operation
CanvasBlocker copied to clipboard

write-only option

Open Vproject opened this issue 12 years ago • 6 comments

Mirroring the approach taken by mozilla bug 967895 might be interesting as a extra option between allowing or blocking all access to Canvas.

Their approach is to allow pages to write to canvas, but to return a completely white image when getImageData() is called, unless given permission.

Bug967895's implementation changes the Firefox source code, but perhaps a javascript only solution is possible similar to your current blocking code by overriding the regular implementation when permission is denied or by leaving it as is if access is allowed.

Something like this to override getImageData()

CanvasRenderingContext2D.prototype.getImageData = function(x, y, w, h) {
    var imgdata = new ImageData(w, h);
    var i=w*h*4; // 4 bytes per pixel for RGBA
    while(i) {
        imgdata.data[i--] = 0xFF;
    }
    return imgdata;
};

Vproject avatar Sep 30 '14 14:09 Vproject

Great Idea. I will add an option in the blockingMode.

But if someone uses it she/he must be aware that this is a fingerprint that the Add-On is used.

kkapsner avatar Oct 05 '14 13:10 kkapsner

But if someone uses it she/he must be aware that this is a fingerprint that the Add-On is used.

Or that Tor Browser is used (that's where Bug967895's patch comes from). Possibly they get a little less info about the platform the browser runs on though.

Note that ImageData's default data is all zero (so black instead of white), so if you don't replace the data with 255 or 0xFF it will be identifiable as CanvasBlocker (and not Tor Browser).

Vproject avatar Oct 09 '14 20:10 Vproject

Maybe the best way would be to fill it with random values.

kkapsner avatar Oct 10 '14 22:10 kkapsner

But getImageData is not the only function that has to be altered. There are also .toBlob(), .toDataURL() and .mozGetAsFile() of the canvas itself.

I tried to randomise them - check out the fakeImageDataApproach branch.

kkapsner avatar Oct 10 '14 23:10 kkapsner

Right! I had absolutely overlooked toBlob(), toDataURL() and mozGetAsFile(). Good catch! :)

Also a good idea to use random values; No lumping in with Tor Browser and harder to identify as fake data.

Vproject avatar Oct 11 '14 12:10 Vproject

It's will always be detectable.

I merged the fake options to the master so it will be in the next release.

kkapsner avatar Oct 14 '14 20:10 kkapsner