html5 - used <script src="sample.pdf"></script> in Html still the javascript code in pdf works -


recently in 1 of code, in script src, used pdf file had javascript code in it. still, javascript worked fine. can use extension of file in src has javascript, if how browser detects javascript code inside pdf file.

example of usage

index.html

<html>  <title> sample </title>  <script   src="https://code.jquery.com/jquery-3.2.1.min.js"   integrity="sha256-hwg4gsxgfzhoseeamdoygbf13fyquitwlaqgxvsngt4="   crossorigin="anonymous"></script>   <script src="js/sample.pdf"></script>  <body>   <h1>sample page test script tag</h1>  </body> </html> 

js/sample.pdf

$(document).ready(function(){ consloe.log('it works'); }); 

in html5, default value script[type] attribute 1 of javascript application.

browsers mime type checks in order allow executable mimes means application/... might seen valid, , text/... too.


[edit] according this mdn article,

the script should served text/javascript mime type, browsers lenient , block them if script served image type (image/*), video type (video/*), audio (audio/*) type, or text/csv.


here snippet which works in chrome* showing few examples of weirdly accepted , refused mime types :

function loadscript(type, magics){    const script = document.createelement('script');    const magic_array = new uint8array(magics.split(' ').map(n=>parseint(n, 16)));    script.src = url.createobjecturl(new blob(magic_array, {type: type}));    script.dataset.id = type;    script.onerror = e => console.log(type, 'failed');    script.onload = e => console.log(type, 'success');    document.head.appendchild(script);    }  loadscript('image/png', '89 50 4e 47 0d 0a 1a 0a'); // fails  loadscript('application/zip', '50 4b 03 04'); // works  loadscript('text/css', ''); // works  loadscript('text/csv', ''); // fails  loadscript('text/plain', ''); // works  loadscript('application/octet-stream', '4d 5a'); // works  loadscript('application/exe', '4d 5a'); // works

*ff doesn't respect mime type , doesn't triggers magic number's checking on bloburis... did test on local server , when sends these mimes, results same.


Comments

Popular posts from this blog

Sort a complex associative array in PHP -

vb.net - How to ignore if a cell is empty nothing -

recursion - Can every recursive algorithm be improved with dynamic programming? -