最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - 'X-Frame-Options','SAMEORIGIN' Cross Domain Iframe issue - Stack Overflow

programmeradmin2浏览0评论

I have 2 projects in node JS. I have included the response to the header of my project is res. header('X-Frame-Options','SAMEORIGIN').

When I generate the source link and include it with the element , this link only working for my domain, I can't include the with other domains.

How can access the with a different domain

Thank you...!

I have 2 projects in node JS. I have included the response to the header of my project is res. header('X-Frame-Options','SAMEORIGIN').

When I generate the source link and include it with the element , this link only working for my domain, I can't include the with other domains.

How can access the with a different domain

Thank you...!

Share Improve this question asked Feb 5, 2021 at 5:46 Thamarai KaniThamarai Kani 111 silver badge6 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 4

when it es to security, I suggest using helmet.js. So better install helmet.js then use it as middleware for security issues. For example write code below:

const express = require("express");
const helmet = require("helmet");

app = express();
app.use(helmet({
  contentSecurityPolicy: {
    directives: {
      "frame-ancestors": ["'self'", "https://otherDomain.", "https://www.oneMoreDomain."]
    }
  }
}));

ContentSecurityPolicy's frame-ancestors is doing the same thing as FRAME-OPTIONS, but you can add whitelist of domains which will have permission using frames.

The main purpose of adding the X-Frame-Options headers is to prevent your page from being rendered within an <iframe> (or within a <frame>, <embed>, <object>). Based on the value of the header, you can prevent it pletely or just allow embedding within the same origin.

So if you need to allow rendering your page from any domain, you can just remove that header from the response.

Please refer this for more details https://developer.mozilla/en-US/docs/Web/HTTP/Headers/X-Frame-Options

发布评论

评论列表(0)

  1. 暂无评论