Skip to content

Commit

Permalink
Merge pull request #679 from mozilla/663-load-external-scripts-from-f…
Browse files Browse the repository at this point in the history
…acebook

Allow external scripts to be loaded if  frame ancestor is valid Facebook domain
  • Loading branch information
groovecoder authored Sep 24, 2020
2 parents ec27a42 + b226ec0 commit 71c7865
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 4 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "contain-facebook",
"version": "2.1.1",
"version": "2.2.0",
"description": "Facebook Container isolates your Facebook activity from the rest of your web activity in order to prevent Facebook from tracking you outside of the Facebook website via third party cookies. ",
"main": "background.js",
"scripts": {
Expand Down
31 changes: 29 additions & 2 deletions src/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,23 @@ function getRootDomain(url) {

}

function topFrameUrlIsFacebookApps(frameAncestorsArray) {
if (!frameAncestorsArray || frameAncestorsArray.length === 0) {
// No frame ancestor return false
return false;
}

const appsFacebookURL = "https://apps.facebook.com";
const frameAncestorsURL = frameAncestorsArray[0].url;

if (!frameAncestorsURL.startsWith(appsFacebookURL)) {
// Only allow frame ancestors that originate from apps.facebook.com
return false;
}

return frameAncestorsURL;
}

function isFacebookURL (url) {
const parsedUrl = new URL(url);
for (let facebookHostRE of facebookHostREs) {
Expand Down Expand Up @@ -506,19 +523,29 @@ async function blockFacebookSubResources (requestDetails) {
}

const urlIsFacebook = isFacebookURL(requestDetails.url);
const originUrlIsFacebook = isFacebookURL(requestDetails.originUrl);

// If this request isn't going to Facebook, let's return {} ASAP
if (!urlIsFacebook) {
return {};
}

const originUrlIsFacebook = isFacebookURL(requestDetails.originUrl);

if (originUrlIsFacebook) {
const message = {msg: "facebook-domain"};
// Send the message to the content_script
browser.tabs.sendMessage(requestDetails.tabId, message);
return {};
}

const frameAncestorUrlIsFacebookApps = topFrameUrlIsFacebookApps(requestDetails.frameAncestors);

if (frameAncestorUrlIsFacebookApps) {
const message = {msg: "facebook-domain"};
// Send the message to the content_script
browser.tabs.sendMessage(requestDetails.tabId, message);
return {};
}

const hasBeenAddedToFacebookContainer = await isAddedToFacebookContainer(requestDetails.originUrl);

if ( urlIsFacebook && !originUrlIsFacebook ) {
Expand Down
2 changes: 1 addition & 1 deletion src/manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"manifest_version": 2,
"name": "Facebook Container",
"version": "2.1.1",
"version": "2.2.0",

"incognito": "not_allowed",

Expand Down

0 comments on commit 71c7865

Please sign in to comment.