@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.
197 lines (196 loc) • 6.83 kB
JavaScript
;
/* @ts-self-types="./zen_internals.d.ts" */
/**
* @param {string} code
* @param {string} userinput
* @param {number} sourcetype
* @returns {boolean}
*/
function wasm_detect_js_injection(code, userinput, sourcetype) {
const ptr0 = passStringToWasm0(code, wasm.__wbindgen_export2, wasm.__wbindgen_export3);
const len0 = WASM_VECTOR_LEN;
const ptr1 = passStringToWasm0(userinput, wasm.__wbindgen_export2, wasm.__wbindgen_export3);
const len1 = WASM_VECTOR_LEN;
const ret = wasm.wasm_detect_js_injection(ptr0, len0, ptr1, len1, sourcetype);
return ret !== 0;
}
exports.wasm_detect_js_injection = wasm_detect_js_injection;
/**
* @param {string} query
* @param {string} userinput
* @param {number} dialect
* @returns {number}
*/
function wasm_detect_sql_injection(query, userinput, dialect) {
const ptr0 = passStringToWasm0(query, wasm.__wbindgen_export2, wasm.__wbindgen_export3);
const len0 = WASM_VECTOR_LEN;
const ptr1 = passStringToWasm0(userinput, wasm.__wbindgen_export2, wasm.__wbindgen_export3);
const len1 = WASM_VECTOR_LEN;
const ret = wasm.wasm_detect_sql_injection(ptr0, len0, ptr1, len1, dialect);
return ret;
}
exports.wasm_detect_sql_injection = wasm_detect_sql_injection;
/**
* @param {string} query
* @param {number} dialect
* @returns {any}
*/
function wasm_idor_analyze_sql(query, dialect) {
const ptr0 = passStringToWasm0(query, wasm.__wbindgen_export2, wasm.__wbindgen_export3);
const len0 = WASM_VECTOR_LEN;
const ret = wasm.wasm_idor_analyze_sql(ptr0, len0, dialect);
return takeObject(ret);
}
exports.wasm_idor_analyze_sql = wasm_idor_analyze_sql;
function __wbg_get_imports() {
const import0 = {
__proto__: null,
__wbg_Error_8c4e43fe74559d73: function (arg0, arg1) {
const ret = Error(getStringFromWasm0(arg0, arg1));
return addHeapObject(ret);
},
__wbg___wbindgen_throw_be289d5034ed271b: function (arg0, arg1) {
throw new Error(getStringFromWasm0(arg0, arg1));
},
__wbg_new_361308b2356cecd0: function () {
const ret = new Object();
return addHeapObject(ret);
},
__wbg_new_3eb36ae241fe6f44: function () {
const ret = new Array();
return addHeapObject(ret);
},
__wbg_set_3f1d0b984ed272ed: function (arg0, arg1, arg2) {
getObject(arg0)[takeObject(arg1)] = takeObject(arg2);
},
__wbg_set_6cb8631f80447a67: function () {
return handleError(function (arg0, arg1, arg2) {
const ret = Reflect.set(getObject(arg0), getObject(arg1), getObject(arg2));
return ret;
}, arguments);
},
__wbg_set_f43e577aea94465b: function (arg0, arg1, arg2) {
getObject(arg0)[arg1 >>> 0] = takeObject(arg2);
},
__wbindgen_cast_0000000000000001: function (arg0) {
// Cast intrinsic for `F64 -> Externref`.
const ret = arg0;
return addHeapObject(ret);
},
__wbindgen_cast_0000000000000002: function (arg0, arg1) {
// Cast intrinsic for `Ref(String) -> Externref`.
const ret = getStringFromWasm0(arg0, arg1);
return addHeapObject(ret);
},
__wbindgen_cast_0000000000000003: function (arg0) {
// Cast intrinsic for `U64 -> Externref`.
const ret = BigInt.asUintN(64, arg0);
return addHeapObject(ret);
},
__wbindgen_object_clone_ref: function (arg0) {
const ret = getObject(arg0);
return addHeapObject(ret);
},
__wbindgen_object_drop_ref: function (arg0) {
takeObject(arg0);
},
};
return {
__proto__: null,
"./zen_internals_bg.js": import0,
};
}
function addHeapObject(obj) {
if (heap_next === heap.length)
heap.push(heap.length + 1);
const idx = heap_next;
heap_next = heap[idx];
heap[idx] = obj;
return idx;
}
function dropObject(idx) {
if (idx < 132)
return;
heap[idx] = heap_next;
heap_next = idx;
}
function getStringFromWasm0(ptr, len) {
ptr = ptr >>> 0;
return decodeText(ptr, len);
}
let cachedUint8ArrayMemory0 = null;
function getUint8ArrayMemory0() {
if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
}
return cachedUint8ArrayMemory0;
}
function getObject(idx) { return heap[idx]; }
function handleError(f, args) {
try {
return f.apply(this, args);
}
catch (e) {
wasm.__wbindgen_export(addHeapObject(e));
}
}
let heap = new Array(128).fill(undefined);
heap.push(undefined, null, true, false);
let heap_next = heap.length;
function passStringToWasm0(arg, malloc, realloc) {
if (realloc === undefined) {
const buf = cachedTextEncoder.encode(arg);
const ptr = malloc(buf.length, 1) >>> 0;
getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);
WASM_VECTOR_LEN = buf.length;
return ptr;
}
let len = arg.length;
let ptr = malloc(len, 1) >>> 0;
const mem = getUint8ArrayMemory0();
let offset = 0;
for (; offset < len; offset++) {
const code = arg.charCodeAt(offset);
if (code > 0x7F)
break;
mem[ptr + offset] = code;
}
if (offset !== len) {
if (offset !== 0) {
arg = arg.slice(offset);
}
ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
const ret = cachedTextEncoder.encodeInto(arg, view);
offset += ret.written;
ptr = realloc(ptr, len, offset, 1) >>> 0;
}
WASM_VECTOR_LEN = offset;
return ptr;
}
function takeObject(idx) {
const ret = getObject(idx);
dropObject(idx);
return ret;
}
let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
cachedTextDecoder.decode();
function decodeText(ptr, len) {
return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
}
const cachedTextEncoder = new TextEncoder();
if (!('encodeInto' in cachedTextEncoder)) {
cachedTextEncoder.encodeInto = function (arg, view) {
const buf = cachedTextEncoder.encode(arg);
view.set(buf);
return {
read: arg.length,
written: buf.length
};
};
}
let WASM_VECTOR_LEN = 0;
const wasmPath = `${__dirname}/zen_internals_bg.wasm`;
const wasmBytes = require('fs').readFileSync(wasmPath);
const wasmModule = new WebAssembly.Module(wasmBytes);
const wasm = new WebAssembly.Instance(wasmModule, __wbg_get_imports()).exports;