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.
@vizydrop/correlation-id
Advanced tools
Create correlation id instance
const {createCorrelationId} = require(`@vizydrop/correlation-id`);
const correlationId = createCorrelationId();
Integrate with @vizydrop/logger
const {createLogger} = require(`@vizydrop/logger`);
const logger = createLogger({
correlationId: {
enabled: true,
getCorrelationId: () => correlationId.correlator.getId(),
emptyValue: `nocorrelation`,
},
});
Register middleware. Support koa
and express
// koa
app.use(correlationId.koaMiddleware);
// express
app.use(correlationId.expressMiddleware);
Enhance request so each request will contain correlation id http header.
const request = require(`request`);
const correlatedRequest = correlationId.enhanceRequest(request);
correlatedRequest.get(`http://anotherservice:10020/data`);
Enhance http proxy so each proxied request will contain correlation id http header.
const httpProxy = require(`http-proxy`);
const proxy = httpProxy.createProxyServer({target: `http://anotherservice:10020/`});
correlationId.enhanceHttpProxy(proxy);
Run jobs. Jobs usually do not go through express/koa
middleware so correlation id should be generated manually.
function jobTask() {}
function runJob() {
correlationId.correlator.withId(correlator.generateDefaultId(), () => {
jobTask();
});
}
Custom settings can be passed as an object to createCorrelationId
function.
generateDefaultId
- function that should return new correlation id. By default uuid
is used.namespaceName
- namespace for cls hook. Default value is correlation-id-namespace
httpHeaderParamName
- name of http header that contains correlation id value. Default value is x-correlationid
expressMiddleware
- express middleware that runs next middlewares in scope of correlation id async hookkoaMiddleware
- koa middleware that runs next middlewares in scope of correlation id async hookenhanceHttpRequest
- takes request and return new request instance that adds correlation id header by defaultenhanceHttpProxy
- register additional listener that adds correlation id header by defaultcorrelator.getId()
- returns current correlation idcorrelator.withId(id, fn)
- run function and all subsequent function with specified correlation idcorrelator.bindEmitter()
- see https://github.com/jeff-lewis/cls-hooked#namespacebindemitteremittercorrelator.bind()
- see https://github.com/jeff-lewis/cls-hooked#namespacebindemitteremittercorrelator.generateId()
- generates new correlation idbluebird.promisifyAll
. Alternative solution is to explicitly promisify using native promiseconst redis = require(`redis`);
const util = require(`util`);
const client = redis.createClient();
client.setAsync = util.promisify(client.set).bind(client);
client.getAsync = util.promisify(client.get).bind(client);
mongoose
callbacks. Alternative solution is to use promisified functions.const mongoose = require(`mongooose`);
mongoose.Promise = global.Promise;
EntityModel.find({name: `name`}).then((value) => {
// do something
});
FAQs
Vizydrop correlation id helper based on async hooks
The npm package @vizydrop/correlation-id receives a total of 125 weekly downloads. As such, @vizydrop/correlation-id popularity was classified as not popular.
We found that @vizydrop/correlation-id demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 6 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.