Security risk for opening new tabs or windows

Background

Today eslint reports an error when I introduce eslint-plugin-react

error  Using target="_blank" without rel="noopener noreferrer" is a security risk: see https://mathiasbynens.github.io/rel-noopener  react/jsx-no-target-blank

Why

Opening a new tab/window, either by hyperlinks (i.e <a> tag with target attribute set to _blank) or programmatically calling window.open, will grant the newly-opened tab/window access back to the originating tab/window via window.opener. Therefore, the newly opened tab/window can then change the window.opener.location to redirect to the phishing page in the background, or execute some JavaScript on the opener-page on your behalf.

How to fix

Add rel="noopenner" to outgoing links. E.g.

<a href="https://abc.com" target="_blank" rel="noopener">
window.open('https://abc.com', 'security', 'noopener');
  • Reset opener property

Note: this technique is subject to Same Origin Policy

let nw = window.open('https://abc.com', 'security');
nw.opener = null;

Reference

Notice

  • If you want to follow the latest news/articles for the series of my blogs, Please 「Watch」to Subscribe.
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • rljs by sennchi Timeline of History Part One The Cognitiv...
    sennchi阅读 7,486评论 0 10
  • **2014真题Directions:Read the following text. Choose the be...
    又是夜半惊坐起阅读 10,053评论 0 23
  • 2017年9月11日觉察日记+尚军伟+9号 今天一天都在激动、紧张中度过! 呼吸加速、心跳加快,整个人的身体都处于...
    浩子爸阅读 400评论 4 8
  • 终于定了《余歌课程》复训时间,中午12点出发,坐大巴转商务拼车直到动车晚点,晚上11点多终于到厦门北了。在此过程中...
    蓝天虹阅读 123评论 0 0
  • 我们这代人的情感多少有点发育不全。父母师长惯于施威,青春期闭塞压抑,成年后又钻进网络,大量精力和感情投射到影视角色...
    _呵呵哒_阅读 230评论 0 0