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.
Orignally this module was created to keep track of keys in redis. But you can use it for any other application of course. Redis is an awesome key/value store, but you can easily lose track of all keys used in production, because there is no schema that every developer of your team has to follow.
npm install key-guard --save
const coreKey = require("key-guard")(options);
options
is an object with following attributes:
namespace
- string - A string that is prefixed to every generated key.minLength
- number - Min length of generated key (default: 1
).maxLength
- number - Max length of generated key (default: 100
).fragments
- object - A fragment is a string that is part of the key and separated by fragments.delimiter
.fragments.delimiter
- string - Delimiter between every key fragement (default: :
).fragments.regexp
- regexp - Regular expression that every key fragment is checked against (default: /^[a-zA-Z0-9]+$/
).fragments.count.min
- number - Min number of fragments (default: 2
).fragments.count.max
- number - Max number of fragments (default: 5
).fragments.len.min
- number - Min length of fragment string (default: 2
).fragments.len.max
- number - Max length of fragment string (default: 20
).{
namespace: 'myApp',
minLength: 1,
maxLength: 100,
fragments: {
delimiter: ':',
count: {
min: 2,
max: 5
},
len: {
min: 2,
max: 20
},
regexp: /^[a-zA-Z0-9]+$/
}
}
const keyGuard = require("key-guard");
let coreKey = keyGuard({
namespace: "myApp"
});
let key = coreKey().update("users").update("283").get();
console.log(key);
// => "myApp:users:283"
You can also overwrite the namespace or entire prefixes:
let key = coreKey("newNamespace:records").update("2384").get();
console.log(key);
// => "newNamespace:records:2384"
Create one file that creates the core key and the is included in every other page that needs generated keys:
coreKey.js
const keyGuard = require("key-guard");
module.exports = keyGuard({
namespace: "myApp"
});
index.js
const coreKey = require("./coreKey.js");
let key = coreKey().update("users").update("283").get();
console.log(key);
// => "myApp:users:283"
Usually scripts use keys for different fragments/sections multiple times. Declare a base key on top of each script or within coreKey.js
.
coreKey.js
const keyGuard = require("key-guard");
module.exports = keyGuard({
namespace: "myApp"
});
users.js
const coreKey = require("./coreKey.js");
const usersKey = coreKey().update("users");
console.log(usersKey.update("283").get());
console.log(usersKey.update("284").get());
console.log(usersKey.update("285").get());
// => "myApp:users:283"
// => "myApp:users:284"
// => "myApp:users:285"
If you do not want to have any literals within you scripts, load variables from config files or environment variables.
coreKey.js
const keyGuard = require("key-guard");
module.exports = keyGuard({
namespace: process.env.REDIS_NAMESPACE_KEY
});
> REDIS_NAMESPACE_KEY=myApp node index.js
FAQs
A module to create keys based on rules.
We found that key-guard 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.