How to set X-Frame Options to ALLOW-FROM https://example.com and SAMEORIGIN on server

user3188291 picture user3188291 · Jul 20, 2017 · Viewed 22.6k times · Source

I have a requirement to set the X-Frame options on the server level to either:

Understand that X-Frame Options are mutually exclusive. See here.

However, my application requires framing in https://example.com and also from its SAMEORIGIN.

Please advise if there is a way around this while retainining my application's requirement to having allow framing on the same origin and be framed on 1 external site.

Or is this impossible?

Answer

Adaline Simonian picture Adaline Simonian · Jul 26, 2017

In addition to only supporting one instance of the header, X-Frame-Options does not support any more than just one site, SAMEORIGIN or not.

You'll have to use Content-Security-Policy and frame-ancestors, which does support multiple origins, like so:

Content-Security-Policy: frame-ancestors 'self' https://example.com

A couple notes to bear in mind: