Skip to content
This repository has been archived by the owner on Dec 11, 2019. It is now read-only.

block access to fingerprinting methods pulled from child frames issue #11683 #11708

Merged
merged 1 commit into from
Oct 31, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions app/extensions/brave/content/scripts/blockCanvasFingerprinting.js
Original file line number Diff line number Diff line change
Expand Up @@ -267,4 +267,29 @@ if (chrome.contentSettings.canvasFingerprinting == 'block') {
type: 'WebRTC',
methodName: 'navigator.mediaDevices.enumerateDevices'
})

// Prevent access to frames' contentDocument / contentWindow
// properties, to prevent the parent frame from pulling unblocked
// references to blocked standards from injected frames.
// This may break some sites, but, fingers crossed, its not too much.
var pageScriptToInject = `
(function () {
var frameTypesToModify = [window.HTMLIFrameElement, window.HTMLFrameElement]
var propertiesToBlock = ["contentDocument", "contentWindow"]
var proxyObject = window.HTMLCanvasElement.prototype.toDataURL
var returnProxyGetter = {
get: function () {
return proxyObject()
}
}

frameTypesToModify.forEach(function (frameType) {
propertiesToBlock.forEach(function (propertyName) {
Object.defineProperty(frameType.prototype, propertyName, returnProxyGetter)
})
})
}())
`

chrome.webFrame.executeJavaScript(pageScriptToInject)
}
13 changes: 13 additions & 0 deletions test/bravery-components/braveryPanelTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -895,6 +895,19 @@ describe('Bravery Panel', function () {
.tabByIndex(0)
.waitUntil(verifyProxyBlocking)
})
it('blocking access to fingerprinting methods on iframe.contentWindow', function * () {
const url = Brave.server.url('fingerprinting-blocking-from-child-frames.html')
yield this.app.client
.tabByIndex(0)
.loadUrl(url)
.waitForUrl(url)
.openBraveMenu(braveMenu, braveryPanel)
yield changeFpSetting(this.app.client, blockFpOption)
yield this.app.client
.keys(Brave.keys.ESCAPE)
.tabByIndex(0)
.waitUntil(verifyProxyBlocking)
})
it('block device enumeration', function * () {
const url = Brave.server.url('enumerate_devices.html')
yield this.app.client
Expand Down
28 changes: 28 additions & 0 deletions test/fixtures/fingerprinting-blocking-from-child-frames.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<html>
<head>
</head>
<body>
<div id="target">
proxy blocking being tested
</div>
<script>
(function () {

let parentFrameMethod = window.HTMLCanvasElement.prototype.toDataURL

let iframe = document.createElement("iframe")
iframe.src = "https://www.brave.com/"
document.body.appendChild(iframe)

// Not blocked
let childFrameMethod = iframe.contentWindow.HTMLCanvasElement.prototype.toDataURL;

if (parentFrameMethod() === childFrameMethod()) {
// If an exception is thrown in the above code, the below line will never
// run, and the text in the div will never be changed (ie test fails).
document.getElementById('target').innerHTML = 'proxy blocking works'
}
}())
</script>
</body>
</html>