More specific dynamic script injection exceptions.

This commit is contained in:
hackademix 2018-07-09 19:32:24 +02:00
parent c6882356d3
commit 17a0426c32
1 changed files with 14 additions and 14 deletions

View File

@ -1,8 +1,11 @@
'use strict'; 'use strict';
{ {
let NULL = new Uint8Array(); let NULL = new Uint8Array();
let xmlFeedOrImage = /^(?:(?:application|text)\/(?:(?:r(?:ss|df)|atom)\+)?xml(;|$))|image\//i; let DEFAULT_CHARSET = "utf-8";
let xmlFeedOrImage = /^(?:(?:application|text)\/(?:(?:r(?:ss|df)|atom)\+)xml(;|$))|image\//i;
let rawXml = /^(?:application|text)\/xml;/i;
let brokenOnLoad = (async () => parseInt(await browser.runtime.getBrowserInfo().version) < 61); let brokenOnLoad = (async () => parseInt(await browser.runtime.getBrowserInfo().version) < 61);
let pendingRequests = new Map(); let pendingRequests = new Map();
let cleanup = r => { let cleanup = r => {
@ -35,15 +38,7 @@
var RequestUtil = { var RequestUtil = {
getContentMetaData(request) { getContentMetaData(request) {
if (request.content) return request.content; return request.content || (request.content = new ContentMetaData(request));
let {responseHeaders} = request;
let content = request.content = {};
for (let h of responseHeaders) {
if (/^\s*Content-(Type|Disposition)\s*$/i.test(h.name)) {
content[h.name.split("-")[1].trim().toLowerCase()] = h.value;
}
}
return content;
}, },
async executeOnStart(request, details) { async executeOnStart(request, details) {
@ -60,8 +55,9 @@
} }
let content = this.getContentMetaData(request); let content = this.getContentMetaData(request);
debug(request.url, content.type); debug(request.url, content.type, content.charset);
if (xmlFeedOrImage.test(content.type) && !/\/svg\b/i.test(content.type)) return; if (xmlFeedOrImage.test(content.type) && !/\/svg\b/i.test(content.type)) return;
let disconnect = !(brokenOnLoad && rawXml.test(content.type));
let filter = browser.webRequest.filterResponseData(requestId); let filter = browser.webRequest.filterResponseData(requestId);
let buffer = []; let buffer = [];
@ -73,18 +69,20 @@
for (let chunk of buffer) { for (let chunk of buffer) {
filter.write(chunk); filter.write(chunk);
} }
filter.disconnect(); if (disconnect) filter.disconnect();
buffer = null; buffer = null;
} }
}; };
if (brokenOnLoad) { if (brokenOnLoad) {
filter.onstart = event => { filter.onstart = event => {
debug(`onstart ${request.url}`);
filter.write(NULL); filter.write(NULL);
} }
} }
filter.ondata = event => { filter.ondata = event => {
if (first) { if (first) {
runAndFlush(); runAndFlush();
first = false; first = false;
@ -93,8 +91,10 @@
buffer.push(event.data); buffer.push(event.data);
return; return;
} }
debug(`ondata ${request.url}`);
filter.write(event.data); filter.write(event.data);
filter.disconnect(); if (disconnect) filter.disconnect();
}; };
} }