如何在nginx中正确设置X-Frame-Options Allow-From



我试图在Nginx中设置ALLOWED-FROM,但迄今为止我尝试的所有设置都导致以下Chrome错误:Invalid 'X-Frame-Options' header encountered when loading 'https://domain.com/#/register': 'ALLOW-FROM domain.com' is not a recognized directive. The header will be ignored.

我尝试的这些选项是:(也尝试了FQDN与https://前缀)

  add_header X-Frame-Options "Allow-From domain.com"; 
  add_header X-Frame-Options "ALLOW-FROM domain.com"; 
  add_header X-Frame-Options "ALLOW-FROM: domain.com";
  add_header X-Frame-Options "Allow-From: domain.com";
  add_header X-Frame-Options ALLOW-FROM "domain.com";
  add_header X-Frame-Options ALLOW-FROM domain.com;

在Chrome和Safari中您需要使用Content-Security-Policy

Content-Security-Policy: frame-ancestors domain.com

您可以在此网站查看更多详细信息:

https://developer.mozilla.org/en-US/docs/Web/Security/CSP/CSP_policy_directives

一些旧的浏览器不支持内容安全策略,所以正确的语法是

add_header X-Frame-Options "ALLOW-FROM domain.com";

和新版本的浏览器支持内容安全策略

add_header Content-Security-Policy "frame-ancestors domain.com";

你应该使用这两个标头,以确保在所有的浏览器中支持

了解更多浏览器对x帧选项和内容安全策略的支持(CSP浏览器支持数据已过时,截至2017年12月19日)。目前所有主要浏览器都支持CSP):https://www.owasp.org/index.php/Clickjacking_Defense_Cheat_Sheet

最新更新