noopener and Reverse Tabnabbing
When your page opens a new tab, that new page can get a handle back to yours. Most of the time nothing bad happens. But when the new page is untrusted, that handle lets it quietly change what your original tab shows. The fix is a single small word, noopener.
You met it briefly in Link Security and External Links. This lesson explains how the attack works, what browsers now do for you, and the cases where the old advice still matters.
What You Will Learnβ
- What
window.openeris - What reverse tabnabbing is, and what an attacker can and cannot do
- What
rel="noopener"does - What browsers already do by default, and where that stops
- How
window.openand theCross-Origin-Opener-Policyheader fit in - When you do need the link back to the opener
The Big Ideaβ
Opening a page with target="_blank" or window.open() is like handing someone a phone line back to your room. noopener cuts the line.
- The Code
- Opener Lab
- Link Scanner
<!-- Safe and explicit -->
<a href="https://partner.example.net/" target="_blank" rel="noopener">Partner</a>
<!-- Also hides the referrer -->
<a href="https://partner.example.net/" target="_blank" rel="noopener noreferrer">Partner</a>
// window.open does not get protection by default. Ask for it.
window.open("https://partner.example.net/", "_blank", "noopener");
<a href="https://partner.example.net/" target="_blank">Partner</a>A simplified picture drawn with ordinary boxes. Nothing is opened. Setting: rel="none".
Loading the checker...
What Is window.opener?β
When one page opens another, the new page receives a reference to the page that opened it, called window.opener. It is useful for things like login popups that report back to the page that started them.
If the new page was not opened this way (for example, the visitor typed the address), window.opener is null.
Reverse Tabnabbingβ
"Tabnabbing" is a trick where a tab you are not looking at changes into something else. In reverse tabnabbing, the attack comes through the link the visitor clicked:
- A visitor is on your page, say an orders page, and clicks a link that opens a new tab to another site.
- That site (or a script on it, or a comment link posted by someone else) runs
window.opener.location = "https://login-shop.example.net/signin". - The visitor finishes reading the new tab and goes back to your tab. It now shows a fake sign-in page, with an address that looks plausible.
- They type their password, and the attacker has it.
Open the Opener Lab tab, choose the "Older" browser (keep "link" and "nothing"), and press the run button to see this unfold.
What the new page can and cannot doβ
| If the opened page is... | It can... | It cannot... |
|---|---|---|
| From another origin | Set window.opener.location (redirect your tab), send postMessage, close or focus your tab, and count its frames | Read your page's content or run scripts inside it |
| From your own origin | Everything, including reading and changing your page (see HTML Security Basics) | Nothing is out of reach |
Even a redirect is serious. Visitors trust the tab they left open, and a convincing fake sign-in page can steal passwords.
The Fix: rel="noopener"β
rel="noopener" makes the new page's window.opener null, so the line back is cut.
<a href="https://partner.example.net/" target="_blank" rel="noopener">Partner</a>
A few facts that surprise people:
- It has a speed benefit too. With no link back, the browser can run the new page separately from yours, so a heavy or slow new page is less likely to drag your page down.
noreferrerimpliesnoopener. Usingrel="noreferrer"closes the line and removes the referrer (see noreferrer). Use both words together if you want both effects clearly stated.- It works on
a,area, andformelements that have atarget. - It has no effect without a new window. A normal same-tab link does not create an opener.
What Browsers Already Doβ
Modern browsers treat target="_blank" as if rel="noopener" were present. That means the classic attack above no longer works on a current browser for plain links. But you should still add the word, for these reasons:
- Older browsers and some embedded web views do not apply the default.
- Being explicit makes your intent obvious to the next developer, and to tools that scan your code.
- The default is narrow. It applies to
_blank. A link with a custom name, such astarget="popup", can reuse an existing named window, and does not get the same automatic protection. window.open()in JavaScript does not get it automatically. You must pass"noopener"in the features string.rel="opener"turns it off on purpose. If you find that word in your code, ask why.
The Opener Lab lets you flip between modern and older browsers and between a link and window.open, so you can see where protection depends on the browser.
window.open and noopenerβ
const win = window.open("https://partner.example.net/", "_blank", "noopener");
console.log(win); // null, because the new window has no link to yours
When you pass "noopener", the browser returns null instead of a window object. That is expected, so do not treat it as an error. If your code needs to talk to the opened window, you cannot use noopener.
The Header: Cross-Origin-Opener-Policyβ
Everything above protects your links. But what about someone else's page that opens yours? A header can protect your page from that:
Cross-Origin-Opener-Policy: same-origin
With this header, your page is placed in a separate group from pages of other origins, and any opener relationship across origins is cut, in both directions. Other values, such as same-origin-allow-popups, relax this to allow popups you open to keep a link to you.
Some features depend on an opener link, such as certain login and payment popups. Strict settings can break them. Test sign-in and payment flows after you add this header, and read your provider's current guidance. See Content Security Policy for another header-based layer.
When You Do Need the Openerβ
Sometimes a page really does need to talk to the window it opened, such as a sign-in popup that returns a result. If so:
- Open only trusted pages with
window.openerintact. - Use
postMessageinstead of direct access, and checkevent.originagainst an exact value, as shown in iFrame Security. - Never rely on
window.openeralone to decide who the sender is. - Keep the link as short-lived as you can, and close the popup when it is done.
- Prefer a redirect-based sign-in flow when your provider offers one, since it needs no opener at all.
User-Submitted Linksβ
If your site lets visitors post links, such as in comments or profiles, they are untrusted by definition. Make sure the link markup your code produces includes rel="noopener noreferrer" when it uses target="_blank". Separately, the values nofollow and ugc tell search engines that the link was not editorially placed. They are about search, not security, so do not confuse them with noopener. Also check that only http and https addresses are allowed, as covered in XSS Basics.
Checking Your Setupβ
- In DevTools, open Elements and search for
target="_blank". Check each one hasrel="noopener"orrel="noreferrer". - Search your JavaScript for
window.open(and check each call passes"noopener"unless it truly needs the opener. - Search for
rel="opener", and justify every match. - Open a link in a new tab and type
window.openerin the new tab's Console. It should benullfor a protected link. - Check the Response Headers of your page for
Cross-Origin-Opener-Policy. - Use the Link Scanner above on a few of your own links.
Best Practicesβ
- Add
rel="noopener"(ornoopener noreferrer) to everytarget="_blank"link. - Pass
"noopener"towindow.openunless you need the opener. - Do not use
rel="opener"without a clear reason. - Add the word even though modern browsers help, for older browsers and clarity.
- Scan user-generated links and add protection automatically.
- Use
postMessagewith an exact origin check when a link back is needed. - Test login and payment popups after any header change.
- Warn visitors when a link opens a new tab, for accessibility, as in External Links.
Quick Checklistβ
- Every
target="_blank"link hasnoopenerornoreferrer -
window.opencalls pass"noopener" - No
rel="opener"without a comment explaining why - User-submitted links get protection added by your code
- Any needed opener use relies on
postMessagewith origin checks - Sign-in and payment flows still work after header changes
Security and Privacy Notesβ
- The attack needs the visitor's trust in the old tab. It depends on people returning to a tab they believe they know. A short, clear address and a habit of checking the address bar help visitors, but your code should not rely on that.
- Your own scripts can be the weak link. A third-party script on your page can also call
window.open. Review what you include, as covered in Third-Party Content Security. noopenerdoes not hide the referrer. That isnoreferrer. It also does not stop the new page from tracking the visitor through its own scripts.- Test only your own pages, or those you have permission to test.
Global Audience Notesβ
- Older browsers and embedded web views are still common in some regions, and on older phones. Protection that does not depend on the browser default is safer.
- Many visitors use shared or family devices and keep many tabs open for days, which is the situation the attack relies on.
- Say in the page's language that a link opens a new tab, using visible text or an icon with an accessible name.
Common Mistakes to Avoidβ
- Leaving
reloff because "browsers fix it now". - Forgetting
window.open. - Using
noreferrerand assuming that is the only job ofnoopener, or the reverse. The words are related but separate. - Writing
rel="noopener"on a link with notarget, and thinking it does something. - Using
rel="opener"for convenience. - Treating a
nullreturn fromwindow.open("...", "_blank", "noopener")as a bug. - Letting
window.openerdecide trust instead of checkingevent.origin. - Not protecting links that visitors post.
- Adding a strict
Cross-Origin-Opener-Policywithout testing login popups. - Never re-checking links after a redesign or a CMS change.
Practice Timeβ
- In the Opener Lab, choose the "Older" browser with a plain link and nothing added, then press the run button. What does the original tab turn into?
- Choose
noopener, and run it again. What changes? - Switch to a modern browser with "nothing" selected for a link. Is the page protected? Now switch to
window.open(). What happens? - Choose
openerfor a link in a modern browser. What does it do? - Tick "my own origin" with an unprotected link. How does the message differ?
- Paste your own links into the Link Scanner, and fix every problem it reports.
- Open any link with
target="_blank"on a site you own, and checkwindow.openerin the new tab's Console. - Bonus: write a small function that adds
rel="noopener noreferrer"to every outbound link in a block of user comments (usingtextContentfor the text, as in XSS Basics).
Quick Recapβ
Click a question to check your answer.
1. What is window.opener?
A reference, available to a page opened by another page, that points back to the page that opened it.
2. What is reverse tabnabbing?
A new page you opened uses window.opener.location to turn your original tab into something else, such as a fake sign-in page, while the visitor is not looking.
3. Can a cross-origin opened page read your page?
No. But it can redirect your tab, send messages, and close or focus it. A same-origin page has full access.
4. What does rel="noopener" do?
It makes window.opener null in the new page, so it has no link back to yours.
5. Do modern browsers make it unnecessary?
Not entirely. They apply noopener to target="_blank" links, but not to window.open(), custom-named targets, or older browsers. Being explicit is still best.
6. What if you really need the opener?
Open only trusted pages, communicate with postMessage, check event.origin exactly, and close the popup when it is finished.
Key Takeawaysβ
window.openeris a link back to the page that opened a window. Untrusted pages can use it to redirect your tab.rel="noopener"cuts the link.noreferrerdoes that too, and also removes the referrer.- Browsers help for
_blanklinks, but not forwindow.open, custom targets, or older browsers. rel="opener"andCross-Origin-Opener-Policychange this behaviour on purpose, so use them with care.- When you need the link, use
postMessagewith exact origin checks. - Scan links regularly, especially user-submitted ones.
Next up: Content Security Policy, where you will learn how a single header tells the browser which sources of scripts, styles, and frames to trust.