The Evolving Landscape of External Links: Why `rel=”noopener noreferrer”` Still Matters (Mostly)

In the fast-paced world of web development, security and performance are paramount. For years, web developers have diligently added the rel="noopener noreferrer" attribute to external links, especially those opening in new tabs (target="_blank"). This practice was a critical safeguard against potential security vulnerabilities and performance issues. But with browsers constantly evolving, is this still a necessary manual step in 2025/2026? Let’s dive into the nuances.

The Historical Problem: `window.opener` and Tabnabbing

Kinsta Hosting Banner

Historically, when a link with target="_blank" was clicked, the newly opened tab or window could gain a reference to the originating window via the window.opener object. This created a security vulnerability known as tabnabbing. A malicious external site could then manipulate the originating page (e.g., redirect it to a phishing site) without the user’s knowledge, compromising user trust and data.

Beyond security, this connection could also lead to performance degradation. The new tab could run JavaScript that consumed resources, potentially slowing down the originating page.

Modern Browsers to the Rescue: Automatic Protection

Good news for modern web development! As of 2025/2026, most contemporary browsers have implemented automatic protections against the window.opener vulnerability for links using target="_blank". This means that when a user clicks an external link set to open in a new tab, the browser automatically treats it as if rel="noopener" were present, effectively nullifying the window.opener reference. The noreferrer attribute, which prevents the new page from seeing the referrer information, is also often implicitly handled or less critical for security in this specific context, though still valuable for privacy.

Why Explicitly Adding `rel=”noopener noreferrer”` Can Still Be Good Practice

While modern browsers offer significant built-in protection, explicitly adding rel="noopener noreferrer" remains a recommended practice for several reasons:

How to Check for Potential Issues (and Ensure Best Practices)

Even with automatic browser handling, it’s wise to periodically audit your site, especially if you have legacy content or custom JavaScript that manipulates links:

  1. Browser Developer Tools: Inspect external links that open in new tabs. While the rel attribute might not always be explicitly visible in the HTML if the browser is handling it, you can often check the computed styles or JavaScript properties to confirm window.opener is null.
  2. Security Scanners: Utilize modern security scanning tools. These tools are updated to understand current browser behaviors and can flag genuine vulnerabilities or areas where explicit attributes might still be beneficial.
  3. Code Review: Regularly review your codebase for how external links are generated, particularly in dynamic content or through JavaScript. Ensure that any custom link generation logic accounts for modern security practices.

Actionable Steps for a Secure and Performant Site

Here’s how to ensure your external links are optimized for security and performance in 2025/2026:

1. For Manually Coded Links:

Always include rel="noopener noreferrer" when using target="_blank":

<a href="https://external-site.com" target="_blank" rel="noopener noreferrer">External Link</a>

2. For WordPress Sites:

WordPress, in its ongoing efforts to enhance security, automatically adds rel="noopener noreferrer" to links with target="_blank" when they are inserted through the editor. Verify this behavior, and if you have custom themes or plugins, ensure they don’t override this default. For older installations or custom scenarios, you might still use functions like:

// Automatically add rel attributes to external links in content
function add_rel_attributes_to_external_links($content) {
    $content = preg_replace_callback(
        '/<a[^>]+href=["\\]([^"\\]+)["\\][^>]*>/i',
        function($matches) {
            $link = $matches[0];
            $url = $matches[1];
            // Check if it's an external link and opens in a new tab
            if (strpos($url, home_url()) === false && (strpos($url, 'http') === 0 || strpos($url, '//') === 0) && strpos($link, 'target="_blank"') !== false) {
                if (strpos($link, 'rel=') === false) {
                    $link = str_replace('>', ' rel="noopener noreferrer">', $link);
                } else {
                    // Add to existing rel attribute if not already present
                    if (strpos($link, 'noopener') === false) {
                        $link = preg_replace('/rel=["\\]([^"\\]*)["\\]/', 'rel="$1 noopener noreferrer"', $link);
                    }
                }
            }
            return $link;
        },
        $content
    );
    return $content;
}
add_filter('the_content', 'add_rel_attributes_to_external_links');

// For menu links (if not automatically handled by WordPress core)
function add_rel_to_menu_links($atts, $item, $args) {
    if (isset($atts['href']) && strpos($atts['href'], home_url()) === false && strpos($atts['href'], 'http') === 0 && isset($atts['target']) && $atts['target'] === '_blank') {
        $atts['rel'] = 'noopener noreferrer';
    }
    return $atts;
}
add_filter('nav_menu_link_attributes', 'add_rel_to_menu_links', 10, 3);

3. For Dynamically Created Links (JavaScript):

If you’re creating links dynamically with JavaScript, ensure you explicitly set the rel attribute:

document.addEventListener('DOMContentLoaded', function() {
    const links = document.querySelectorAll('a[href^="http"]:not([href*="' + window.location.hostname + '"])');

    links.forEach(link => {
        if (link.target === '_blank') {
            const currentRel = link.getAttribute('rel') || '';
            // Ensure noopener noreferrer are present
            let newRel = currentRel;
            if (!newRel.includes('noopener')) {
                newRel += ' noopener';
            }
            if (!newRel.includes('noreferrer')) {
                newRel += ' noreferrer';
            }
            link.setAttribute('rel', newRel.trim());
        }
    });
});

The Enduring Benefits

By understanding modern browser behavior and applying best practices, you continue to reap significant benefits:

In conclusion, while modern browsers have taken on much of the heavy lifting for external link security, a proactive and informed approach to rel="noopener noreferrer" remains a hallmark of a well-maintained and secure website. Stay vigilant, stay updated, and keep your site performing at its best!

Kinsta Hosting Banner Horizontal

Leave a Reply

Your email address will not be published. Required fields are marked *