OK, here’s a technical problem to solve. I’ve been chatting with one of the administrators of a very large website (if you guess, keep it to yourself) which, as part of its function, displays user-provided content in the middle of site-provided pages. For historical reasons, the user-provided content needs to allow scripts, Flash and other dynamic content. However, they want to prevent such content affecting “their” part of the page, above and below the user content, and performing malicious actions. Currently, this can be done using either script or CSS-positioning or both.
I suggested that in general, their problem was unsolvable, but that the industrial-strength way of getting such separation was to use an <iframe>. He told me that they’d tried that, but as scrollbars internal to the page were unacceptable, they’d had to try resizing the iframe dynamically using JS to eliminate the bars. This solution had run into technical difficulties, as explained in the following saga, some of which I don’t quite follow.
Read it for background if you think it helps – but the question is: how hard would it be to get an <iframe> or <object> which always resized to its content? The solution can involve either JavaScript, or hacking Gecko.
Currently in Gecko, as far as I can tell, if you don’t set a width and a height, <object> tags of type e.g. image/png size to their content. So why can’t (or why don’t) <object> tags of type text/html?
Here’s the story:
Here was the general process under which we went through to implement iframes:
The Problem: The users enter malicious content on the page that can overwrite our page content as well as steal cookies since it’s in the same domain.
Our proposed solution: We want to separate the user data on the page from our site content. The most esthetically clean way to do this was inside of an iframe that is automatically resized to avoid having embedded scrollbars which our user community would never be okay with.
How it was implemented: We wrapped the content inside of JavaScript to detect the vertical height of the page and then render the iframe appropriately to avoid any scrollbars inside the page itself. When we tried to roll this out we encountered massive problems.
- Any items with links, when clicked on only redirected the main page. We solved this issue for the most part, except for Applets, objects, etc… We would be willing to take this hit and force our developer community to change their code to support this. This is somewhere around 10-30% (the number is hard to calculate since it isn’t a part of the page, it’s a part of the code hosted elsewhere).
- Tables rendered badly. This ended up being the show-stopper. Users would put dozens of large images into tables and wouldn’t put sizes on the images. This would cause the page to sit there for minutes in some cases because the table wouldn’t finish loading so our JavaScript wouldn’t render the entire table until every last image were loaded. So next we attempted to change it so that every image pre-loaded as a 1×1 pixel image. That worked okay, but the only way to do that was to wrap the entire user’s content in <noscript> tags. The problem with that was that once we encountered an end </noscript> tag it would start rendering again. IE:
<noscript>
User content
<script>
//Some javascript
</script>
<noscript>
You don’t support JS
</noscript> <— at this point it breaks our <noscript> block
More user content with tables, etc which breaks our code…
</noscript>
At the time <noscript> was found on 22% of user input. Now it is closer to 2-3% due to some changes we have made, although that number is still too high to implement this solution. The users would also do really bizarre things with their code like have weirdly malformed tables, and JavaScript that outputted </noscript> tags. The fact that there was no way to completely stop text from rendering so that we could pause it and run JS over the code made this approach unfeasible after months of testing.
- It broke save-as in IE, which we don’t care about that much, but it was a big deal in certain countries, as users really like to save data to their desktops to prove that they saw it and agreed to whatever was said on the page. We can get around this issue by allowing a save-as friendly version that can only be linked to from our own page, but it’s less than ideal.
- Certain forms of popups still allowed some forms of overwriting (both Netscape and IE verified – although SP2 has fixed some of these issues since that time).
- When users resized during render time it became an issue because of the weird way in which the JS was written… it would be making assumptions about a size that was no longer accurate.
- It caused JS errors with pages that attempted to resize themselves.
- Browser support – with iframes and JS required for this to work it only supported ~90% of browsers.
Based on our discussion the right idea would be to have a different form of iframe that resizes to the size of the page it is calling to avoid the embedded scrollbar issue. If we could make this a standard we might even be able to get higher than the ~90% we found in #7 of the problems list.