Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[网络] 9. 什么是点击劫持?如何防范? #946

Open
qiilee opened this issue Feb 24, 2020 · 0 comments
Open

[网络] 9. 什么是点击劫持?如何防范? #946

qiilee opened this issue Feb 24, 2020 · 0 comments

Comments

@qiilee
Copy link
Member

qiilee commented Feb 24, 2020

答案:

什么点击劫持?最常见的是恶意网站使用 <iframe> 标签把我方的一些含有重要信息类如交易的网页嵌入进去,然后把 iframe 设置透明,用定位的手段的把一些引诱用户在恶意网页上点击。这样用户不知不觉中就进行了某些不安全的操作。

有两种方式可以防范:

  1. 使用 JS 防范:
    if (top.location.hostname !== self.location.hostname) {
    alert("您正在访问不安全的页面,即将跳转到安全页面!");
    top.location.href = self.location.href;
    }

  2. 使用 HTTP 头防范:
    通过配置 nginx 发送 X-Frame-Options 响应头,这样浏览器就会阻止嵌入网页的渲染。更详细的可以查阅 MDN 上关于 X-Frame-Options 响应头的内容。
    add_header X-Frame-Options SAMEORIGIN;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant