Skip to content

Commit

Permalink
Address @ghostwords comments and combine canvas suites
Browse files Browse the repository at this point in the history
  • Loading branch information
STRML committed Aug 14, 2020
1 parent 165d12b commit aef17af
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 44 deletions.
6 changes: 3 additions & 3 deletions src/js/contentscripts/fingerprinting.js
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ function getFpPageScript() {
// set to true after the first write, if the method is not
// restorable. Happens if another library also overwrites
// this method.
var skipMonitoring = false;
var skip_monitoring = false;

function wrapped() {
var args = arguments;
Expand All @@ -216,7 +216,7 @@ function getFpPageScript() {
// to avoid false positives,
// bail if the text being written is too short,
// of if we've already sent a monitoring payload
if (skipMonitoring || !args[0] || args[0].length < 5) {
if (skip_monitoring || !args[0] || args[0].length < 5) {
return orig.apply(this, args);
}
}
Expand Down Expand Up @@ -247,7 +247,7 @@ function getFpPageScript() {
if (this[item.propName] === wrapped) {
this[item.propName] = orig;
} else {
skipMonitoring = true;
skip_monitoring = true;
}
}

Expand Down
41 changes: 0 additions & 41 deletions tests/selenium/fingerprinting_canvas_hidpi_test.py

This file was deleted.

25 changes: 25 additions & 0 deletions tests/selenium/fingerprinting_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,13 @@ def detected_tracking(self, domain, page_url):
map[tracker_origin].indexOf(site_origin) != -1
);""".format(domain, page_url))

def get_fillText_source(self):
return self.js("""
const canvas = document.getElementById("writetome");
const ctx = canvas.getContext("2d");
return ctx.fillText.toString();
""")

# TODO can fail because our content script runs too late: https://crbug.com/478183
@pbtest.repeat_if_failed(3)
def test_canvas_fingerprinting_detection(self):
Expand Down Expand Up @@ -69,6 +76,24 @@ def test_canvas_fingerprinting_detection(self):
"Canvas fingerprinting resource was detected as a fingerprinter."
)

# Privacy Badger overrides a few functions on canvas contexts to check for fingerprinting.
# In previous versions, it would restore the native function after a single call. Unfortunately,
# this would wipe out polyfills that had also overridden the same functions, such as the very
# popular "hidpi-canvas-polyfill".
def test_canvas_polyfill_clobbering(self):
FIXTURE_URL = (
"https://efforg.github.io/privacybadger-test-fixtures/html/"
"fingerprinting_canvas_hidpi.html"
)

# visit the page
self.load_url(FIXTURE_URL)

# check that we did not restore the native function (should be hipdi polyfill)
self.assertNotIn("[native code]", self.get_fillText_source(),
"Canvas context fillText is not native version (polyfill has been retained)."
)


if __name__ == "__main__":
unittest.main()

0 comments on commit aef17af

Please sign in to comment.