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

前端 未结 2 1701
孤街浪徒
孤街浪徒 2021-02-13 05:15

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

  • X-Frame-Options: SAMEORIGIN
  • X-Frame-Options: A
2条回答
  •  一向
    一向 (楼主)
    2021-02-13 06:07

    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.

提交回复
热议问题