# X-Frame-Options in haproxy

**URL:** <https://discourse.haproxy.org/t/x-frame-options-in-haproxy/4055>\
**Category:** Help!\
**Created:** [July 17, 2019, 10:52am UTC](https://discourse.haproxy.org/t/x-frame-options-in-haproxy/4055 "2019-07-17T10:52:17Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Giant](https://avatars.discourse-cdn.com/v4/letter/g/919ad9/32.png) [@Giant](https://discourse.haproxy.org/u/Giant)\
**Post date:** [July 17, 2019, 10:52am UTC](https://discourse.haproxy.org/t/x-frame-options-in-haproxy/4055/1 "2019-07-17T10:52:17Z")

</div>

Hi  
We use haproxy version 1.8.16 for our sites. one week ago we saw one site is using our site by means of iframe tag in its site, I think this is a kind of clickjacking. We could stop them with below command in our front end:  
rspadd X-Frame-Options:\ SAMEORIGIN  
This worked very well and stop them  
but we need to except some sites from this. I have found nothing about this issue in internet for haproxy.  
Thanks for ur help

---

<div class="post-metadata">

**Author:** ![ciprian.craciun](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.haproxy.org/ciprian.craciun/32/722_2.png) [@ciprian.craciun](https://discourse.haproxy.org/u/ciprian.craciun)\
**Post date:** [July 17, 2019, 11:09am UTC](https://discourse.haproxy.org/t/x-frame-options-in-haproxy/4055/2 "2019-07-17T11:09:47Z")

</div>

The `X-Frame-Options` is a feature implemented in browsers, therefore not pertaining to HAProxy (or any other web-server or load-balancer out there).

However you should have a look at the Mozilla documentation pertaining to this header (they even have an example for HAProxy):

> **[X-Frame-Options](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-Frame-Options)**
>
> The X-Frame-Options HTTP response header can be used to indicate whether or not a browser should be allowed to render a page in a frame, iframe, embed or object. Sites can use this to avoid clickjacking attacks, by ensuring that their content is not...

Unfortunately, based on their compatibility matrix, except Firefox (and surprisingly IE), only the `sameorigin` option looks to be fully supported by most browsers.

* * *

That being said, another alternative is to inject the `X-Frame-Option: deny` only when the `Referer` request header is different than the domains you want to whitelist. (You should also make sure to configure the `referrerpolicy` option of the `<iframe>`.)

[https://developer.mozilla.org/en-US/docs/Web/HTML/Element/iframe#attr-referrerpolicy](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/iframe#attr-referrerpolicy)

* * *

All in all, please take into account that the success of any of these measures depends on the browser, and in the end there is nothing that HAProxy (or for that matter any web server out there) can actually do to stop this kind of attacks.

* * *

Alternatively you could rely on JavaScript to either detect the usage inside of an `<iframe>` and either “escape” from it, or issue an alert to the user, or perhaps even redirect that iframe to a warning page.

> **[Break Out of iframe](https://css-tricks.com/snippets/javascript/break-out-of-iframe/)**
>
> if (top.location!= self.location) { top.location = self.location.href; } That will generally work, but there is a small chance of failure in the case that window is overridden. Here’s a coupl…
