Skip to content

Commit 34f8050

Browse files
committed
Adjusted protection for document.write and document.writeln
Fixes #356
1 parent 1e8553d commit 34f8050

File tree

4 files changed

+23
-3
lines changed

4 files changed

+23
-3
lines changed

.vscode/settings.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
"fakeable",
2828
"fragmenter",
2929
"graytext",
30+
"iframe",
3031
"ignorelist",
3132
"micrococo",
3233
"monero",
@@ -39,6 +40,8 @@
3940
"unticking",
4041
"webgl",
4142
"whitelisted",
43+
"writeln",
44+
"wyciwyg",
4245
"yfdyh"
4346
],
4447
"cSpell.language": "en,de,en-GB"

lib/iframeProtection.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,12 @@
148148
);
149149
const documentWrite = documentWriteDescriptor.value;
150150
documentWriteDescriptor.value = exportFunction(function write(str){
151-
const parts = str.split(/(?=<)/);
151+
str = "" + str;
152+
// weird problem with waterfox and google docs
153+
const parts = (
154+
str.match(/^\s*<!doctype/i) &&
155+
!str.match(/frame/i)
156+
)? [str]: str.split(/(?=<)/);
152157
const length = parts.length;
153158
const scripts = window.document.getElementsByTagName("script");
154159
for (let i = 0; i < length; i += 1){
@@ -170,6 +175,7 @@
170175
);
171176
const documentWriteln = documentWritelnDescriptor.value;
172177
documentWritelnDescriptor.value = exportFunction(function writeln(str){
178+
str = "" + str;
173179
const parts = str.split(/(?=<)/);
174180
const length = parts.length - 1;
175181
const scripts = window.document.getElementsByTagName("script");

releaseNotes.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@ Version 0.5.10:
88

99
fixes:
1010
- setter for innerHTML broke pages
11-
- protection for document.write and document.wirteln broke in Firefox 69
11+
- protection for document.write and document.writeln broke in Firefox 69
1212
- not connected iFrame threw error with persistent rng
13+
- detection over document.write and document.writeln was possible
14+
- google docs were broken in Waterfox
1315

1416
known issues:
1517
- if a data URL is blocked the page action button does not appear

test/iframeTest.html

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,18 @@
2424
});
2525
document.writeln("<iframe></iframe><script>log(\"TEST:\", \"iframe and script in document.writeln:\", compare(test(window[4]), reference));<\/script>");
2626
document.write("<script src=\"iframeTest.js\"><\/script><iframe></iframe><script>log(\"TEST:\", \"script with src, iframe and script in document.write:\", compare(test(window[5]), reference));<\/script>");
27+
28+
"<ifr|ame></ifr|ame>".split("|").forEach(function(part){
29+
document.write(part);
30+
});
31+
document.write("<script>log(\"TEST:\", \"ifr|ame split:\", compare(test(window[6]), reference));<\/script>");
2732
window.addEventListener("load", function(){
2833
// document.open();
29-
document.write("<script src=\"iframeTest.js\"><\/script><iframe></iframe><script>log(\"TEST:\", \"reopened document: script with src, iframe and script in document.write:\", compare(test(window[0]), reference, true));<\/script>");
34+
"<ifr|ame></ifr|ame>".split("|").forEach(function(part){
35+
document.write(part);
36+
});
37+
document.write("<script>log(\"TEST:\", \"reopened document: ifr|ame split:\", compare(test(window[0]), reference));<\/script>");
38+
document.write("<script src=\"iframeTest.js\"><\/script><iframe></iframe><script>log(\"TEST:\", \"reopened document: script with src, iframe and script in document.write:\", compare(test(window[1]), reference, true));<\/script>");
3039
// document.close();
3140
});
3241
window.setTimeout(function(){

0 commit comments

Comments
 (0)