Skip to content

Commit 9568584

Browse files
committed
Should fix some race conditions causing corruptions in non-HTML non-XML documents.
1 parent e0f46a2 commit 9568584

2 files changed

Lines changed: 11 additions & 1 deletion

File tree

src/content/DocumentCSP.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ class DocumentCSP {
3333
let root = document.documentElement;
3434
try {
3535
if (!(document instanceof HTMLDocument)) {
36+
if (!(document instanceof XMLDocument)) {
37+
return false; // nothing to do with ImageDocument, for instance
38+
}
3639
// non-HTML XML documents ignore <meta> CSP unless wrapped in
3740
// - <html><head></head></head> on Gecko
3841
// - just <head></head> on Chromium

src/content/syncFetchPolicy.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
ns.on("capabilities", () => {
2525

2626
let {readyState} = document;
27+
2728
debug("Readystate: %s, suppressedScripts = %s, canScript = %s", readyState, DocumentFreezer.suppressedScripts, ns.canScript);
2829

2930
if (!ns.canScript) {
@@ -45,6 +46,12 @@
4546
try {
4647
let doc = window.wrappedJSObject.document;
4748
removeEventListener("DOMContentLoaded", softReload, true);
49+
50+
let isDir = document.querySelector("link[rel=stylesheet][href^='chrome:']")
51+
&& document.querySelector(`base[href^="${url}"]`);
52+
if (isDir || document.contentType !== "text/html") {
53+
throw new Error(`Can't document.write() on ${isDir ? "directory listings" : document.contentType}`)
54+
}
4855
doc.open();
4956
console.debug("Opened", doc.documentElement);
5057
DocumentFreezer.unfreeze();
@@ -55,7 +62,7 @@
5562
debug("Written", html)
5663
})();
5764
} catch (e) {
58-
debug("Can't use document.write(), XML document?");
65+
debug("Can't use document.write(), XML document?", e);
5966
try {
6067
DocumentFreezer.unfreeze();
6168
let scripts = [], deferred = [];

0 commit comments

Comments
 (0)