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

secure-env-ts

Package Overview
Dependencies
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

secure-env-ts - npm Package Compare versions

Comparing version 1.2.4 to 1.2.5

.env.staging.enc

85

dist/cli.js

@@ -35,2 +35,8 @@ #! /usr/bin/env node

const log_1 = __importStar(require("./utils/log"));
const fs_1 = __importDefault(require("fs"));
const child_process_1 = require("child_process");
const diff = __importStar(require("diff"));
const colors_1 = __importDefault(require("colors"));
const inquirer_1 = __importDefault(require("inquirer"));
const command_exists_1 = require("command-exists");
const argv = (0, minimist_1.default)(process.argv.slice(2));

@@ -42,5 +48,80 @@ const outputFile = argv.out || argv.o;

// should decrypt or encrypt ?
if (argv.decrypt || argv.d)
if (argv.decrypt || argv.d) {
(0, log_1.default)((0, cryptography_1.decrypt)({ secret, inputFile, outputFile, decryptionAlgo: encryptionAlgo }), log_1.logTypes.INFO);
else
}
else if (argv.edit || argv.e) {
const decrypted = (0, cryptography_1.decrypt)({ secret, inputFile, outputFile, decryptionAlgo: encryptionAlgo });
if (!decrypted) {
process.exit(1);
}
const file = '.env.temp';
const path = `./${file}`;
fs_1.default.writeFileSync(path, decrypted);
console.log(colors_1.default.bold.white('Opening your text editor...'));
const code = (0, command_exists_1.sync)('code') ? 'code' : null;
const nano = (0, command_exists_1.sync)('nano') ? 'nano' : null;
const vim = (0, command_exists_1.sync)('vim') ? 'vim' : null;
const usersEditor = process.env.EDITOR || nano || code || vim || 'vi';
const childProcess = (0, child_process_1.spawn)(usersEditor, [file], {
stdio: 'inherit',
detached: true
});
childProcess.on('data', () => process.exit());
const abort = () => {
fs_1.default.unlinkSync(path);
console.log('\n');
console.log(colors_1.default.bold.white(`Aborted no changes made.`));
console.log('\n');
process.exit(0);
};
let saved = false;
fs_1.default.watch(path, (evenType) => {
console.log(evenType);
if (evenType === "change") {
if (saved) {
return;
}
saved = true;
const newEnvVars = fs_1.default.readFileSync(path);
const envVarsDiff = diff.diffLines(decrypted, newEnvVars.toString());
const removed = (envVarsDiff.filter(line => line.removed))?.map((line) => line.value);
const added = (envVarsDiff.filter(line => line.added))?.map((line) => line.value);
if (!removed.length && !added.length) {
abort();
}
console.log(colors_1.default.bold.white('Your changes:'));
console.log('\n');
console.log(colors_1.default.bold.underline.red('Removed:'));
console.log('\n');
console.log(colors_1.default.red(removed.join('\n')));
console.log('\n');
console.log(colors_1.default.bold.underline.green('Added:'));
console.log('\n');
console.log(colors_1.default.green(added.join('\n')));
console.log('\n');
inquirer_1.default.prompt([{
name: 'continue',
type: 'string',
message: 'Encrypt? Yes/ No',
}]).then((answers) => {
if (['yes', 'y'].includes(answers.continue.toLowerCase())) {
(0, cryptography_1.encrypt)({ secret, inputFile: file, outputFile: inputFile, encryptionAlgo, isEdit: true })?.then(() => {
fs_1.default.unlinkSync(path);
console.log('\n');
console.log(colors_1.default.bold.white(`All done!`));
console.log(colors_1.default.bold.white(`The Environment file "${inputFile}" has been edited.`));
console.log(colors_1.default.bold.white(`Don't forget to push and commit "${inputFile}"".`));
console.log('\n');
process.exit(0);
});
}
else {
abort();
}
});
}
});
}
else {
(0, cryptography_1.encrypt)({ secret, inputFile, outputFile, encryptionAlgo });
}

3

dist/cryptography.d.ts

@@ -57,4 +57,5 @@ /// <reference types="node" />

ivLength?: number;
isEdit?: boolean;
}
export declare const decrypt: (options: IDecryptOptions) => (Buffer & string) | undefined;
export declare const encrypt: (options: IEncryptOptions) => void;
export declare const encrypt: (options: IEncryptOptions) => Promise<void> | undefined;

@@ -64,2 +64,3 @@ "use strict";

const ivLength = options.ivLength || 16;
const isEdit = options.isEdit;
// presumably createCipheriv() should work for all the algo in ./openssl_list-cipher-algorithms.csv with the right key/iv length

@@ -70,11 +71,16 @@ if (!fs_1.default.existsSync(inputFile))

throw new Error('No SecretKey provided.Use -s option to specify secret');
const key = crypto_1.default.createHash('sha256').update(String(secret)).digest(); // /// TODO: node v10.5.0+ should use crypto.scrypt(secret, salt, keylen[, options], callback)
const iv = crypto_1.default.randomBytes(ivLength);
const cipher = crypto_1.default.createCipheriv(encryptionAlgo, key, iv);
const output = fs_1.default.createWriteStream(outputFilePath);
output.write(iv);
fs_1.default.createReadStream(inputFile).pipe(cipher).pipe(output);
output.on('finish', () => {
(0, log_1.default)(`The Environment file "${inputFile}" has been encrypted to "${outputFilePath}".`, log_1.logTypes.INFO);
(0, log_1.default)(`Make sure to delete "${inputFile}" for production use.`, log_1.logTypes.WARN);
return new Promise(resolve => {
const key = crypto_1.default.createHash('sha256').update(String(secret)).digest(); // /// TODO: node v10.5.0+ should use crypto.scrypt(secret, salt, keylen[, options], callback)
const iv = crypto_1.default.randomBytes(ivLength);
const cipher = crypto_1.default.createCipheriv(encryptionAlgo, key, iv);
const output = fs_1.default.createWriteStream(outputFilePath);
output.write(iv);
fs_1.default.createReadStream(inputFile).pipe(cipher).pipe(output);
output.on('finish', () => {
if (!isEdit) {
(0, log_1.default)(`The Environment file "${inputFile}" has been encrypted to "${outputFilePath}".`, log_1.logTypes.INFO);
(0, log_1.default)(`Make sure to delete "${inputFile}" for production use.`, log_1.logTypes.WARN);
}
resolve();
});
});

@@ -81,0 +87,0 @@ }

{
"name": "secure-env-ts",
"version": "1.2.4",
"version": "1.2.5",
"description": "Use ENVs securely with encryption",

@@ -40,2 +40,5 @@ "license": "MIT",

"devDependencies": {
"@types/command-exists": "^1.2.0",
"@types/diff": "^5.0.1",
"@types/inquirer": "^8.1.3",
"@types/minimist": "^1.2.2",

@@ -47,4 +50,8 @@ "@types/node": "^16.10.2",

"dependencies": {
"colors": "^1.4.0",
"command-exists": "^1.2.9",
"diff": "^5.0.0",
"inquirer": "^8.2.0",
"minimist": "^1.2.0"
}
}
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