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

2

20

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?

Petronilapetronilla answered 20/7, 2017 at 2:49 Comment(1)
any help is appreciated.Petronilapetronilla
P
44

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:

Pricecutting answered 26/7, 2017 at 19:13 Comment(1)
This answer is the right one and should be accepted (and upvoted)Circuitry
M
0

I had a similar requirement and i handled in global.asax. i checked from where the request is coming and based on that i changed the header value to either sameorigin or allow-from. hope that helps.

Marquess answered 28/11, 2017 at 11:20 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.