From 0464075dfcaa6ca589ed1f59596ee87106a8a073 Mon Sep 17 00:00:00 2001 From: gorhill Date: Wed, 17 May 2017 09:25:11 -0400 Subject: [PATCH] code review: fix "logger enabled" code paths re. csp injection --- src/js/traffic.js | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/src/js/traffic.js b/src/js/traffic.js index af28762ca..5ecff9140 100644 --- a/src/js/traffic.js +++ b/src/js/traffic.js @@ -473,19 +473,15 @@ var injectCSP = function(pageStore, details) { // Static filtering. - var logData = []; + var logDataEntries = []; µb.staticNetFilteringEngine.matchAndFetchData( 'csp', requestURL, cspSubsets, - loggerEnabled === true ? logData : undefined + loggerEnabled === true ? logDataEntries : undefined ); - // <<<<<<<< All policies have been collected - - context.dispose(); - // URL filtering `allow` rules override static filtering. if ( cspSubsets.length !== 0 && @@ -502,10 +498,11 @@ var injectCSP = function(pageStore, details) { context.pageHostname ); } + context.dispose(); return; } - // Dynamic filtering rules override static filtering. + // Dynamic filtering `allow` rules override static filtering. if ( cspSubsets.length !== 0 && µb.userSettings.advancedUserEnabled && @@ -522,16 +519,18 @@ var injectCSP = function(pageStore, details) { context.pageHostname ); } + context.dispose(); return; } + // <<<<<<<< All policies have been collected + // Static CSP policies will be applied. - var i = logData.length; - while ( i-- ) { + for ( var entry of logDataEntries ) { logger.writeOne( tabId, 'net', - logData[i], + entry, 'csp', requestURL, context.rootHostname, @@ -539,14 +538,17 @@ var injectCSP = function(pageStore, details) { ); } + context.dispose(); + if ( cspSubsets.length === 0 ) { return; } µb.updateBadgeAsync(tabId); - var csp, headers = details.responseHeaders; - i = headerIndexFromName('content-security-policy', headers); + var csp, + headers = details.responseHeaders, + i = headerIndexFromName('content-security-policy', headers); if ( i !== -1 ) { csp = headers[i].value.trim(); headers.splice(i, 1);