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.
secure-env-ts
Advanced tools
Secure-env is a module that loads environment variables from a .env.enc
file. An encryption tool that would helps you prevent attacks from npm-malicious-packages.
Create a .env
file in the root directory of your project. Add
environment-specific variables on new lines in the form of NAME=VALUE
.
For example:
DB_HOST=localhost:27017
DB_USER=scott
DB_PASS=tiger
$ npm install -g secure-env
$ secure-env .env -s mySecretPassword
Alternatively if you want this installed locally run the command as follows:
$ ./node_modules/secure-env/dist/cli.js .env -s mySecretPassword
If you are running NPM > v5.2. You can use npx
:
$ npx secure-env .env -s mySecretPassword
A new encrypted file .env.enc
will be created in your project root directory.You can delete the .env
file after this,to prevent stealing.
As early as possible in your application, require and configure dotenv.
let secureEnv = require('secure-env');
global.env = secureEnv({ secret:'mySecretPassword' });
That's it.
global.env
now has the keys and values you defined in your .env
file.
var db = require('db')
db.connect({
host: global.env.DB_HOST,
username: global.env.DB_USER,
password: global.env.DB_PASS
})
$ secure-env --option <VALUE> <file-path-which-is-to-be-encrypted>
Option | What does it do | Defaults |
---|---|---|
--secret | Specify the secret Key which would be later used to decrypt the file. | mySecret |
--out | The encrypted file path that would be created. | env.enc |
--algo | The encryption algorithm that is to be used to encrypt the env file. | aes256 |
--decrypt | prints the decrypted text to stdout |
Default: .env
You can specify a custom path if your file containing environment variables is named or located differently.
require('secure-env')({ file:'/custom/path/to/your/env/vars' });
Default: aes256
You may specify the encryption algorithm for your file containing environment variables using this option.
require('secure-env')({ decryptionAlgo:'aes256' });
Required
Specify the secret Key which was used during encryption of raw file.Having a salt-hashed secret key is recommended.
require('secure-env')({ secret: 'mySecretPassword' });
Now a days, it's common to use typescript in a project.
With secure-env
you can type your env by using generics.
It's required for your interface to extend IObject
import SecureEnv, { IObject } from "secure-env"
interface IEnv extends IObject{
DB_HOST: string;
DB_USER: string;
DB_PASS: string;
}
const env = SecureEnv<IEnv>(your_options);
Refer https://github.com/motdotla/dotenv/blob/master/README.md#parse
The parsing engine currently supports the following rules:
BASIC=basic
becomes {BASIC: 'basic'}
#
are treated as commentsEMPTY=
becomes {EMPTY: ''}
)SINGLE_QUOTE='quoted'
becomes {SINGLE_QUOTE: "quoted"}
)MULTILINE="new\nline"
becomes{MULTILINE: 'new
line'}
JSON={"foo": "bar"}
becomes {JSON:"{\"foo\": \"bar\"}"
)trim
) (FOO=" some value "
becomes {FOO: 'some value'}
)
G.md)See LICENSE
Source-env uses these open source projects to work properly:
Source-env is inspired from and also uses code references from these open source projects:
FAQs
Use ENVs securely with encryption
The npm package secure-env-ts receives a total of 38 weekly downloads. As such, secure-env-ts popularity was classified as not popular.
We found that secure-env-ts 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.