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

block media device enumeration when fingerprinting protection is on #7871

Merged
merged 1 commit into from
Apr 3, 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
36 changes: 19 additions & 17 deletions app/extensions/brave/content/scripts/blockCanvasFingerprinting.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,10 @@ if (chrome.contentSettings.canvasFingerprinting == 'block') {
return script_url.replace(/:\d+:\d+$/, '')
}

function reportBlock (item) {
function reportBlock (type) {
var script_url = getOriginatingScriptUrl()
var msg = {
type: item.type,
obj: item.objName,
prop: item.propName,
type,
scriptUrl: stripLineAndColumnNumbers(script_url)
}

Expand All @@ -85,7 +83,11 @@ if (chrome.contentSettings.canvasFingerprinting == 'block') {
* @param item special item objects
*/
function trapInstanceMethod (item) {
chrome.webFrame.setGlobal(item.objName + ".prototype." + item.propName, reportBlock.bind(null, item))
if (!item.methodName) {
chrome.webFrame.setGlobal(item.objName + ".prototype." + item.propName, reportBlock.bind(null, item.type))
} else {
chrome.webFrame.setGlobal(item.methodName, reportBlock.bind(null, item.type))
}
}

var methods = []
Expand All @@ -94,8 +96,7 @@ if (chrome.contentSettings.canvasFingerprinting == 'block') {
var item = {
type: 'Canvas',
objName: 'CanvasRenderingContext2D',
propName: method,
obj: CanvasRenderingContext2D
propName: method
}

methods.push(item)
Expand All @@ -106,8 +107,7 @@ if (chrome.contentSettings.canvasFingerprinting == 'block') {
var item = {
type: 'Canvas',
objName: 'HTMLCanvasElement',
propName: method,
obj: HTMLCanvasElement
propName: method
}
methods.push(item)
})
Expand All @@ -118,8 +118,7 @@ if (chrome.contentSettings.canvasFingerprinting == 'block') {
var item = {
type: 'WebGL',
objName: 'WebGLRenderingContext',
propName: method,
obj: WebGLRenderingContext
propName: method
}
methods.push(item)
})
Expand All @@ -129,8 +128,7 @@ if (chrome.contentSettings.canvasFingerprinting == 'block') {
var item = {
type: 'AudioContext',
objName: 'AudioBuffer',
propName: method,
obj: AudioBuffer
propName: method
}
methods.push(item)
})
Expand All @@ -141,8 +139,7 @@ if (chrome.contentSettings.canvasFingerprinting == 'block') {
var item = {
type: 'AudioContext',
objName: 'AnalyserNode',
propName: method,
obj: AnalyserNode
propName: method
}
methods.push(item)
})
Expand All @@ -153,11 +150,16 @@ if (chrome.contentSettings.canvasFingerprinting == 'block') {
var item = {
type: 'WebRTC',
objName: 'webkitRTCPeerConnection',
propName: method,
obj: webkitRTCPeerConnection
propName: method
}
methods.push(item)
})

methods.forEach(trapInstanceMethod)

// Block WebRTC device enumeration
trapInstanceMethod({
type: 'WebRTC',
methodName: 'navigator.mediaDevices.enumerateDevices'
})
}
25 changes: 25 additions & 0 deletions test/bravery-components/braveryPanelTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -518,6 +518,31 @@ describe('Bravery Panel', function () {
.then((stat) => stat === '2' || stat === '3')
})
})
it('block device enumeration', function * () {
const url = Brave.server.url('enumerate_devices.html')
yield this.app.client
.tabByIndex(0)
.loadUrl(url)
.waitUntil(function () {
return this.getText('body')
.then((body) => {
return body.includes('default')
})
})
.openBraveMenu(braveMenu, braveryPanel)
.click(fpSwitch)
.waitUntil(function () {
return this.getText(fpStat)
.then((stat) => stat === '1')
})
.tabByUrl(url)
.waitUntil(function () {
return this.getText('body')
.then((body) => {
return body === ''
})
})
})
it('allows fingerprinting when setting is off in private tab', function * () {
const url = Brave.server.url('fingerprinting.html')
yield this.app.client
Expand Down
14 changes: 14 additions & 0 deletions test/fixtures/enumerate_devices.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<body>
<div id='results'></div>
<script>
let results = document.getElementById('results')
navigator.mediaDevices.enumerateDevices()
.then(function(devices) {
devices.forEach(function(device) {
let li = document.createElement('li')
li.textContent = [device.label, device.deviceId].join(': ')
results.appendChild(li)
});
})
</script>
</body>