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.

27 lines (26 loc) 1.18 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.SQLInjectionDetectionResult = void 0; exports.detectSQLInjection = detectSQLInjection; const shouldReturnEarly_1 = require("./shouldReturnEarly"); // eslint-disable-next-line camelcase const zen_internals_1 = require("../../internals/zen_internals"); exports.SQLInjectionDetectionResult = { SAFE: 0, INJECTION_DETECTED: 1, INTERNAL_ERROR: 2, FAILED_TO_TOKENIZE: 3, }; function detectSQLInjection(query, userInput, dialect) { if ((0, shouldReturnEarly_1.shouldReturnEarly)(query, userInput)) { return exports.SQLInjectionDetectionResult.SAFE; } const code = (0, zen_internals_1.wasm_detect_sql_injection)(query.toLowerCase(), userInput.toLowerCase(), dialect.getWASMDialectInt()); if (code === exports.SQLInjectionDetectionResult.SAFE || code === exports.SQLInjectionDetectionResult.INJECTION_DETECTED || code === exports.SQLInjectionDetectionResult.INTERNAL_ERROR || code === exports.SQLInjectionDetectionResult.FAILED_TO_TOKENIZE) { return code; } throw new Error("Unexpected return code from WASM: " + code); }