@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.
32 lines (31 loc) • 1.44 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.checkContextForJsInjection = checkContextForJsInjection;
const attackPath_1 = require("../../helpers/attackPath");
const extractStringsFromUserInputCached_1 = require("../../helpers/extractStringsFromUserInputCached");
const getSourceForUserString_1 = require("../../helpers/getSourceForUserString");
const detectJsInjection_1 = require("./detectJsInjection");
/**
* This function goes over all the different input types in the context and checks
* if it's a possible JS Injection, if so the function returns an InterceptorResult
*/
function checkContextForJsInjection({ js, operation, context, }) {
for (const str of (0, extractStringsFromUserInputCached_1.extractStringsFromUserInputCached)(context)) {
if ((0, detectJsInjection_1.detectJsInjection)(js, str)) {
const source = (0, getSourceForUserString_1.getSourceForUserString)(context, str);
if (source) {
return {
operation: operation,
kind: "code_injection",
source: source,
pathsToPayload: (0, attackPath_1.getPathsToPayload)(str, context[source]),
metadata: {
language: "js",
code: js,
},
payload: str,
};
}
}
}
}