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.
@tsmx/secure-config
Advanced tools
Secure multi-environment JSON configurations with encrypted secrets.
Secure multi-environment configurations with encrypted secrets.
Encrypt sensitive data in your JSON configuration file. For more details please see generating encrypted values and naming conventions.
{
"database": {
"host": "127.0.0.1",
"user": "ENCRYPTED|50ceed2f97223100fbdf842ecbd4541f|df9ed9002bfc956eb14b1d2f8d960a11",
"pass": "ENCRYPTED|8fbf6ded36bcb15bd4734b3dc78f2890|7463b2ea8ed2c8d71272ac2e41761a35"
}
}
Use your configuration in the code.
const conf = require('@tsmx/secure-config');
function MyFunc() {
let dbHost = conf.database.host; // = '127.0.0.1'
let dbUser = conf.database.user; // = 'MySecretDbUser'
let dbPass = conf.database.pass; // = 'MySecretDbPass'
//...
}
A fully working example project is also available on GitHub.
To get all information please also check out the full documentation.
The key for decrypting the encrypted values is derived from an environment variable named CONFIG_ENCRYPTION_KEY
. You can set this variable
whatever way is most suitable, e.g.
export CONFIG_ENCRYPTION_KEY=0123456789qwertzuiopasdfghjklyxc
...
"env": {
"CONFIG_ENCRYPTION_KEY": "0123456789qwertzuiopasdfghjklyxc"
},
...
env_variables:
CONFIG_ENCRYPTION_KEY: "0123456789qwertzuiopasdfghjklyxc"
jest.config.js
, e.g.
process.env['CONFIG_ENCRYPTION_KEY'] = '0123456789qwertzuiopasdfghjklyxc';
module.exports = {
testEnvironment: 'node'
};
More examples are available in the full documentation.
The key length must be 32 bytes! The value set in CONFIG_ENCRYPTION_KEY
has to be:
Otherwise an error will be thrown.
Examples of valid key strings:
MySecretConfigurationKey-123$%&/
9af7d400be4705147dc724db25bfd2513aa11d6013d7bf7bdb2bfe050593bd0f
Different keys for each configuration environment are strongly recommended.
For better convenience I provided a very basic secure-config-tool to easily generate the encrypted entries.
You can simply use crypto
functions from NodeJS with the following snippet to create the encrypted entries:
const crypto = require('crypto');
const algorithm = 'aes-256-cbc';
function encrypt(value) {
let iv = crypto.randomBytes(16);
let key = Buffer.from('YOUR_KEY_HERE');
let cipher = crypto.createCipheriv(algorithm, key, iv);
let encrypted = cipher.update(value);
encrypted = Buffer.concat([encrypted, cipher.final()]);
return 'ENCRYPTED|' + iv.toString('hex') + '|' + encrypted.toString('hex');
}
The generated encrypted entry must always have the form: ENCRYPTED | IV | DATA
.
Part | Description |
---|---|
ENCRYPTED | The prefix ENCRYPTED used to identify configuration values that must be decrypted. |
IV | The ciphers initialization vector (IV) that was used for encryption. Hexadecimal value. |
DATA | The AES-256-CBC encrypted value. Hexadecimal value. |
You can have multiple configuration files for different environments or stages. They are distinguished by the environment variable NODE_ENV
. The basic configuration file name is config.json
if this variable is not present. If it is present, a configuration file with the name config-[NODE_ENV].json
is used. An exception will be thrown if no configuration file is found.
All configuration files must be located in a conf/
directory of the current running app, meaning a direct subdirectory of the current working directory (CWD/conf/
).
NODE_ENV
: not setconf/config.json
NODE_ENV
: production
conf/config-production.json
NODE_ENV
: test
conf/config-test.json
path-to-your-app/
├── conf/
│ ├── config.json
│ ├── config-production.json
│ └── config-test.json
├── app.js
└── package.json
npm install
npm test
FAQs
Easy and secure configuration management. JSON based encrypted secrets, optional HMAC validation.
We found that @tsmx/secure-config demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers 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.