npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

react-secure-link

v3.2.0

Published

A TypeScript compatible, zero dependency React component to avoid security exploits when opening a link in a new tab.

Downloads

3,275

Readme

react-secure-link 🔗

Test Coverage Status npm GitHub npm bundle size npm

A TypeScript compatible React component to avoid security exploits when opening a link in a new tab. react-secure-link is lightweight and has zero dependencies!

The Exploit 💥

It's possible when opening a link to a webpage in a new tab that the webpage in the new tab can hijack the webpage in the original tab via the window.opener property. This is an easy, low-level exploit. Here is how it can occur:

A hacker knows they can leave links in comments on your webpage and that they will open in a new tab. When a user to your website clicks that link, it will show them a seemingly harmless webpage. This newly opened tab has access to the window.opener property which the hacker can exploit. This webpage will use the window.opener property to run a little JavaScript like: window.opener.location = "https://www.some-malicious-website.com/login.html". This changes what webpage is opened in the original tab where the user clicked the link. This is problematic if the hacker redirects the original tab to a webpage that looks like the original. The hacker could show a message like, "You have been automatically logged out, log back in to continue." Since the webpage looks the same and the user knows they were just on the same webpage in that same tab, they'll trust the login form, but now their account has been compromised and they don't know it. The hacker could then redirect back to the original webpage after the login form is submitted to further cover their tracks.

What is the window.opener Property?

From MDN:

The Window interface's opener property returns a reference to the window that opened the window, either with open(), or by navigating a link with a target attribute.

How Does react-secure-link Prevent this Exploit?

Using react-secure-link for outbound links prevents the new tab from having access to the window.opener property altogether.

Usage

  1. Add react-secure-link to your project via npm install react-secure-link
  2. Import the package: import { SecureLink } from "react-secure-link";
  3. Use the following for links you want to open in a new tab: <SecureLink href="https://www.npmjs.com/package/react-secure-link">react-secure-link on NPM</SecureLink>

CodeSandbox Examples

There are several examples of the various ways to use this package on CodeSandbox.

react-secure-link CodeSandbox Examples

API

SecureLink can be used to make text, images, or other children components clickable. In addition, standard a element attributes can be pass in as props (i.e. href, className, id, role, style).

Basic Usage Example

<SecureLink href="https://www.npmjs.com/package/react-secure-link" />

Advance Usage Example

<SecureLink
    href="https://www.npmjs.com/package/react-secure-link"
    className="no-link-decoration"
    style={{ color: "red" }}
    key={123}
    onClick={() => console.log("Clicked")}
>
    react-secure-link on NPM
</SecureLink>