code review: fix "logger enabled" code paths re. csp injection

This commit is contained in:
gorhill 2017-05-17 09:25:11 -04:00
parent 8eec0059e5
commit 0464075dfc
No known key found for this signature in database
GPG Key ID: 25E1490B761470C2
1 changed files with 14 additions and 12 deletions

View File

@ -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);