18 June 2010

Frame Busting Code

It has been common in the past to include JavaScript "frame busting" or "frame killing" code to prevent a web site being displayed inside a frame (typically by someone else's frame).

Close-up photograph of engine machinery at the London Transport Museum, Covent Garden

It is also referred to as a frame killer frame buster. For those with an interest in coding, the type of thing I mean is something like:

<script type="text/javascript">
   if(top.location != location) {
	top.location.href = document.location.href;
   }
</script>

Originally this was mainly related to the concern of other sites framing your own content to make it look like their own. This was common where the frames site also used frames and had little branding on its content pages.

Well frames are used much less for this purpose nowadays but there are plenty of uses for frames in dynamic sites, and there are other problems to consider too such as Clickjacking identified by Robert Hansen and Jeremiah Grossman. So what is it best to use?

The Stanford Web Security Group has published a paper on Busting Frame Busting: A Study of Clickjacking Vulnerabilities at Popular Sites which examines existing frame busting code, ways it can be circumvented and includes a recommendation for current use. The paper is very readable, and easily digested if you are involved with web development.

So what are the recommendations? The paper suggests using the X-Frame-Options HTTP header, and creating a Firefox Content Security Policy, and adding code like:

<style type="text/css">
    html { visibility:hidden; }
</style>
<script language="javascript" type="text/javascript">
    if ( self == top ) {
	document.documentElement.style.visibility='visible';
    } else {
	top.location = self.location;
    }
</script>

This requires JavaScript to be supported and enabled. This may be an acceptable assumption if the site itself relies on JavaScript. But the code uses CSS to blank the content and JavaScript to make it visible, meaning that it could be inaccessible by some (many?) users. The paper's authors believe the code does not significantly alter page rendering or load time. The code is not guaranteed to be a secure approach to frame busting but the authors believe it is the best approach currently.

There is of course no harm in having target="_top" in all hyperlinks and forms, and using the BASEHREF tag and/or full URL in hyperlinks and form actions. If you allow parts of your site to be framed by your own or other web sites, you will need to be more careful how all these anti-framing techniques are applied.

However, I think there could be an adverse effect on public content search engine ranking, due to the use of content hiding, and I do not believe this risk has been examined. If the JavaScript code is used on content which is not meant to be indexed (e.g. registration, log in, password reset and content meant for authenticated users only), this is no longer a risk.

Pass this information on to your development team and ask them what they are doing to protect your web site and its users from framing.

Posted on: 18 June 2010 at 10:25 hrs

Comments Comments (0) | Permalink | Send Send | Post to Twitter

Comments

Comments are filtered automatically and should appear shortly after they been checked.

Post a comment
Confirm acceptance and understanding of the terms of use
New posts to this thread will be sent to your email address
Frame Busting Code
http://www.clerkendweller.com/2010/6/18/Frame-Busting-Code
ISO/IEC 18004:2006 QR code for http://clerkendweller.com

Page http://www.clerkendweller.com/2010/6/18/Frame-Busting-Code
Requested by 38.107.179.223 on Saturday, 4 February 2012 at 22:57 hrs (London date/time)

Please read our terms of use and obtain professional advice before undertaking any actions based on the opinions, suggestions and generic guidance presented here. Your organisation's situation will be unique and all practices and controls need to be assessed with consideration of your own business context.

Terms of use http://www.clerkendweller.com/page/terms
Privacy statement http://www.clerkendweller.com/page/privacy
© 2010-2012 clerkendweller.com