Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why people use `rel="noopener noreferrer"` instead of just `rel="noreferrer"`

Tags:

html

security

I often see following pattern:

<a href="<external>" target="_blank" rel="noopener noreferrer"></a>

But as far as I see, noreferrer implies the effect of noopener. So why is noopener even needed here?

https://html.spec.whatwg.org/multipage/links.html#link-type-noreferrer

<a href="..." rel="noreferrer" target="_blank"> has the same behavior as <a href="..." rel="noreferrer noopener" target="_blank">.

Note that noreferrer browser support is strictly wider that one of noopener https://caniuse.com/#feat=rel-noreferrer https://caniuse.com/#feat=rel-noopener

like image 372
Philipp Ryabchun Avatar asked Aug 23 '19 15:08

Philipp Ryabchun


People also ask

Should I use rel Noopener or rel Noreferrer?

rel=noreferrer is same as rel=noopener. The only difference is that if you use rel=norefferer the owner of the destination page will never know that you are linking to his/her site. Because this attribute blocks the browser to transfer the HTTP referral header to the destination site.

Why is rel Noopener Noreferrer used?

Adding the nofollow attribute to a link that includes rel=”noopener noreferrer” allows you to link to other websites without appearing to approve their content or perspective.

Where and why is the rel Noopener attribute used?

rel=”noopener” is an HTML attribute that's added to all WordPress links that are selected to open in a new browser tab. It is also accompanied by a rel=”noreferrer” attribute. This feature was introduced in WordPress to address a security vulnerability which can be exploited by malicious websites.

What does Noopener mean?

The noopener keyword for the rel attribute of the <a> , <area> , and <form> elements instructs the browser to navigate to the target resource without granting the new browsing context access to the document that opened it — by not setting the Window.


Video Answer


2 Answers

Tag rel with "noopener" and "noreferrer" combined means that no referrer information should be passed to the website being linked to because of noreferrer tag and also prevents the newly opened page from controlling the page that delivered the traffic.

rel="noreferrer" attribute has the same effect as the rel="noopener" attribute, and it will also prevent the referrer header from being sent to the new page.

Most modern browser support noopener, but when it is not supported, we can use noreferrer. In practical terms, it makes sense to use both of them to support older browsers. There is also no good reason to remove rel="noopener" since it doesn't seem to have any downside and it is something widely considered.

like image 108
Azametzin Avatar answered Oct 28 '22 19:10

Azametzin


Yes, noreferrer implies noopener, making the additional value redundant. And an old version of Firefox even requires that noopener be omitted when using noreferrer.

Using both probably became a habit after following outdated recommendations or lint rules.

See this ESLint thread.

like image 32
jabacchetta Avatar answered Oct 28 '22 19:10

jabacchetta