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

Commit

Permalink
Restore 3rd party document.cookie block
Browse files Browse the repository at this point in the history
Auditors: @bbondy

Partially fix #3214
  • Loading branch information
diracdeltas committed Aug 16, 2016
1 parent 4df9dfe commit 92f86e3
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions app/extensions/brave/content/scripts/block3rdPartyContent.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,25 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */

/**
* Whether this is running in a third-party document.
*/
function is3rdPartyDoc () {
try {
// Try accessing an element that cross-origin frames aren't supposed to
window.top.document
} catch (e) {
if (e.name === 'SecurityError') {
return true
} else {
console.log('got unexpected error accessing window.top.document', e)
// Err on the safe side and assume this is a third-party frame
return true
}
}
return false
}

function blockReferer () {
if (document.referrer) {
// Blocks cross-origin referer
Expand All @@ -13,11 +32,24 @@ function blockReferer () {
}
}

function blockCookie () {
// Block js cookie storage
window.Document.prototype.__defineGetter__('cookie', () => { return '' })
window.Document.prototype.__defineSetter__('cookie', () => {})
}

function getBlockRefererScript () {
return '(' + Function.prototype.toString.call(blockReferer) + '());'
}

function getBlockCookieScript () {
return '(' + Function.prototype.toString.call(blockCookie) + '());'
}

if (chrome.contentSettings.referer != 'allow' &&
document.location.origin && document.location.origin !== 'https://youtube.googleapis.com') {
executeScript(getBlockRefererScript())
}
if (chrome.contentSettings.cookies != 'allow' && is3rdPartyDoc()) {
executeScript(getBlockCookieScript())
}

1 comment on commit 92f86e3

@bbondy
Copy link
Member

@bbondy bbondy commented on 92f86e3 Aug 17, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

++

Please sign in to comment.