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

Commit

Permalink
block access to child frames' contentWindow, contentDocument, place g…
Browse files Browse the repository at this point in the history
…uard in blocking proxy to prevent an infinite loop, issue #11683
  • Loading branch information
pes10k committed Nov 3, 2017
1 parent 4cd4d20 commit 8e294d6
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions app/extensions/brave/content/scripts/blockCanvasFingerprinting.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,17 @@ if (chrome.contentSettings.canvasFingerprinting == 'block') {
return undefined
}

var callCounter = 0;

var allPurposeProxy = new Proxy(defaultFunc, {
get: function (target, property) {

if (callCounter > 1000) {
callCounter = 0;
return undefined;
}
callCounter += 1;

if (property === Symbol.toPrimitive) {
return valueOfCoercionFunc
}
Expand Down Expand Up @@ -267,4 +275,32 @@ if (chrome.contentSettings.canvasFingerprinting == 'block') {
type: 'WebRTC',
methodName: 'navigator.mediaDevices.enumerateDevices'
})

chrome.webFrame.setGlobal("window.__braveBlockingProxy", allPurposeProxy())

// 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.__braveBlockingProxy
delete window.__braveBlockingProxy
var returnProxyGetter = {
get: function () {
return proxyObject
}
}
frameTypesToModify.forEach(function (frameType) {
propertiesToBlock.forEach(function (propertyName) {
Object.defineProperty(frameType.prototype, propertyName, returnProxyGetter)
})
})
}())
`

chrome.webFrame.executeJavaScript(pageScriptToInject)
}

0 comments on commit 8e294d6

Please sign in to comment.