如何在服务器上将 X-Frame 选项设置为 ALLOW-FROM https://example.com 和 SAMEORIGIN

2024-03-14

我需要在服务器级别至:

  • X 框架选项:SAMEORIGIN
  • X 框架选项:ALLOW-FROMhttps://example.com/ https://example.com/

了解 X 框架选项是互斥的。看here https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-Frame-Options.

但是,我的应用程序需要框架https://example.com https://example.com也来自其同源.

请告知是否有办法解决这个问题,同时保留我的应用程序的允许框架的要求同源并被框起来1 个外部站点.

或者这是不可能的?


除了仅支持一个标头实例之外,X-Frame-Options仅支持一个站点,SAMEORIGIN or not.

你必须使用Content-Security-Policy and frame-ancestors,它确实支持多个来源,如下所示:

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

需要记住的几点:

  • frame-ancestors过时的X-Frame-Options https://w3c.github.io/webappsec-csp/#frame-ancestors-and-frame-options- 意思是如果frame-ancestors存在并且浏览器支持它,它将覆盖的行为X-Frame-Options.
  • Internet Explorer 不支持frame-ancestors指示,根据MDN https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy/frame-ancestors#Browser_compatibility。这意味着他们将回落到X-Frame-Options。如果您需要在 IE 中支持多个来源,请参阅 SO 上的此答案以及解决方法 https://stackoverflow.com/a/42257574/4220785.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何在服务器上将 X-Frame 选项设置为 ALLOW-FROM https://example.com 和 SAMEORIGIN 的相关文章

随机推荐