Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
@beequeue/dotenv-webpack
Advanced tools
A simple webpack plugin to support dotenv.
A secure webpack plugin that supports dotenv and other environment variables and only exposes what you choose and use.
Include the package locally in your repository.
npm install dotenv-webpack --save-dev
dotenv-webpack
wraps dotenv
and Webpack.DefinePlugin
. As such, it does a text replace in the resulting bundle for any instances of process.env
.
Your .env
files can include sensitive information. Because of this,dotenv-webpack
will only expose environment variables that are explicitly referenced in your code to your final bundle.
The plugin can be installed with little-to-no configuration needed. Once installed, you can access the variables within your code using process.env
as you would with dotenv
.
The example bellow shows a standard use-case.
// .env
DB_HOST=127.0.0.1
DB_PASS=foobar
S3_API=mysecretkey
// webpack.config.js
const Dotenv = require('dotenv-webpack');
module.exports = {
...
plugins: [
new Dotenv()
]
...
};
// file1.js
console.log(process.env.DB_HOST);
// '127.0.0.1'
// bundle.js
console.log('127.0.0.1');
Note: the .env
values for DB_PASS
and S3_API
are NOT present in our bundle, as they were never referenced (as process.env.[VAR_NAME]
) in the code.
By allowing you to define exactly where you are loading environment variables from and bundling only variables in your project that are explicitly referenced in your code, you can be sure that only what you need is included and you do not accidentally leak anything sensitive.
Add .env
to your .gitignore
file
Due to the fact that we use webpack.DefinePlugin
under the hood, we cannot support destructing as that breaks how this plugin is meant to be used. Because of this, please reference your variables without destructing. For more information about this, please review the issue here.
Use the following properties to configure your instance.
'./.env'
) - The path to your environment variables.false
) - If true, load '.env.example' to verify the '.env' variables are all set. Can also be a string to a different file.false
) - Whether to allow empty strings in safe mode. If false, will throw an error if any env variables are empty (but only if safe mode is enabled).false
) - Set to true if you would rather load all system variables as well (useful for CI purposes).false
) - If true, all warnings will be suppressed.false
) - Allows your variables to be "expanded" for reusability within your .env
file.false
) - Adds support for dotenv-defaults
. If set to true
, uses ./.env.defaults
. If a string, uses that location for a defaults file. Read more at npm.The following example shows how to set any/all arguments.
module.exports = {
...
plugins: [
new Dotenv({
path: './some.other.env', // load this now instead of the ones in '.env'
safe: true, // load '.env.example' to verify the '.env' variables are all set. Can also be a string to a different file.
allowEmptyValues: true, // allow empty variables (e.g. `FOO=`) (treat it as empty string, rather than missing)
systemvars: true, // load all the predefined 'process.env' variables which will trump anything local per dotenv specs.
silent: true, // hide any errors
defaults: false // load '.env.defaults' as the default values if empty.
})
]
...
};
MIT
FAQs
A simple webpack plugin to support dotenv.
The npm package @beequeue/dotenv-webpack receives a total of 0 weekly downloads. As such, @beequeue/dotenv-webpack popularity was classified as not popular.
We found that @beequeue/dotenv-webpack demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.