The Security Vulnerabilities of The Target="_Blank" Attribute

undefined or mostly null.
Search for a command to run...

undefined or mostly null.
Thanks for sharing, I've always wondered why React keeps yelling at me to include that attribute.
thanks so so much for sharing this, I have something to make reference to.
That is truly incredible. Thank you for sharing the knowledge Balaji. I had been blindly using this target='_blank' for many years, without really giving a thought about the technicalities and the possible vulnerabilities if any.
It is a master piece ;)
Glad I could help, thanks for reading.
Now I fully understand the warning message reactjs displays in my console; that using target="blank" without rel="noopenner noreferrer" is discouraged.
Thanks Bolaji Ayodeji for this insightful article.
Wow! Never knew this until now and I make use of the attribute a lot. Thanks for this chief!
😂😂. Nice one!
In this series, I will share articles related to best practices for building and deploying applications on the web with the JavaScript and Python programming languages.
The HTML list tag allows you to list ordered and unordered items. One major UI problem I had with list items is the position of the ::marker (bullet) pseudo-element in a list item. The ::marker pseudo-element selects the marker box of a list item, w...
I wrote this article in December 2023 for an interview screening task and thought to share it today while clearing my drafts for some new content prep, just in case it's still helpful to someone out t

Hey! I’m super excited to announce that I have joined the Secretariat Team at the Digital Public Goods Alliance. In this role, I leverage my passion for open source and technical background to assess DPG applications, provide technical support and ad...

Creative designs have become more important than ever in the software ecosystem today with many industries and end-consumers having several use cases that require them to offer design editing solutions to either designers or end-consumers. Every busi...

With the rise of artificial intelligence (AI) and large language models (LLMs), it has become easier to solve different human problems than ever before. Even consumers with little to no technical expertise can benefit from AI. Humans can now automate...

Some years ago, GitHub introduced the new Profile README feature that allowed GitHub users to pin a markdown file on their profile using a special repository named after their GitHub username. Since then, developers have used this file as a quick por...

The HTML hyperlink tag allows you to create an element that can be clicked on to reference another document or section on a web page. Hyperlinks are defined with the HTML <a> tag like so:
<a href="/about">About Page"></a>
While the href attribute specifies the destination address of the link, another common attribute is target which is used to specify where to open the destination address of the link. You can either open the link in:
_self_selfMost often, you'll find yourself only using the _blank target attribute than others since the frame, and frameset tags are obsolete in HTML5.
Every new window has the opener API, and when you click on an external link with target="blank, the new tab has a window.opener which points to the parent window and can run on the same process as the parent (unless site isolation is enabled). So when a user clicks the external link, the new page opened has control over the parent document's window object.
Since the new page can access the parent window object with the window.opener property, it can redirect the external page to a malicious URL, which makes your site or users vulnerable and exposed to data theft or other phishing attacks (and since users trust your website already, they can easily be a victim).
window.opener.location = newURL
Phishing is the fraudulent attempt to obtain sensitive information such as usernames, passwords and credit card details by disguising oneself as a trustworthy entity in an electronic communication. ~Wikipedia
When using the target blank attribute, please ensure to add rel="noopener noreferrer" attribute to avoid exploitation of the window.opener API available on every page.
Adding the rel="noopener noreferrer" attribute on the parent <a> element will allow the new window run in a separate process and prevent the window.opener reference from being set, which means the property will equal null.
var newWindow = window.open();
newWindow.opener = null;
newWindow.location = url;
When a user moves from URL A to URL B, URL B still receives information (like traffic data) about the previous web location (URL A) even though it's owned by a different user. Adding the rel="noreferrer" attribute on the parent would prevent sending request "referrer" header information between both locations.
<a href="https://hashnode.com/devblog" target="_blank" rel="noopener noreferrer">
Create your Devblog today
</a>
By adding the rel="noopener" or rel="noreferrer" attribute to an external link, it will prevent a new tab from taking advantage of the JavaScript window.opener property which therefore improves the security and performance of your site (since the new window is running on a separate process, any script on it won't affect the referring or parent window).