I created a simple HTML page with an iframe
whose src
attribute references the containing page -- in other words a self-referencing iframe.
this.html
<html>
<head></head>
<body>
<iframe src="this.html"></iframe>
</body>
</html>
Why does this not infinitely loop and crash my browser? Also, why doesn't even IE crash at this?
(Note: This spawned from a team discussion on the virtues and demerits of using iframes to solve problems. You know, the 'mirror of a mirror' sort.)
W3C took care of that in 1997 explaining how frames should be implemented in "Implementing HTML Frames":
Iframe recursion bug/attack history
As kingdago found out and mentioned in the comment above, one browser that missed to implement a safeguard for this was Mozilla in 1999. Quote from one of the developers:
I decided to dig some more into this and it turns out that in 2004 this happened again. However, this time JavaScript was involved:
Then again in 2008 with Firefox 2 (this also involved JavaScript).
And again in 2009. The interesting part here is that this bug is still open and this attachment:
https://bugzilla.mozilla.org/attachment.cgi?id=414035
(will you restrain your curiosity?) will still crash/freeze your Firefox (I just tested it and I almost crashed the whole Ubuntu). In Chrome it just loads indefinitely (probably because each tab lives in a separate process).As for the other browsers:
I'd like to add a little something to the "Also, why doesn't even IE crash at this?" part of the question. IE does not let us down...
If you add a simple iteration number as a query string to the nested iFrame's src Firefox and others will just stop after a certain iteration depth. IE - and we tested this with IE version 10 - just crashes :)
this.php