@aikidosec/firewall
Version:
Zen by Aikido is an embedded Application Firewall that autonomously protects Node.js apps against common and critical attacks, provides rate limiting, detects malicious traffic (including bots), and more.
30 lines (29 loc) • 1.11 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.wrapMiddleware = wrapMiddleware;
const contextFromRequest_1 = require("./contextFromRequest");
const Context_1 = require("../../agent/Context");
function wrapMiddleware(origMiddleware) {
return function wrapped() {
const applyOriginal = () => {
return origMiddleware.apply(
// @ts-expect-error We don't know the type of this
this,
// @ts-expect-error We don't know the type of arguments
// eslint-disable-next-line prefer-rest-params
arguments);
};
// eslint-disable-next-line prefer-rest-params
const args = Array.from(arguments);
if (typeof args[0] !== "object" ||
Array.isArray(args[0]) ||
args[0] === null) {
return applyOriginal();
}
const ctx = args[0];
const context = (0, contextFromRequest_1.contextFromRequest)(ctx);
return (0, Context_1.runWithContext)(context, () => {
return applyOriginal();
});
};
}
;