diff --git a/js/background.js b/js/background.js index 1ae82e4c1..15a0a27c4 100644 --- a/js/background.js +++ b/js/background.js @@ -89,7 +89,7 @@ return { firstUpdateAfter: 5 * oneMinute, nextUpdateAfter: 7 * oneHour, - selfieMagic: 'imktayytaizj', + selfieMagic: 'clegcrcjvuzg', selfieAfter: 7 * oneMinute, pageStores: {}, diff --git a/js/net-filtering.js b/js/net-filtering.js index 0b139e1b9..414b50d7d 100644 --- a/js/net-filtering.js +++ b/js/net-filtering.js @@ -54,14 +54,15 @@ const ThirdParty = 2 << 2; const AnyType = 1 << 4; var typeNameToTypeValue = { - 'stylesheet': 2 << 4, - 'image': 3 << 4, - 'object': 4 << 4, - 'script': 5 << 4, - 'xmlhttprequest': 6 << 4, - 'sub_frame': 7 << 4, - 'other': 8 << 4, - 'popup': 9 << 4 + 'stylesheet': 2 << 4, + 'image': 3 << 4, + 'object': 4 << 4, + 'script': 5 << 4, + 'xmlhttprequest': 6 << 4, + 'sub_frame': 7 << 4, + 'other': 8 << 4, + 'inline-script': 14 << 4, + 'popup': 15 << 4 }; const BlockAnyTypeAnyParty = BlockAction | AnyType | AnyParty; @@ -1066,6 +1067,7 @@ FilterParser.prototype.toNormalizedType = { 'xmlhttprequest': 'xmlhttprequest', 'subdocument': 'sub_frame', 'other': 'other', + 'inline-script': 'inline-script', 'popup': 'popup' }; @@ -1095,12 +1097,19 @@ FilterParser.prototype.parseOptType = function(raw, not) { var type = this.toNormalizedType[raw]; if ( not ) { for ( var k in typeNameToTypeValue ) { - if ( k === type ) { continue; } + if ( typeNameToTypeValue.hasOwnProperty(k) === false ) { + continue; + } + if ( k === type ) { + continue; + } // https://github.com/gorhill/uBlock/issues/121 // `popup` is a special type, it cannot be set for filters intended // for real net request types. The test is safe since there is no // such thing as a filter using `~popup`. - if ( k === 'popup' ) { continue; } + if ( typeNameToTypeValue[k] > typeNameToTypeValue['other'] ) { + continue; + } this.types.push(typeNameToTypeValue[k]); } } else { diff --git a/js/traffic.js b/js/traffic.js index 1c788036f..38ba7391d 100644 --- a/js/traffic.js +++ b/js/traffic.js @@ -279,6 +279,52 @@ var cr410382Workaround = function(details) { /******************************************************************************/ +// To handle `inline-script`. + +var onHeadersReceived = function(details) { + // Only root document. + if ( details.parentFrameId !== -1 ) { + return; + } + + // Do not interfere with behind-the-scene requests. + var tabId = details.tabId; + if ( tabId < 0 ) { + return; + } + + // Lookup the page store associated with this tab id. + var µb = µBlock; + var pageStore = µb.pageStoreFromTabId(tabId); + if ( !pageStore ) { + return; + } + + var result = ''; + if ( pageStore.getNetFilteringSwitch() ) { + result = µb.netFilteringEngine.matchStringExactType(pageStore, details.url, 'inline-script'); + } + + // Not blocked? + if ( result === '' || result.slice(0, 2) === '@@' ) { + return; + } + + // Blocked + pageStore.perLoadBlockedRequestCount++; + µb.localSettings.blockedRequestCount++; + µb.updateBadgeAsync(tabId); + + details.responseHeaders.push({ + 'name': 'Content-Security-Policy', + 'value': "script-src *" + }); + + return { 'responseHeaders': details.responseHeaders }; +}; + +/******************************************************************************/ + var headerValue = function(headers, name) { var i = headers.length; while ( i-- ) { @@ -338,6 +384,20 @@ chrome.webRequest.onBeforeSendHeaders.addListener( [ "blocking", "requestHeaders" ] ); +chrome.webRequest.onHeadersReceived.addListener( + onHeadersReceived, + { + "urls": [ + "http://*/*", + "https://*/*", + ], + "types": [ + "main_frame" + ] + }, + [ "blocking", "responseHeaders" ] +); + console.log('µBlock> Beginning to intercept net requests at %s', (new Date()).toISOString()); /******************************************************************************/