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

eslint-plugin-vuln-regex-detector

v1.0.4

Published

Detect vulnerable regexes using the vuln-regex-detector module.

Downloads

489

Readme

eslint-plugin-vuln-regex-detector

Detect unsafe regexes.

Recommended use

This plugin is not intended for use with your typical eslint runs. It uses the eslint framework to identify the files you care about and to have easy access to an AST from which to extract regexes.

It does work with as part of a regular eslint configuration. However, it will be slow the first few times eslint is triggered until the local cache warms up.

So, how should you use it? I suggest adding this line to the scripts section of your package.json:

"test:regex": "eslint --plugin vuln-regex-detector --rule '\"vuln-regex-detector/no-vuln-regex\": 2' FILES_YOU_CARE_ABOUT",

Then when you run npm run test:regex, you'll run your existing eslint rules plus identify vulnerable regexes in your code. This is appropriate for use in your CI.

You should re-use your existing eslint invocation (see the lint line in your package.json scripts). You might want to restrict the files you care about, since e.g. vulnerable regexes in test/ are probably not an issue.

Configuring

The vuln-regex-detector module lets users specify the server hostname and port, as well as the local cache.

Server config

Invoke eslint with ESLINT_PLUGIN_NO_VULN_REGEX_HOSTNAME=... ESLINT_PLUGIN_NO_VULN_REGEX_PORT=....

Cache config

Invoke eslint with ESLINT_PLUGIN_NO_VULN_REGEX_PERSISTENT_DIR=....

Performance

Cold cache

From an AWS micro instance, it takes about 30 seconds to scan a project with 100 regexes.

Steady-state

This plugin relies on vuln-regex-detector which queries a remote server about regexes. Once the server gives a firm response (it might say "unknown" for a few minutes), it gets cached locally in the FS. So after a few uses on the same machine, the plugin's performance will improve. The improvement will be significant if you have many regexes.

Installation

You'll first need to install ESLint:

$ npm i eslint --save-dev

Next, install eslint-plugin-vuln-regex-detector:

$ npm install eslint-plugin-vuln-regex-detector --save-dev

Note: If you installed ESLint globally (using the -g flag) then you must also install eslint-plugin-vuln-regex-detector globally.

Usage

If you want to use it in every eslint run, update your .eslintrc configuration file as follows:

  1. Update plugins.
{
    "plugins": [
        "vuln-regex-detector"
    ]
}
  1. Update rules.
{
    "rules": {
        "vuln-regex-detector/no-vuln-regex": 2
    }
}

Supported Rules

  • no-vuln-regex: Identify vulnerable regexes in your code.