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

node-shield

v0.1.11

Published

Protects against common Node.js vulnerabilities in MEAN stack (MongoDB, Node.js)

Downloads

57

Readme

node-shield

npm version Build Status

Protects against common Node.js vulnerabilities in MEAN stack (MongoDB, Node.js).

Provides an extremelly fast and low overhead API and Express 4.x middleware.

  • Executes in ~200ns (nanoseconds) for a payload with 10 keys and 500 bytes.
  • 100% code coverage.
  • Zero dependencies.
  • Supports Node 6+

Install

npm install node-shield

Description

This module aims in protecting Node.js applications againt OWASP Injection (A1) attacks.

One of the most common attacks of MEAN stack is the MongoDB NoSQL injection using arbitraty input in request parameters.

A second and more recent attack comes with JavaScript prototype pollution and it was seen in multiple libraries in last years (Lodash, Hapi.js), but it is also present if you use Object.assign API.

WARNING This is not a replacement for good coding practices like:

  • Use parameterized queries to prevent injection flaws.
  • Always validate input parameters types (JSON Schema recommended)

MongoDB NoSQL protection

Block object keys which start with $ operator for MongoDB. e.g: username: { $gt: ''}.

References:

  • https://www.owasp.org/index.php/Testing_for_NoSQL_injection
  • https://blog.websecurify.com/2014/08/hacking-nodejs-and-mongodb.html
  • https://blog.websecurify.com/2014/08/attacks-nodejs-and-mongodb-part-to.html

Prototype Pollution protection

Block object keys with names __proto__ or constructor which are also an object.

References:

  • https://github.com/HoLyVieR/prototype-pollution-nsec18/blob/master/paper/JavaScript_prototype_pollution_attack_in_NodeJS.pdf

API usage

Callback style

const { shield } = require('node-shield');

shield.evaluate({ user: { $gt: '' } }, { mongo: true, proto: true },
  (err) => {
    if (err) {
      throw err;
    }
  });

Promise style

const { shield } = require('node-shield');

shield.evaluateAsync({ user: { $gt: '' } }, { mongo: true, proto: true })
  .catch((err) => {
    throw err;
  });

Express 4.x middleware usage

By default, both mongo and proto protections are evaluated and the error handler return a 403 error. You can do anything you would normally do in a express middleware. Example, but not limited to:

  • Log the injection attempt and continue to process the request
  • Log the injection attempt and response with an error
const express = require('express');
const { expressShield } = require('node-shield');

const app = express();
app.use(express.urlencoded({ extended: true }));
app.use(express.json());
app.use(expressShield({
  errorHandler: (shieldError, req, res, next) => {
    console.error(shieldError);
    res.sendStatus(400);
  },
}));

app.listen(3000);

License

Apache2.0

Author

Leonardo Zanivan [email protected] www.panga.dev