0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

HTML: script要素やlink要素の参照先をblob:fileに指定すると…

Last updated at Posted at 2024-12-14

何が起こるかと言うと、しっかりちゃっかりうっかりblob:file///…などというURL指定がまかり通るのであります。勿論img要素等にも適用されやがります。

<iframe id=a></iframe>
<iframe id=b></iframe>
<script>{
const url=(a,b)=>URL.createObjectURL(new Blob([a],{type:b})),
	js=url("console.log(new Date)"),
	css=url("a{color:red}"),
	img=url(new Uint8Array([71,73,70,56,55,97,38,0,14,0,240,1,0,252,206,85,51,102,153,44,0,0,0,0,38,0,14,0,0,2,71,140,143,169,203,237,15,129,156,212,208,11,44,158,40,47,239,41,32,19,6,101,103,153,151,153,150,153,75,182,235,200,214,240,215,162,180,122,220,98,222,179,245,66,190,196,8,70,75,234,102,178,202,81,135,194,213,126,83,99,103,35,209,96,181,27,136,247,11,14,51,10,0,59])),
	src=url("<a href=javascript:alert(1)>text</a>","text/html"),
	html='<script src='+js+'><\/script><link rel=stylesheet href='+css+'><a>text</a> <img src='+img+'> <input type=image src='+img+'>';
b.src=src;
document.write(a.srcdoc=html)
}</script>

iframeのsrc属性にblob:file的なものを指定すると、HTMLが反映されたりされなかったりbrowser依存です(Blobの第2引数に{type:"text/html"}を指定すると反映されるっぽいです)。
当然ながらsrcdoc属性の場合はURLが表示されるだけです。上記例ではhtmlを直書きして対応。
ちなみにWorkerの引数に対しても有効。拒否するbrowserもあるかもしれませんが…

new Worker(URL.createObjectURL(new Blob(["console.log(1)"])))

ふーん、だから何?

そんな事私の知った事ではありませんが、面白い事ができるはずです。例えばchm fileもどきを作るとか?

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?