You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
var f = document.createElement('iframe');
document.body.appendChild(f);
f.contentDocument.write('<iframe id="tst');
f.contentDocument.write('"></iframe><script>tst.contentWindow.alert(1);</script>');
What happens is that document.write calls are buffered, but handleHTML sees only one chunk at a time so it won't find anything inside the template.
related: bypass with multiple arguments to doc.write
var f = document.createElement('iframe');
document.body.appendChild(f);
f.contentDocument.write('<iframe id="tst', '"></iframe><script>tst.contentWindow.alert(1);</script>');
to deal with .innerHTML, could the same be applied here by hooking into contentDocument.write?
Basically this snippet fixes it and maybe can be generalized.
varf=document.createElement('iframe');document.body.appendChild(f);fix(f)// should be done by patched `.appendChild`f.contentDocument.write('<iframe id="tst');f.contentDocument.write('"></iframe><script>tst.contentWindow.alert(1);</script>');functionfix(f){varold_write=f.contentDocument.writevarcontent=''constparser=document.createElement('div')f.contentDocument.write=patched_writefunctionpatched_write(...args){content+=args.join('')parser.innerHTML=contentconstiframes=[...parser.querySelectorAll('iframe')]if(iframes.length){f.contentDocument.close()iframes.forEach(iframe=>{var[s1,s2]=[`console.log('apply snow to iframe')`,`tst.contentWindow.alert = (...args) => console.log(...args)`].map(s=>Object.assign(document.createElement('script'),{textContent: `${s}`}))iframe.before(s1)iframe.after(s2)})console.log('fuck')console.log(parser.children)old_write.apply(f.contentDocument,[parser.innerHTML])}else{old_write.apply(f.contentDocument,args)}}}
@serapath yes, something like that, the main points are that args should be joined (to address this), and buffered (to address the OP). I'd say the optimal parser for this case would be another document (new DOMParser().parseFromString('...', 'text/html') with the same readyState and content as the target document, because if reflects the actual resulting DOM the best. To illustrate my latest point:
var doc1 = new DOMParser().parseFromString('<html><head><body><frameset><frame src="/" /></frameset></body></head><html>', 'text/html');
var doc2 = new DOMParser().parseFromString('<html><frameset><frame src="/" /></frameset><html>', 'text/html');
// compare doc1 and 2
I found it the hard way when an attempted fix broke a similar test...
Activity
mmndaniel commentedon Jun 29, 2023
related: bypass with multiple arguments to doc.write
serapath commentedon Jul 4, 2023
wow, mental.
Given there is
snow/src/inserters.js
Line 33 in 48ec98b
.innerHTML, could the same be applied here by hooking intocontentDocument.write?Basically this snippet fixes it and maybe can be generalized.
mmndaniel commentedon Jul 4, 2023
@serapath yes, something like that, the main points are that
argsshould bejoined(to address this), and buffered (to address the OP). I'd say the optimal parser for this case would be another document (new DOMParser().parseFromString('...', 'text/html') with the same readyState and content as the target document, because if reflects the actual resulting DOM the best. To illustrate my latest point:I found it the hard way when an attempted fix broke a similar test...
weizman commentedon Jul 10, 2023
yes, and #80 (comment)
weizman commentedon Jul 17, 2023
Sorry to ruin the party guys, but with the help of #118 we might not need to dig too deep into this (thanks for the help!)