Ensure `about:` frames use proper origin

Related issue:
- https://github.com/uBlockOrigin/uBlock-issues/issues/688

`about:` frames need to lookup and use the inherited
origin from their parent browsing context for proper
lookup of cosmetic filters.
This commit is contained in:
Raymond Hill 2020-07-24 18:50:12 -04:00
parent 779fde8f3a
commit 3b72c7cb04
No known key found for this signature in database
GPG Key ID: 25E1490B761470C2
3 changed files with 34 additions and 8 deletions

View File

@ -118,6 +118,26 @@ vAPI.contentScript = true;
/******************************************************************************/
/******************************************************************************/
// https://github.com/uBlockOrigin/uBlock-issues/issues/688#issuecomment-663657508
{
let location = self.location;
if ( location.protocol === 'about:' ) {
try {
let context = self;
do {
context = context.parent;
location = context.location;
} while ( context !== self.top && location.protocol === 'about:' );
} catch(ex) {
}
}
vAPI.pageLocation = location;
}
/******************************************************************************/
/******************************************************************************/
/******************************************************************************/
vAPI.userStylesheet = {
added: new Set(),
removed: new Set(),
@ -1765,8 +1785,8 @@ vAPI.injectScriptlet = function(doc, text) {
vAPI.bootstrap = function() {
vAPI.messaging.send('contentscript', {
what: 'retrieveContentScriptParameters',
url: window.location.href,
isRootFrame: window === window.top,
url: vAPI.pageLocation.href,
isRootFrame: self === self.top,
charset: document.characterSet,
}).then(response => {
bootstrapPhase1(response);

View File

@ -524,11 +524,15 @@ const µb = µBlock;
const retrieveContentScriptParameters = function(senderDetails, request) {
if ( µb.readyToFilter !== true ) { return; }
const { url, tabId, frameId } = senderDetails;
if ( url === undefined || tabId === undefined || frameId === undefined ) {
const { url: senderURL, tabId, frameId } = senderDetails;
if (
tabId === undefined ||
frameId === undefined ||
senderURL === undefined ||
senderURL !== request.url && senderURL.startsWith('about:') === false
) {
return;
}
if ( request.url !== url ) { return; }
const pageStore = µb.pageStoreFromTabId(tabId);
if ( pageStore === null || pageStore.getNetFilteringSwitch() === false ) {
return;
@ -714,7 +718,7 @@ const onMessage = function(request, sender, callback) {
xhr.responseType = 'text';
xhr.onload = function() {
this.onload = null;
var i18n = {
const i18n = {
bidi_dir: document.body.getAttribute('dir'),
create: vAPI.i18n('pickerCreate'),
pick: vAPI.i18n('pickerPick'),

View File

@ -211,10 +211,12 @@ const processTimer = new vAPI.SafeAnimationFrame(( ) => {
if ( toLog.length === 0 ) { return; }
const location = vAPI.pageLocation || self.location;
vAPI.messaging.send('scriptlets', {
what: 'logCosmeticFilteringData',
frameURL: window.location.href,
frameHostname: window.location.hostname,
frameURL: location.href,
frameHostname: location.hostname,
matchedSelectors: toLog,
});
//console.timeEnd('dom logger/scanning for matches');