Movatterモバイル変換


[0]ホーム

URL:


Skip to content
DEV Community
Log in Create account

DEV Community

sachindra@work
sachindra@work

Posted on

     

Unsafe use of target=”_blank”

Developers have been frequently using this attribute to open a new webpage. But this attribute, though looks pretty simple, can create a major security threat to your application.

The threat associated is called Reverse Tabnabbing. The issue is the webpage that we are linking our existing page to gains a partial access to the linking page, or in other words, the target page or url gains a partial access to our parent page from where the user is redirected to a new url. This happens through the window.opener object of Javascript. The attacker can change the window.opener.location to some malicious page and also the parent page. In case the parent page has the same look and feel of the user intended page, he might end up sharing credentials or secure information assuming that the webpage is secure.

To prevent pages from misusing window.opener property, we use rel="noopener". This ensures that window.opener is assigned to NULL. This works in Chrome 49 and above, Opera 36 and above, Firefox 52 and above, Desktop Safari 10.1+ and iOS Safari 10.3+. Though for older browsers, rel="noreferrer" works pretty fine. So, as a combination, we can use rel="noopener noreferrer" attribute.

Also, remember, whenever we open a new window using window.open() property, we’re also vulnerable to this, so, its always advisable to reset the "opener" property.

Top comments(0)

Subscribe
pic
Create template

Templates let you quickly answer FAQs or store snippets for re-use.

Dismiss

Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment'spermalink.

For further actions, you may consider blocking this person and/orreporting abuse

There is always a simple way to learn & implement things no matter how complicated that might sound 👋👋👋
  • Location
    India
  • Joined

More fromsachindra@work

DEV Community

We're a place where coders share, stay up-to-date and grow their careers.

Log in Create account

[8]ページ先頭

©2009-2025 Movatter.jp