New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

protect-env

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

protect-env

A naive way to protect your process.env

  • 1.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
7
increased by250%
Maintainers
1
Weekly downloads
 
Created
Source

🛡 protect-env


A naive implementation of protecting your process.env.

Avoid malicious packages and hackerz. Restrict process.env access to authorized libraries only.

🚀 Installation

npm i protect-env

🐜 Usage

Require this project as the very first line in your app.

Basic

const rules = {
	ENV_VAR_NAME: ['allowed-file.pattern'],
	ENV_VAR_NAME_2: ['package-name'],
	ENV_VAR_NAME_3: ['*'],
	env: ['global-patterns'],
}
require('protect-env')(rules)

/* ... your code ... */

Errors

Errors will be thrown if an unapproved library attempts to access your process.env or keys on it. Those libraries will not gain access to your protected env vars.

Minimal "Glob" Matching

protect-env uses minimatch for pattern matching. Pass arrays of glob/minimatching patterns for each key.

Restoring process.env

const restore = require('protect-env')({
	WHATEVER: ['my-file'],
})
process.env.WHATEVER // protected
restore()
process.env.WHATEVER // unprotected

⚠️ Caveats

This is a very naive implementation - only protecting your process.env using getters. It does not protect against other ways of accessing your environment variables (like calling external code, file system requires, or other more elegant methods).

📐 Testing

npm run test

🖌 Linting

npm run prettier

⚖ License

MIT

Keywords

FAQs

Package last updated on 08 Aug 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc