Skip to content

Commit

Permalink
Optimize widget surrogate message frame check
Browse files Browse the repository at this point in the history
For messages from top level frames, and from nested frames
that are trivially first party (same scheme and host) to the tab.
  • Loading branch information
ghostwords committed Jul 17, 2024
1 parent 00b351a commit ed7bb6a
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions src/js/webrequest.js
Original file line number Diff line number Diff line change
Expand Up @@ -1763,7 +1763,8 @@ function dispatcher(request, sender, sendResponse) {
// proxies surrogate script-initiated widget replacement messages
// from one content script to another
case "widgetFromSurrogate": {
let tab_host = extractHostFromURL(sender.tab.url);
let tab_url = sender.tab.url,
tab_host = extractHostFromURL(tab_url);
if (!badger.isPrivacyBadgerEnabled(tab_host)) {
break;
}
Expand All @@ -1774,14 +1775,19 @@ function dispatcher(request, sender, sendResponse) {
// NOTE: before removing this restriction, investigate
// implications of accepting pbSurrogateMessage events
// from third-party scripts in nested frames
if (!request.frameUrl.startsWith('https://cdn.embedly.com/')) {
let frame_host = extractHostFromURL(request.frameUrl);
// CNAME uncloaking
if (utils.hasOwn(badger.cnameDomains, frame_host)) {
frame_host = badger.cnameDomains[frame_host];
}
if (!frame_host || utils.isThirdPartyDomain(frame_host, tab_host)) {
break;
if (sender.frameId > 0) {
if (!request.frameUrl.startsWith('https://cdn.embedly.com/')) {
let tab_scheme = tab_url.slice(0, tab_url.indexOf(tab_host));
if (!request.frameUrl.startsWith(tab_scheme + tab_host)) {
let frame_host = extractHostFromURL(request.frameUrl);
// CNAME uncloaking
if (utils.hasOwn(badger.cnameDomains, frame_host)) {
frame_host = badger.cnameDomains[frame_host];
}
if (!frame_host || utils.isThirdPartyDomain(frame_host, tab_host)) {
break;
}
}
}
}

Expand Down

0 comments on commit ed7bb6a

Please sign in to comment.