zoukankan      html  css  js  c++  java
  • iframe 相关选项 x-frame-options: 设置 meta 标签无效 & helmet

    The X-Frame-Options HTTP 响应头是用来给浏览器 指示允许一个页面 可否在 <frame>, <iframe>, <embed> 或者 <object> 中展现的标记。

    站点可以通过确保网站没有被嵌入到别人的站点里面,从而避免 clickjacking 攻击。

    The added security is only provided if the user accessing the document is using a browser supporting X-Frame-Options.

    Content-Security-Policy HTTP 头中的 frame-ancestors 指令会替代这个非标准的 header。

    CSP 的 frame-ancestors 会在 Gecko 4.0 中支持,但是并不会被所有浏览器支持。

    然而 X-Frame-Options 是个已广泛支持的非官方标准,可以和 CSP 结合使用。

    X-Frame-Options 有三个可能的值:

      # 表示该页面不允许在 frame 中展示,即便是在相同域名的页面中嵌套也不允许。

      X-Frame-Options: deny

      # 表示该页面可以在相同域名页面的 frame 中展示。

      X-Frame-Options: sameorigin

      # 表示该页面可以在指定来源的 frame 中展示。

      X-Frame-Options: allow-from https://example.com/

    注意:

      设置 meta 标签是无效的!

      例如 <meta http-equiv="X-Frame-Options" content="deny"> 没有任何效果。

      不要这样用!只有当像下面示例那样设置 HTTP 头 X-Frame-Options 才会生效。

    Apache:

      Header set X-Frame-Options "sameorigin"

    Nginx:

      add_header X-Frame-Options sameorigin always;

    HAProxy:

      http-response set-header X-Frame-Options sameorigin

    Express:

      const helmet = require('helmet');

      const app = express();

        app.use(helmet.frameguard({ action: "sameorigin" }));  // app.use(helmet()) 使用所有安全策略

      

    在 Firefox 尝试加载 frame 的内容时,如果 X-Frame-Options 响应头设置为禁止访问了,那么 Firefox 会用 about:blank 展现到 frame 中。

    也许从某种方面来讲的话,展示为错误消息会更好一点。

    Refer:https://developer.mozilla.org/zh-CN/docs/Web/HTTP/Headers/X-Frame-Options

    Refer:https://www.npmjs.com/package/helmet

    Link:https://www.cnblogs.com/farwish/p/15484863.html

  • 相关阅读:
    C. 1D Sokoban 二分,思维
    E. Almost Fault-Tolerant Database 暴力枚举 + 分类讨论 + 思维 Codeforces Round #704 (Div. 2)
    Tkinter(六):Checkbutton 复选按钮
    LeetCode260. 只出现一次的数字 III
    LeetCode297. 二叉树的序列化与反序列化
    LeetCode300. 最长上升子序列
    LeetCode299. 猜数字游戏
    LeetCode295. 数据流的中位数
    你真的知道嵌入式系统的优先级吗?
    学习4412开发板gdb和gdbserver的调试
  • 原文地址:https://www.cnblogs.com/farwish/p/15484863.html
Copyright © 2011-2022 走看看