UNPKG

@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.

36 lines (35 loc) 1.19 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.wrapBuiltinExports = wrapBuiltinExports; const AgentSingleton_1 = require("../../AgentSingleton"); const instructions_1 = require("./instructions"); function wrapBuiltinExports(id, exports) { var _a; const agent = (0, AgentSingleton_1.getInstance)(); if (!agent) { return exports; } const interceptors = (0, instructions_1.getBuiltinInterceptors)(id); if (interceptors.length === 0) { return exports; } const pkgInfo = { name: id, type: "builtin", }; for (const interceptor of interceptors) { try { const returnVal = interceptor(exports, pkgInfo); // If the interceptor returns a value, we want to use this value as the new exports if (returnVal !== undefined) { exports = returnVal; } } catch (error) { if (error instanceof Error) { (_a = (0, AgentSingleton_1.getInstance)()) === null || _a === void 0 ? void 0 : _a.onFailedToWrapModule(pkgInfo.name, error); } } } return exports; }