Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Yes you can be sure; using an iframe + innerHTML because the later one is not a function and can't point at one or can be defined any other way and the same goes for its parent objects.

    document.body.innerHTML += "<iframe></iframe>";
    document.body.childNodes[document.body.childNodes.length-1].contentWindow.crypto.getRandomValues;
And please don't talk about how the JS engione of the browser can be compromised too; I know that but here we are aiming for practical applications not a philosophical debate about how everything is just an illusion.


Yes, I know, it's turtles all the way down, of course.

Still, I think that "but here we are aiming for practical applications not a philosophical debate about how everything is just an illusion." is a dangerous statement. Some people would say the same about something like sql injection, or cross-site scripting (Really? Yes, really, I encounter them on a regular basis).

With security issues the border between 'practical' and 'not practical/philosophical' depends on your threat model. If the kind of adversary that is able to compromise your JS engine does not appear in your threat model you can ignore the possibility of your JS engine being compromised and your solution may be good enough. If however that kind of adversary does appear in your threat model you do not have that luxury and your solution is not good enough.

That's not philosophical, that's real world practical.


This defeats your security in IE: (A bit of a moot point since IE doesn't support the crypto API anyway, but still.)

    document.body.innerHTML += '<script>document.write("<plaintext>"); document.body.childNodes[document.body.childNodes.length-1].contentWindow = {crypto: {getRandomValues: function() { alert("Ha!"); }}};</script>';


I know this isn't the point of your comment, but modifying document.body.innerHTML and then using document.all to access it is probably the worst possible way to append an element to the document and then use it.


To avoid some of the bad you can put this before the other Javascript files because that way you don't destroy event listeners.

Also I changed "document.all" for "document.body.childNodes" that is cross-browser and can't be compromised.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: