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.
A circuit-breaker implementation for node.js with exponential backoff.
Disyuntor is the Spanish word used for circuit-breaker.
The purpose of this pattern is to detect errors and prevent cascading failures across multiple systems.
Disyuntor wraps an async (errback) function and returns a new function with the same signature.
During normal behavior of the system the circuit remains in its closed
state. This means that every call to the wrapper is forwarded to the protected function.
Once the protected function returns more than maxFailures
, the breaker trips and every call made during the cooldown
interval will immdiately return an error preventing resource depletion. This is known as the open
state.
Once the system has settled it will allow one call to go to the protected function. If the call succeds the breaker will be reset to its closed
state otherwise it will continue open
. This state is known as half open
A call is considered to have failed if the callback is not called before the timeout
or if it is called with the first (error) parameter.
npm i disyuntor
const disyuntor = require('disyuntor');
const dnsSafeLookup = disyuntor.wrapCallbackApi({
//This is used in error messages.
name: 'dns.lookup',
//Timeout for the protected function.
// timeout: '2s',
//The number of consecutive failures before switching to open mode
//and stop calling the underlying service.
// maxFailures: 5,
//The minimum time the circuit remains open before doing another attempt.
// cooldown: '15s',
//The maximum amount of time the circuit remains open before doing a new attempt.
// maxCooldown: '60s',
//optionally log errors
onTrip: (err, failures, cooldown) => {
console.log(`dns.lookup triped because it failed ${failures} times.
Last error was ${err.message}! There will be no more attempts for ${cooldown}ms.`);
},
onClose: (cooldown) => {
console.log(`dns.lookup circuit closed after ${cooldown}ms.`;
}
// //optional callback to prevent some errors to trigger the disyuntor logic
// //in this case ENOTFOUND is passed to the callback and will
// //not trigger the breaker eg:
// trigger: (err) => err.code !== 'ENOTFOUND'
}, dns.lookup);
//then use as you will normally use dns.lookup
dnsSafeLookup('google.com', (err, ip) => {
if (err) { return console.error(err.message); }
console.log(ip);
})
Timeouts can be expressed either by strings like '15s' or by milliseconds.
Defaults values are:
timeout
: 2smaxFailures
: 5cooldown
: 15smaxCooldown
: 60sconst lookup = Promise.promisify(require('dns').lookup);
const protectedLookup = disyuntor.wrapPromiseApi({
name: 'dns.lookup',
timeout: '2s',
maxFailures: 2
}, lookup);
protectedLookup('google.com')
.then((ip) => console.log(ip),
(err) => console.error(err));
You can create an instance of Disyuntor to have more control as follows:
const Disyuntor = require('disyuntor').Disyuntor;
const disyuntor = new Disyuntor({
name: 'dns.lookup',
timeout: '2s',
maxFailures: 2
});
await disyuntor.protect(() => dns.lookupAsync('google.com'));
Note: this api only supports promise-returning functions.
Copyright (c) 2015 Auth0, Inc. support@auth0.com (http://auth0.com)
FAQs
A circuit-breaker implementation with exponential backoff.
The npm package disyuntor receives a total of 502 weekly downloads. As such, disyuntor popularity was classified as not popular.
We found that disyuntor demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 3 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.