Clickjacking là gì

Introduction¶

This cheat sheet is intended to lớn provide guidance for developers on how to lớn defkết thúc against Clickjacking, also known as UI redress attacks.

Bạn đang xem: Clickjacking là gì

There are three main mechanisms that can be used to lớn defover against these attacks:

Implementing JavaScript code in the page lớn attempt lớn prevent it being loaded in a frame (known as a "frame-buster").

chú ý that these mechanisms are all independent of each other, and where possible more than one of them should be implemented in order lớn provide defense in depth.

Defending with Content Security Policy (CSP) frame-ancestors directive¶

The frame-ancestors directive sầu can be used in a Content-Security-Policy HTTPhường response header khổng lồ indicate whether or not a browser should be allowed khổng lồ render a page in a or . Sites can use this khổng lồ avoid Clickjacking attacks by ensuring that their nội dung is not embedded inkhổng lồ other sites.

frame-ancestors allows a site khổng lồ authorize multiple domains using the normal Content Security Policy semantics.

Content-Security-Policy: frame-ancestors Examples¶

Common uses of CSPhường frame-ancestors:

Content-Security-Policy: frame-ancestors "none";This prevents any domain from framing the nội dung. This setting is recommended unless a specific need has been identified for framing.Content-Security-Policy: frame-ancestors "self";This only allows the current site lớn frame the nội dung.Content-Security-Policy: frame-ancestors "self" *.somesite.com https://myfriover.site.com;This allows the current site, as well as any page on somesite.com (using any protocol), and only the page myfriend.site.com, using HTTPS only on the default port (443).

chú ý that the single quotes are required around self and none, but may not occur around other source expressions.

See the following documentation for further details and more complex examples:

Limitations¶

Browser support: CSPhường frame-ancestors is not supported by all the major browsers yet.

Defending with X-Frame-Options Response Headers¶

The X-Frame-Options HTTPhường response header can be used to indicate whether or not a browser should be allowed khổng lồ render a page in a or . Sites can use this to lớn avoid Clickjacking attacks, by ensuring that their nội dung is not embedded into other sites. Set the X-Frame-Options header for all responses containing HTML content. The possible values are "DENY", "SAMEORIGIN", or "ALLOW-FROM uri"

X-Frame-Options Header Types¶

There are three possible values for the X-Frame-Options header:

DENY, which prevents any domain name from framing the nội dung. The "DENY" setting is recommended unless a specific need has been identified for framing.SAMEORIGIN, which only allows the current site to frame the content.ALLOW-FROM uri, which permits the specified "uri" to frame this page. (e.g., ALLOW-FROM http://www.example.com).Check limitations below because this will fail open if the browser does not tư vấn it.

Browser Support¶

The following browsers tư vấn X-Frame-Options headers.

References:

Implementation¶

To implement this protection, you need lớn add the X-Frame-Options HTTP.. Response header khổng lồ any page that you want khổng lồ protect from being clickjacked via framebusting. One way to vày this is to add the HTTP.. Response Header manually khổng lồ every page. A possibly simpler way is to lớn implement a filter that automatically adds the header to lớn every page or lớn add it at Web Application Firewall of Web/Application Server màn chơi.

Common Defense Mistakes¶

Meta-tags that attempt to lớn apply the X-Frame-Options directive sầu DO NOT WORK. For example, will not work. You must apply the X-FRAME-OPTIONS directive sầu as HTTPhường Response Header as described above sầu.

Xem thêm: Customs Procedures Là Gì - Phân Loại Thủ Tục Hải Quan

Limitations¶

Per-page policy specification: The policy needs to be specified for every page, which can complicate deployment. Providing the ability khổng lồ enforce it for the entire site, at login time for instance, could simplify adoption.Problems with multi-domain sites: The current implementation does not allow the webmaster to provide a list of domains that are allowed khổng lồ frame the page. While listing allowed domains can be dangerous, in some cases a webmaster might have sầu no choice but khổng lồ use more than one hostname.ALLOW-FROM browser support: The ALLOW-FROM option is a relatively recent addition (circa 2012) và may not be supported by all browsers yet. BE CAREFUL ABOUT DEPENDING ON ALLOW-FROM. If you apply it & the browser does not tư vấn it, then you will have sầu NO clickjacking defense in place.Multiple options not supported: There is no way lớn allow the current site & a third-buổi tiệc ngọt site khổng lồ frame the same response. Browsers only honour one X-Frame-Options header and only one value on that header.Nested Frames don"t work with SAMEORIGIN và ALLOW-FROM: In the following situation, the http://framed.invalid/child frame does not load because ALLOW-FROM applies to lớn the top-level browsing context, not that of the immediate parent. The solution is khổng lồ use ALLOW-FROM in both the parent and child frames (but this prevents the child frame loading if the //framed.invalid/parent page is loaded as the top màn chơi document).

*

X-Frame-Options Deprecated While the X-Frame-Options header is supported by the major browsers, it was never standardized và has been deprecated in favour of the frame-ancestors directive from the CSP Level 2 specification.Proxies Web proxies are notorious for adding & stripping headers. If a web proxy strips the X-Frame-Options header then the site loses its framing protection.

Defending with SameSite Cookies¶

The SameSite cookie attribute defined in RFC 6265bis is primarily intended to lớn defkết thúc against cross-site request forgery (CSRF); however it can also provide protection against Clickjacking attacks.

Cookies with a SameSite attribute of either strict or lax will not be included in requests made to lớn a page within an . This means that if the session cookies are marked as SameSite, any Clickjacking attachồng that requires the victim to be authenticated will not work, as the cookie will not be sent. An article on the Netsparker blog provides further details on which types of requests cookies are sent for with the different SameSite policies.

This approach is discussed on the JavaScript.info trang web.

Limitations¶

If the Clickjacking attack does not require the user lớn be authenticated, this attribute will not provide any protection.

Additionally, while SameSite attribute is supported by most modern browsers, there are still some users (approximately 6% as of November 2020) with browsers that do not support it.

The use of this attribute should be considered as part of a defence-in-depth approach, and it should not be relied upon as the sole protective sầu measure against Clickjacking.

Best-for-now Legacy Browser Frame Breaking Script¶

One way lớn defend against clickjacking is to lớn include a "frame-breaker" script in each page that should not be framed. The following methodology will prsự kiện a webpage from being framed even in legacy browsers, that vì not support the X-Frame-Options-Header.