美文网首页
iframe跨域安全

iframe跨域安全

作者: 涅槃快乐是金 | 来源:发表于2022-03-09 20:04 被阅读0次

1.响应头X-Frame-Options

响应头X-Frame-Options是用来给浏览器指示允许一个页面可否在<frame><iframe><object>中展现的标记。网站可以使用此功能,来确保自己网站的内容没有被嵌套到其他网站中去,也从而避免了点击劫持 (clickjacking) 的攻击。

支持的指令

  • DENY 表示该页面不允许在frame中展示,即便是在相同域名的页面中嵌套也不允许。
  • SAMEORIGIN 表示该页面可以在相同域名页面的frame中展示。
  • ALLOW-FROM uri1,uri2 表示该页面可以在指定来源的frame中展示。

在nginx中配置

add_header X-Frame-Options DENY;
add_header X-Frame-Options SAMEORIGIN;
add_header X-Frame-Options "ALLOW-FROM http://www.a.com,http:///www.b.com";

兼容性

ALLOW-FROM指令在除IE以外的很多浏览器中无效,如在chrome中报错如下:

Invalid 'X-Frame-Options' header encountered when loading 'http://www.a.com':
 'ALLOW-FROM http://www.a.com' is not a recognized directive.
 The header will be ignored.

2.响应头Content-Security-Policy

响应头Content-Security-Policy允许网站管理员控制允许用户代理为给定页面加载的资源。除少数例外,策略主要涉及指定服务器源和脚本端点。这有助于防止跨站点脚本攻击(XSS)。

支持的指令

  • frame-ancestors uri1 uri2 允许一个页面可否在<frame><iframe><object><embed>,或<applet>中展现。 将此指令设置’none’为类似于X-Frame-Options: DENY

在nginx中配置

add_header Content-Security-Policy "frame-ancestors ‘none’";
add_header Content-Security-Policy "frame-ancestors http://www.a.com http://www.b.com";

兼容性

IE浏览器不支持

3.子域名跨域

site1.a.com

document.domain = "a.com";

site2.a.com

document.domain = "a.com"

将不同子域名的站点document.domain设置为相同的基础域名,则可实现跨域访问

相关文章

  • iframe跨域安全

    1.响应头X-Frame-Options 响应头X-Frame-Options[https://cloud.ten...

  • iframe页面相互调用方法

    关键词:iframe,跨域,vue最近的项目中嵌入了外部的iframe,想跨域调用自己页面的方法,点击iframe...

  • Iframe高度自适应

    1. 同域iframe高度自适应 2. 跨域iframe高度自适应

  • iframe

    一、iframe跨域的几种常用方法 1、postmessage window.postMessage方法可以安全地...

  • 前端如何解决常见跨域问题

    跨域解决方案 1、 通过jsonp跨域 2、 document.domain + iframe跨域 3、 loca...

  • Web前后端跨域问题处理

    跨域问题有前台跨域(iframe间)和后台跨域。 前台跨域的解决方案可以采用跨域文档通讯(Cross domain...

  • PHP跨域问题

    使用iframe方式实现局部刷新,但是iframe不支持跨域 通过script方式,src属性可以实现跨域,但只能...

  • 前端常见跨域解决方案

    一、通过Jsonp跨域二、document.domain+iframe 跨域三、location.hash+ifr...

  • cookie和跨域数据交互(jsonp)

    cookie: 跨域数据交互(jsonp) 谁能跨域:JSONP/iframe-window.name/h5-PO...

  • FE-interview-Q&A

    浏览器标签页通信 WebSocket (可跨域) postMessage(可跨域)iframe 父子通信np = ...

网友评论

      本文标题:iframe跨域安全

      本文链接:https://www.haomeiwen.com/subject/ihcxdrtx.html