Added regex string (like in SVR.JS config) support

This commit is contained in:
svrjs 2023-07-30 01:19:50 +02:00
parent 6305442f26
commit e94e5bba61
2 changed files with 20 additions and 1 deletions

View file

@ -8,6 +8,24 @@ var url = require("url");
var easywafconfig = {}; var easywafconfig = {};
var logm = {}; var logm = {};
if (fs.existsSync("easywaf-config.json")) easywafconfig = JSON.parse(fs.readFileSync("easywaf-config.json").toString()) if (fs.existsSync("easywaf-config.json")) easywafconfig = JSON.parse(fs.readFileSync("easywaf-config.json").toString())
function createRegex(regex) {
var regexObj = regex.split("/");
if (regexObj.length == 0) throw new Error("Invalid regex!");
var modifiers = regexObj.pop();
regexObj.shift();
var searchString = regexObj.join("/");
return new RegExp(searchString, modifiers);
}
if(easywafconfig.modules) {
var moduleOptions = Object.keys(easywafconfig.modules);
for(var i=0;i<moduleOptions.length;i++) {
try {
if(easywafconfig.modules[moduleOptions[i]].excludePaths) easywafconfig.modules[moduleOptions[i]].excludePaths = createRegex(easywafconfig.modules[moduleOptions[i]].excludePaths);
} catch(ex) { }
}
}
easywafconfig.preBlockHook = function(req, moduleInfo, ip) { easywafconfig.preBlockHook = function(req, moduleInfo, ip) {
try { try {
logm[ip]("Request blocked by EasyWAF. Module: " + moduleInfo.name); logm[ip]("Request blocked by EasyWAF. Module: " + moduleInfo.name);
@ -56,3 +74,4 @@ Mod.prototype.callback = function callback(req, res, serverconsole, responseEnd,
} }
} }
module.exports = Mod; module.exports = Mod;

View file

@ -1,4 +1,4 @@
{ {
"name": "Integration with EasyWAF", "name": "Integration with EasyWAF",
"version": "1.1.0" "version": "1.1.1"
} }