Skip to content

Commit

Permalink
Fix clobbering of overridden canvas methods
Browse files Browse the repository at this point in the history
The method may be overridden again after we override,
as is done in the `hidpi-canvas-polyfill`. So if we
restore the method to the original as we see it, we'll
wipe out the polyfill.

Fixes EFForg#2657, EFForg#1226
  • Loading branch information
STRML committed Jul 30, 2020
1 parent 0a8a9a7 commit fa34749
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/js/contentscripts/fingerprinting.js
Original file line number Diff line number Diff line change
Expand Up @@ -204,9 +204,16 @@ function getFpPageScript() {
);

item.obj[item.propName] = (function (orig) {
// set to true after the first write, if the method is not
// restorable. Happens if another library also overwrites
// this method.
var skipMonitoring = false;

function wrapped() {
var args = arguments;
if (skipMonitoring) {
return orig.apply(this, args);
}

if (is_canvas_write) {
// to avoid false positives,
Expand Down Expand Up @@ -237,7 +244,13 @@ function getFpPageScript() {
// optimization: one canvas write is enough,
// restore original write method
// to this CanvasRenderingContext2D object instance
this[item.propName] = orig;
// Careful! Only restorable if we haven't already been replaced
// by another lib, such as the hidpi polyfill
if (this[item.propName] === wrapped) {
this[item.propName] = orig;
} else {
skipMonitoring = true;
}
}

return orig.apply(this, args);
Expand Down

0 comments on commit fa34749

Please sign in to comment.