Try it Yourself: Adding rel="noopener noreferrer"

Introduction

Open the links below in new tabs and observe the behavior:

Why use rel="noopener noreferrer"?

Using rel="noopener noreferrer" prevents the new page from being able to access the window.opener property and ensures it runs in a separate process. This is particularly important for security and performance reasons.

Understanding the Exploit

When a link is opened with target="_blank" without using rel="noopener noreferrer", the new page has access to the window.opener property, which refers to the original page. This can be exploited by malicious pages to manipulate the content or URL of the original page.

Steps to Exploit example-without-noreferrer.html

  1. Open the Example without noreferrer link. A new tab will open malicious.html.
  2. Observe that malicious.html attempts to manipulate the original page by redirecting it to hacked.html or changing its content to display a fake login form.
  3. In a real-world scenario, this could be used to steal sensitive information by tricking users into entering their credentials on a phishing page that looks like a legitimate login form.

Mitigation with example-with-noreferrer.html

  1. Open the Example with noreferrer link. A new tab will open malicious.html.
  2. Observe that malicious.html fails to manipulate the original page because the window.opener property is null.
  3. By using rel="noopener noreferrer", the original page is protected from any manipulation attempts by the new page, thus preventing potential phishing attacks.

Explanation of malicious.html

The malicious.html page has been styled to look like a legitimate Skunkworks Mail login page. It includes a form that checks for specific credentials (username: skunkworks, password: password123). If the correct credentials are entered, the user is redirected to hacked.html. Otherwise, an error message is displayed. The page still attempts to manipulate the opener's content or URL to demonstrate the security risk.

Credentials for Redirection

Username skunkworks
Password password123

This setup should provide a clear and realistic demonstration of the security implications and how the rel="noopener noreferrer" attribute helps mitigate such risks.

Try It Yourself: