reactjs - 我们可以防止来自客户端渲染的 React JS 应用程序的点击劫持吗?
问题描述
我有一个客户端反应应用程序。我想阻止我的网站在其 iframe 中被任何其他网站打开。我看到使用标题中设置的 X-Frame-Options 是一个选项。但这可以从客户端应用程序中完成吗?还是只需要从服务器端完成?将点击劫持应用到客户端反应应用程序的任何最佳方法都将对我的应用程序有所帮助。
解决方案
const UnsecuredPageWarning = styled.h1`
color: red;
`;
const Link = styled.a`
text-decoration: none;
color: red;
`;
const UnsecuredPage: FunctionComponent = (): ReactElement => (
<div>
<UnsecuredPageWarning>If you see this page, Webb App link you have clicked on is under Clickjacking security attack.</UnsecuredPageWarning>
<h2>Please inform team with the reference of the application from where you clicked this link.</h2>
<h2>Click <Link href={window.self.location.href} title='Web Application' target='blank'>here</Link> to access WebApp safely.</h2>
</div>
);
// Won't render the application if WebApp is under Clickjacking attack
if(window.self === window.top) {
ReactDOM.render(<WrappedApp />, document.getElementsByClassName('app')[0]);
} else{
ReactDOM.render(<UnsecuredPage />, document.getElementsByClassName('app')[0]);
}
还在网页中用下面的html测试了上面的代码
<html>
<head>
<title>Clickjack test page</title>
</head>
<body>
<iframe src="http://localhost:3000/login" width="900" height="300"></iframe>
</body>
</html>
推荐阅读
- r - 如何使用 R + Selenium WebDriver 保存和导入 cookie
- geomesa - 如何从 Geomesa HBase 表中读取数据?
- php - 在下拉表单字段上创建选择选项
- r - 如何将 Sentinel-3 .nc 文件转换为 .tiff 文件?
- python - 将索引的空 Pandas 数据框保存到 excel 会引发越界错误
- kotlin - 如何合并两个对象列表并识别相同的元素
- android - AndroidJUnitRunner - 它是否以任何特定顺序运行测试用例?
- java - 带有undertow的静态资源,来自fatjar
- javascript - 分配给范围的链接函数在控制器构造函数中不可访问
- javascript - 使用 Extjs 存储的基本身份验证