【问题标题】:add_header X-Frame-Options DENY; in nginx conf is not working, i can still see the iframe in our applicationadd_header X-Frame-Options DENY;在 nginx conf 中不起作用,我仍然可以在我们的应用程序中看到 iframe
【发布时间】:2019-06-18 11:16:44
【问题描述】:

add_header X-Frame-Options DENY; 似乎不适合我们。

我们打算将我们的托管页面之一显示为 PCI 相关问题的 iframe,我们成功了,但为了避免 点击劫持,我们建议使用 x-frame-options DENY,但我们可以不要那样做,因为我们希望我们的用户使用我们开发的框架,所以解决方案可能是使用x-frame-options ALLOW FROM uri

我们正在尝试add_header X-Frame-Options DENY; 来查看我们的应用程序是否首先限制了 iframe,但 iframe 仍然可见。我们多次验证了 add header 是否在 nginx conf 中的位置错误,但事实并非如此。

P.S. 下图是 ref,但我们仍然可以看到 angular 应用程序成功渲染了帧 :(

【问题讨论】:

  • 为什么是content-typetext/plain?!
  • 我粘贴了该图像,因为我们在应用程序中呈现的每个文件中都看到了该图像。 @cnst
  • 测试时,您是否嵌入了来自另一个域的iframe
  • no iframe 来自同一个域 [parent(somename.mylab.io) 和 iframe(othername.mylab.io) 中的子级]
  • 您能否确认 x-frame-options 标头是在对 index.html 请求的响应中设置的,而不是某些资产或 API 调用

标签: angular nginx iframe x-frame-options clickjacking


【解决方案1】:

nginx.conf

location 块下添加以下代码
add_header X-Frame-Options "DENY" always;

例子

 location / {
        expires -1;
        add_header Pragma "no-cache";
        add_header Cache-Control 'no-store, no-cache, must-revalidate, proxy-revalidate, max-age=0, post-check=0, pre-check=0';
        add_header X-Frame-Options "DENY" always;
        root  <root directory>;
        index  index.html index.htm;
        try_files $uri $uri/ /index.html?$args;
   }

【讨论】:

    【解决方案2】:

    假设您的托管页面位于 URI1 中,而您的托管页面位于 URI2 中

    发送 GET 请求直接获取 URI1 时的响应标头是什么?

    我认为您将“x-frame-option”添加到 URI2 而不是 URI1 的响应中

    【讨论】:

      【解决方案3】:

      您可能使用的是旧浏览器,因为它适用于 Chrome 68。您可以使用 F12 检查 Javascript 错误和 HTTP 标头。

      &lt;iframe src="https://www.facebook.com"&gt;&lt;/iframe&gt;

      【讨论】:

      • 不,我尝试使用 chrome 和 firefox 最新版本。 @youkouleley
      • 你能确认你在运行我的 sn-p 时没有看到 facebook 页面吗?
      • 我的朋友,我想在我的应用程序中看到相同的行为。我很久以前尝试过同样的例子。问题是为什么它在我的应用程序中不起作用!
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-07-25
      • 2015-09-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-10-17
      • 2017-04-03
      相关资源
      最近更新 更多