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

protofree

v1.0.0

Published

Disable the __proto__ property for better security

Downloads

1,032

Readme

protofree

Node.js CI

protofree is a module designed to increase the security of node.js through eliminating usage of the __proto__ object property.

Background

In node.js, all regular objects contain a obj.__proto__ property, which can be used to query the prototype of an object, as well as assigning it another prototype. This "magic" property has been the cause of numerous security issues through the years, both by accidentially modifying the global Object.prototype, and by assigning a new prototype to an existing object, and changing its behavior.

Given these issues, and that it is an API where any usage can be replaced with other safer APIs, there is no good reason to continue allowing this surprising behavior.

Install

npm install protofree

Usage

protofree is intended to be injected into node through the --require option.

Three variants are available to use with --require:

  • protofree/apply – Completely removes the special obj.__proto__ handling from node.
  • protofree/partial – Change obj.__proto__ to always return undefined.
  • protofree/deprecate – Preserves obj.__proto__ handling, but logs each use with console.trace().

In general, the protofree/apply variant should be used. However, it can cause issues when using modules that continue to rely on the __proto__ property for modifying the prototype. In that case, the protofree/partial variant can be used. While it doesn't protect against accidental re-assignment, it does protect against the more serious global Object.prototype poisoning.

The protofree/deprecate is not for normal usage, but rather for development and testing. It can help expose existing usage of obj.__proto__ in your code or dependencies.

Note that these can also be injected into node through the NODE_OPTIONS env variable, eg. NODE_OPTIONS="-r protofree/apply". If desired, the relevant variant can also be required normally, or the API can be used to activate it manually through the protofree module.

Example

node -r protofree/apply index.js

Eslint no-proto rule

To avoid using __proto__ in your own code, the eslint no-proto rule can be enabled.

API

An API is exposed through requiring the main module:

const ProtoFree = require('protofree);

ProtoFree.apply([options])

Enable an override of the __proto__ property. Without any options, the property is deleted, and will no longer have any special meaning.

  • options - optional settings:
    • partial - Only changes the getter to always return undefined.
    • deprecate - Preserves __proto__ handling, but logs each use with options.tracer or console.trace.
    • tracer - Method that is called whenever the __proto__ property is accessed. Only works with the deprecate option.

ProtoFree.restore()

Restores Object.prototype.__proto__ to the default behavior.