Skip to content

Commit 5a60d58

Browse files
committed
Prevent script injection from messing with content-disposition=attachment responses.
1 parent 493d400 commit 5a60d58

2 files changed

Lines changed: 16 additions & 12 deletions

File tree

src/bg/RequestUtil.js

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,21 @@
5757
let {requestId, url, tabId, frameId, statusCode} = request;
5858

5959
if (statusCode >= 300 && statusCode < 400) return;
60+
if (frameId === 0) {
61+
let key = tabKey(tabId, url);
62+
debug("Checking whether %s is a reloading tab...", key);
63+
if (reloadingTabs.get(key)) {
64+
reloadingTabs.set(key, false); // doom it for removal in cleanup
65+
return;
66+
}
67+
}
68+
let content = this.getContentMetaData(request);
69+
if (content.disposition) {
70+
debug("Skipping execute on start of %s %o", url, content);
71+
return;
72+
}
73+
debug("Injecting script on start in %s (%o)", url, content);
74+
6075
let scripts = pendingRequests.get(requestId);
6176
let scriptKey = JSON.stringify(details);
6277
if (!scripts) {
@@ -67,17 +82,6 @@
6782
return;
6883
}
6984

70-
if (frameId === 0) {
71-
let key = tabKey(tabId, url);
72-
debug("Checking whether %s is a reloading tab...", key);
73-
if (reloadingTabs.get(key)) {
74-
reloadingTabs.set(key, false); // doom it for removal in cleanup
75-
return;
76-
}
77-
}
78-
79-
let content = this.getContentMetaData(request);
80-
debug(url, content.type, content.charset);
8185
if (xmlFeedOrImage.test(content.type) && !/\/svg\b/i.test(content.type)) return;
8286
if (typeof brokenOnLoad === "undefined") {
8387
brokenOnLoad = await (async () => parseInt((await browser.runtime.getBrowserInfo()).version) < 61)();

src/lib/ContentMetaData.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ class ContentMetaData {
44
let {responseHeaders} = request;
55
for (let h of responseHeaders) {
66
if (/^\s*Content-(Type|Disposition)\s*$/i.test(h.name)) {
7-
this[h.name.split("-")[1].trim().toLowerCase()] = h.value;
7+
this[RegExp.$1.toLowerCase()] = h.value;
88
}
99
}
1010
}

0 commit comments

Comments
 (0)