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

╄→гoц情女王★ 提交于 2019-12-22 03:44:43

问题


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

  • X-Frame-Options: SAMEORIGIN
  • X-Frame-Options: ALLOW-FROM https://example.com/

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?


回答1:


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:

  • frame-ancestors obsoletes X-Frame-Options - meaning that if frame-ancestors is present and the browser supports it, it will override the behaviour of X-Frame-Options.
  • Internet Explorer and Edge do not currently support the frame-ancestors directive, according to MDN. This means they will fall back to X-Frame-Options. If you need to support multiple origins in IE or Edge, see this answer on SO with a workaround.



回答2:


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.



来源:https://stackoverflow.com/questions/45204258/how-to-set-x-frame-options-to-allow-from-https-example-com-and-sameorigin-on-s

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!