window.opener and target=”_blank”: The Tabnabbing Risk Explained

By Marko Denic
Contents
  1. What the opened page can do
  2. How reverse tabnabbing works
  3. The fix: rel=”noopener”
  4. In HTML
  5. In JavaScript
  6. What browsers do today
  7. Protect your whole site with COOP
  8. When you actually need window.opener
  9. Popups that report back: use postMessage
  10. FAQ

window.opener is a reference to the window that opened the current one. When page A opens page B with window.open() or a target="_blank" link, page B can read window.opener and get a handle on page A.

For pages on the same site, that’s useful. For pages on other sites, it was a security hole called reverse tabnabbing, and it’s the reason rel="noopener" exists.

What the opened page can do

Across different sites, the browser blocks almost everything: the new page can’t read the opener’s content, cookies or DOM. But it can still change the opener’s location.

javascript
// Running on the page that was opened in a new tab
if (window.opener) {
  window.opener.document.title;  // blocked across origins: throws
  window.opener.location = 'https://evil.example/login'; // allowed!
}

How reverse tabnabbing works

  1. You’re on a site you trust (your bank, a forum, your email) and click a link to an external page. It opens in a new tab.
  2. That external page (malicious, or compromised) runs window.opener.location = 'https://fake-login.example'.
  3. While you read the new tab, your original tab quietly navigates to a perfect copy of the trusted site’s login page.
  4. You switch back, see “Your session expired, please log in again” in the tab you trust, and type your password.

The attack works because nobody expects a tab they left alone to change. It was a real risk for any site that lets users post links: forums, comments, social networks, webmail.

The fix: rel=”noopener”

In HTML

rel="noopener" opens the link without giving the new page an opener: window.opener is null. As a bonus, the new tab can run in its own process, so a heavy page there doesn’t slow yours down. noreferrer includes noopener and also hides your URL from the other site. See how to open a link in a new tab for the full details.

html
<a href="https://external.example" target="_blank" rel="noopener">Safe</a>
<a href="https://external.example" target="_blank" rel="noopener noreferrer">Safe and private</a>

In JavaScript

Pass 'noopener' in the third argument of window.open(). The new window has no opener, and window.open() returns null instead of a window reference.

javascript
window.open('https://external.example', '_blank', 'noopener');

// Older pattern, before the 'noopener' feature existed
const win = window.open('https://external.example', '_blank');
if (win) win.opener = null;

What browsers do today

Since around 2021, all major browsers treat target="_blank" links as if they had rel="noopener", unless you explicitly add rel="opener". So reverse tabnabbing through plain links is largely fixed in current browsers.

It’s still worth adding rel="noopener": older browsers in the wild don’t have the default, window.open() without 'noopener' still sets an opener, and linters and security scanners will flag links without it.

Protect your whole site with COOP

The Cross-Origin-Opener-Policy response header tells the browser to cut the opener link between your pages and other sites in both directions, whatever the links say. same-origin-allow-popups keeps popups you open (like payment or login windows) working.

bash
Cross-Origin-Opener-Policy: same-origin-allow-popups

When you actually need window.opener

Popups that report back: use postMessage

Login popups (OAuth, “Sign in with…”), payment windows and file pickers often need to send a result back to the page that opened them. Do it with postMessage, always with an explicit target origin, and check event.origin on the receiving side.

javascript
// Main page: open the popup and listen
const popup = window.open('/auth/start', 'login', 'width=500,height=600');

window.addEventListener('message', (event) => {
  if (event.origin !== 'https://example.com') return; // only trust yourself
  if (event.data.type === 'auth-success') {
    console.log('Logged in as', event.data.user);
  }
});

// Popup page (same site), when done:
window.opener?.postMessage(
  { type: 'auth-success', user: 'marko' },
  'https://example.com' // never '*' for sensitive data
);
window.close();

FAQ

What is window.opener in JavaScript?

A property that references the window that opened the current one, through window.open() or a link with a target. It’s null if the page was opened directly or with noopener.

What is reverse tabnabbing?

An attack where a page opened in a new tab uses window.opener.location to redirect the original tab to a phishing page while the user isn’t looking.

Do I still need rel=”noopener” in 2026?

Current browsers apply it by default to target="_blank", so it’s no longer critical, but it’s a cheap safety net for older browsers and keeps audit tools quiet.

Why is window.opener null in my popup?

The popup was opened with noopener, through a target="_blank" link (which now implies it), or a Cross-Origin-Opener-Policy header cut the link. Open it with window.open() without 'noopener', and keep it on the same site.