Window.open() 和 target= blank 有个安全漏洞

安全 应用安全
我们经常使用 HTML target="_blank" 或 window.open() 在新窗口中打开页面。但是,当新打开的页面指向一个我们不知道的网站时,我们就会被暴露在钓鱼网站的漏洞中

[[429950]]

我们经常使用 HTML target="_blank" 或 window.open() 在新窗口中打开页面。

  1. // in html 
  2. <a href="www.google.com" target="_blank">open google</a> 
  3.  
  4. // in javascript 
  5. window.open("www.google.com"

但是,当新打开的页面指向一个我们不知道的网站时,我们就会被暴露在钓鱼网站的漏洞中。新页面通过 window.opener对象获得了对链接页面的一些部分访问权限。

例如,可以使用 window.opener.location 将初始页面的用户指向一个假的钓鱼网站,该网站模仿原始网站的外观并做各种恶心的事情。鉴于用户信任已经打开的页面,这可能是非常有效的。

为了防止这种情况,我们可以:

在 HTML 中使用 rel="noopener 和 target="_blank"。

  1. <a href="someLink.com" target="_blank" rel="noopener noreferrer"
  2.     open securely in a new tab 
  3. </a> 

在Javascript中,一定要重置 opener 属性:

  1. const newWindow = window.open("someLink.com"); 
  2. newWindow.opener = null

后续:现在看来,noreferrer 是多余的,所以noopener` 对于HTML的使用应该是足够的。

作者:Daniel 译者:前端小智

来源:js-craft 原文:http://www.js-caft.io/blog/window-open-and-target_blank-have-a-security-vulnerability/

 

责任编辑:姜华 来源: 大迁世界
相关推荐

2009-12-11 16:28:09

2010-07-30 16:02:56

2010-07-26 15:37:12

telnet安全漏洞

2023-05-17 18:47:45

2010-09-29 14:05:23

2017-02-27 22:01:32

2014-06-03 09:23:41

2021-02-14 11:25:47

漏洞微软网络安全

2022-02-11 11:46:05

漏洞UEFI安全

2011-03-31 13:46:51

2010-09-17 16:16:28

2014-06-03 11:36:18

2010-08-11 14:59:35

2009-03-07 09:59:16

2011-12-26 11:22:48

2021-05-12 10:46:23

漏洞BINDDNS服务器

2020-10-09 09:52:00

漏洞分析

2021-12-19 11:55:25

NIST安全漏洞网络安全

2022-03-30 14:13:53

安全漏洞首席信息安全官

2010-03-05 15:46:05

点赞
收藏

51CTO技术栈公众号