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.
call-reduce
Advanced tools
Iterate through a sequence of methods, firing each method explicitly in turn with a next
callback.
Useful for asynchronous pipes or middleware.
npm install call-reduce --save
or yarn add call-reduce
const callReduce = require('call-reduce')
const stack = callReduce(
(x, next) => next(x + ' world!'),
(y, next) => {
console.log(y) // hello world!
},
z => {
throw new Error("We shouldn't get here since `next` is never called at step 2")
}
)
stack('hello')
Imagine your Node application has some request middleware that looks up a user from the DB and determines if they have permissions to access that route, or whether they should be rejected.
While a bit more advanced, you could also pipe the req
and res
through a whole series of asynchronous operations easily using this pattern, composing each as a stand-alone method
const { createServer } = require('http')
const callReduce = require('call-reduce')
const auth = callReduce(
(req, res, next) => {
User.findOne({_id: req.params.user}, (err, user) => {
if (user.canAccess(req)) {
next(req, res)
} else {
res.statusCode = 403
res.end('Forbidden')
}
})
},
(req, res) => {
res.end('Yay! You made it')
}
)
createServer(auth).listen(8000)
FAQs
Reduce an array of functions, calling the next explicitly
We found that call-reduce 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.