Framekiller

A framekiller (or framebuster or framebreaker) is a technique used by websites and web applications to prevent their web pages from being displayed within an HTML frame element. A frame is a subdivision of a Web browser window and can act like a smaller window. A framekiller is usually used to prevent a website from being loaded from within a frameset without permission, which might be part of an attack, as with clickjacking.

Framekiller scripts have largely been replaced by the usage of X-Frame-Options and Content-Security-Policy headers, which prevent the page from being loaded in a frame in the first place. These headers are supported by all modern browsers and do not require the use of JavaScript.[1] These headers are also intended to be specified inside the web server software, rather than directly inside the HTML.

Implementations

Framekillers are implemented using JavaScript that validates if the current window is the main window. The recommended approach is to block rendering of the window by default and only unblock it after confirming the current window is the main one:

<style>html {display: none;}</style>
<script>
    if (self == top) {
        document.documentElement.style.display = 'block'; 
    } else {
        top.location = self.location; 
    }
</script>

This approach was proposed in 2010 by Gustav Rydstedt, Elie Bursztein, Dan Boneh and Collin Jackson in a paper that highlighted the limitations of existing frame-busting techniques along with techniques allowing to bypass them.[2]

Alternative solutions

An alternative choice is to allow the user to determine whether to let the framekiller work.

var framekiller = false;
window.onbeforeunload = function() { 
  if (framekiller) {
    return "...";  // any message that helps user to make decision
  }
};

and the code below should be added after the frame tag:

// "my_frame" should be changed according to the real id of the frame in your page 
document.getElementById("my_frame").onload = function() { 
  framekiller = true;
};

Original framekillers

Historically, the first framekiller scripts were as simple as this:

<script type="text/javascript">
  if (top != self) top.location.replace(location);
</script>

The logic here was to display the page, but check if the top location is the same as the current page, and replace the top by current if not. This method however can be easily bypassed by blocking execution of the framebuster script from the outer frame.[2]

Framekiller limitations

Client-side JavaScript solution relies on the end-user's browser enforcing their own security. This makes it a beneficial, but unreliable, means of disallowing your page to be embedded in other pages. The following situations may render the script above useless:

  • The user agent does not support JavaScript.
  • The user agent supports JavaScript but the user has turned support off.
  • The user agent's JavaScript support is flawed or partially implemented.

Anti-framekiller

The iframe in HTML5 has a sandbox attribute.[3] The attribute's value is a set of allowed capabilities for the iframe's content. If the value is empty or not set, the iframe's content will not execute JavaScript, and won't allow top-level navigation. By specifying allow-scripts in the space separated set of exceptions in the value, the iframe will allow JavaScript, but will still disallow top-level navigation, rendering framekillers in the iframe impotent.

See also

  • Clickjacking - discusses more sophisticated methods to prevent embedding in a frame, such as X-Frame-Options header

References

  1. ^ "CSP: frame-ancestors". Retrieved 2023-09-27.
  2. ^ a b G. Rydstedt; E. Bursztein; D. Boneh; C. Jackson (2010). "Busting Frame Busting: a Study of Clickjacking Vulnerabilities on Popular sites". 3rd Web 2.0 Security and Privacy workshop. IEEE.
  3. ^ "Archived copy". Archived from the original on 2013-06-06. Retrieved 2014-11-01.{{cite web}}: CS1 maint: archived copy as title (link)

Content Disclaimer

Informasi ini disarikan dari Wikipedia dan disajikan kembali untuk tujuan edukasi. Konten tersedia di bawah lisensi CC BY-SA 3.0. Kami tidak bertanggung jawab atas ketidakakuratan data yang bersumber dari kontribusi publik tersebut.

  1. The information displayed on this website is sourced in part or in whole from Wikipedia and has been adapted for the purpose of restating it. We strive to provide accurate and relevant information, however:
  2. There is no guarantee of absolute accuracy. Wikipedia is an open, collaborative project that can be edited by anyone, so information is subject to change.
  3. It is not intended to constitute professional advice. The content displayed is for informational and educational purposes only. For important decisions (e.g., medical, legal, or financial), please consult a professional.
  4. Content copyright. Wikipedia is licensed under the Creative Commons Attribution-ShareAlike License (CC BY-SA). This means that content may be reused with appropriate attribution and shared under a similar license.
  5. Responsible use. Any risk arising from the use of information from this website is entirely the responsibility of the user.