Iframe嵌套拒绝接入

问题描述:在A系统中使用iframe嵌入B系统,出现下面错误。

在这里插入图片描述

原因:
X-Frame-Options: HTTP 响应头是用来给浏览器 指示允许一个页面 可否在, , 或者 中展现的标记。站点可以通过确保网站没有被嵌入到别人的站点里面,从而避免 点击劫持 攻击。

X-Frame-Options 有三个属性值:
deny:表示该页面不允许在frame中展示,即便是在相同域名的页面中嵌套也不允许。
sameorigin:表示该页面可以在相同域名页面的frame中展示。
allow-from uri:表示该页面可以在指定来源的frame中展示。

nginx配置
需要添加到 ‘http’, ‘server’ 或者 ‘location’ 的配置项中。正常情况下都是使用SAMEORIGIN参数,允许同域嵌套
add_header X-Frame-Options SAMEORIGIN;
允许单个域名iframe嵌套
add_header X-Frame-Options ALLOW-FROM http://whsir.com/;
允许多个域名iframe嵌套,注意这里是用逗号分隔
add_header X-Frame-Options “ALLOW-FROM https://kjgh.zjzwfw.gov.cn/”;(这里url为A系统的域名)

代码示例

server {
    listen 80;
    server_name *.xxxxxxx.xyz;

    location /public/ {
      autoindex on;
      alias /usr/local/nginx/html/web/myblog/node/public/;
    }

    location /webgate/ {
      proxy_set_header Host $host;
      proxy_set_header X-Real-IP $remote_addr;
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
      proxy_pass http://127.0.0.1:1314/api/;
    }

    location / {
      proxy_set_header Host $host;
      proxy_set_header X-Real-IP $remote_addr;
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
      # add_header X-Frame-Options deny;
      # 此处设置X-Frame-Options配置
      add_header X-Frame-Options "ALLOW-FROM  https://kjgh.zjzwfw.gov.cn/";
      if ($host ~ ^(xxxx)\.xxxxxxx\.xyz$) {
        proxy_pass http://0.0.0.0:8083;
      }
      if ($host ~ ^(xxxx)\.xxxxxxx\.xyz$) {
        proxy_pass http://0.0.0.0:8081;
      }
      if ($host ~ ^(xxxx)\.xxxxxxx\.xyz$) {
        proxy_pass http://0.0.0.0:8082;
      }
      proxy_pass http://127.0.0.1:1314/;
    }
  }

猜你喜欢

转载自blog.csdn.net/weixin_43424325/article/details/125345672
今日推荐