Skip to main content

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.opener is
  • 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.open and the Cross-Origin-Opener-Policy header 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.

index.html
<!-- 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>
script.js
// window.open does not get protection by default. Ask for it.
window.open("https://partner.example.net/", "_blank", "noopener");

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:

  1. A visitor is on your page, say an orders page, and clicks a link that opens a new tab to another site.
  2. 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".
  3. 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.
  4. 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 originSet window.opener.location (redirect your tab), send postMessage, close or focus your tab, and count its framesRead your page's content or run scripts inside it
From your own originEverything, 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.
  • noreferrer implies noopener. Using rel="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, and form elements that have a target.
  • 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:

  1. Older browsers and some embedded web views do not apply the default.
  2. Being explicit makes your intent obvious to the next developer, and to tools that scan your code.
  3. The default is narrow. It applies to _blank. A link with a custom name, such as target="popup", can reuse an existing named window, and does not get the same automatic protection.
  4. window.open() in JavaScript does not get it automatically. You must pass "noopener" in the features string.
  5. 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.

warning

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:

  1. Open only trusted pages with window.opener intact.
  2. Use postMessage instead of direct access, and check event.origin against an exact value, as shown in iFrame Security.
  3. Never rely on window.opener alone to decide who the sender is.
  4. Keep the link as short-lived as you can, and close the popup when it is done.
  5. Prefer a redirect-based sign-in flow when your provider offers one, since it needs no opener at all.

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​

  1. In DevTools, open Elements and search for target="_blank". Check each one has rel="noopener" or rel="noreferrer".
  2. Search your JavaScript for window.open( and check each call passes "noopener" unless it truly needs the opener.
  3. Search for rel="opener", and justify every match.
  4. Open a link in a new tab and type window.opener in the new tab's Console. It should be null for a protected link.
  5. Check the Response Headers of your page for Cross-Origin-Opener-Policy.
  6. Use the Link Scanner above on a few of your own links.

Best Practices​

  1. Add rel="noopener" (or noopener noreferrer) to every target="_blank" link.
  2. Pass "noopener" to window.open unless you need the opener.
  3. Do not use rel="opener" without a clear reason.
  4. Add the word even though modern browsers help, for older browsers and clarity.
  5. Scan user-generated links and add protection automatically.
  6. Use postMessage with an exact origin check when a link back is needed.
  7. Test login and payment popups after any header change.
  8. Warn visitors when a link opens a new tab, for accessibility, as in External Links.

Quick Checklist​

  • Every target="_blank" link has noopener or noreferrer
  • window.open calls 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 postMessage with 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.
  • noopener does not hide the referrer. That is noreferrer. 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​

  1. Leaving rel off because "browsers fix it now".
  2. Forgetting window.open.
  3. Using noreferrer and assuming that is the only job of noopener, or the reverse. The words are related but separate.
  4. Writing rel="noopener" on a link with no target, and thinking it does something.
  5. Using rel="opener" for convenience.
  6. Treating a null return from window.open("...", "_blank", "noopener") as a bug.
  7. Letting window.opener decide trust instead of checking event.origin.
  8. Not protecting links that visitors post.
  9. Adding a strict Cross-Origin-Opener-Policy without testing login popups.
  10. Never re-checking links after a redesign or a CMS change.

Practice Time​

  1. 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?
  2. Choose noopener, and run it again. What changes?
  3. Switch to a modern browser with "nothing" selected for a link. Is the page protected? Now switch to window.open(). What happens?
  4. Choose opener for a link in a modern browser. What does it do?
  5. Tick "my own origin" with an unprotected link. How does the message differ?
  6. Paste your own links into the Link Scanner, and fix every problem it reports.
  7. Open any link with target="_blank" on a site you own, and check window.opener in the new tab's Console.
  8. Bonus: write a small function that adds rel="noopener noreferrer" to every outbound link in a block of user comments (using textContent for 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.opener is a link back to the page that opened a window. Untrusted pages can use it to redirect your tab.
  • rel="noopener" cuts the link. noreferrer does that too, and also removes the referrer.
  • Browsers help for _blank links, but not for window.open, custom targets, or older browsers.
  • rel="opener" and Cross-Origin-Opener-Policy change this behaviour on purpose, so use them with care.
  • When you need the link, use postMessage with 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.