Some WAF errors now result in 500 errors instead of crashing the server.
This commit is contained in:
parent
90ccd1cd77
commit
44a257dbee
3 changed files with 34 additions and 23 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -1 +0,0 @@
|
||||||
commit.sh
|
|
54
index.js
54
index.js
|
@ -102,7 +102,7 @@ Mod.prototype.callback = function callback(req, res, serverconsole, responseEnd,
|
||||||
logm[req.socket.remoteAddress] = serverconsole;
|
logm[req.socket.remoteAddress] = serverconsole;
|
||||||
if(!logm[req.socket.remoteAddress].locwarnmessage) logm[req.socket.remoteAddress].locwarnmessage = logm[req.socket.remoteAddress].errmessage;
|
if(!logm[req.socket.remoteAddress].locwarnmessage) logm[req.socket.remoteAddress].locwarnmessage = logm[req.socket.remoteAddress].errmessage;
|
||||||
|
|
||||||
//REQ.BODY
|
//req.body
|
||||||
function readableHandler() {
|
function readableHandler() {
|
||||||
try {
|
try {
|
||||||
if(req._readableState.buffer.head !== null) {
|
if(req._readableState.buffer.head !== null) {
|
||||||
|
@ -113,34 +113,46 @@ Mod.prototype.callback = function callback(req, res, serverconsole, responseEnd,
|
||||||
} catch (ex) {
|
} catch (ex) {
|
||||||
}
|
}
|
||||||
|
|
||||||
//EASYWAF
|
//EasyWaf
|
||||||
easyWaf(req, res, function() {
|
try {
|
||||||
if (((href == "/easywaf-config.json" || (os.platform() == "win32" && href.toLowerCase() == "/easywaf-config.json")) || (href == "/easywaf-hooks.js" || (os.platform() == "win32" && href.toLowerCase() == "/easywaf-hooks.js"))) && __dirname == process.cwd()) {
|
easyWaf(req, res, function() {
|
||||||
if (callServerError) {
|
if (((href == "/easywaf-config.json" || (os.platform() == "win32" && href.toLowerCase() == "/easywaf-config.json")) || (href == "/easywaf-hooks.js" || (os.platform() == "win32" && href.toLowerCase() == "/easywaf-hooks.js"))) && __dirname == process.cwd()) {
|
||||||
callServerError(403, "easy-waf-integration/1.2.1");
|
|
||||||
} else {
|
|
||||||
res.writeHead(403, "Forbidden", {
|
|
||||||
"Server": "SVR.JS",
|
|
||||||
"Content-Type": "text/plain"
|
|
||||||
});
|
|
||||||
res.end("403 Forbidden!");
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
try {
|
|
||||||
elseCallback();
|
|
||||||
} catch (ex) {
|
|
||||||
if (callServerError) {
|
if (callServerError) {
|
||||||
callServerError(500, "easy-waf-integration/1.2.1", ex);
|
callServerError(403, "easy-waf-integration/1.2.2");
|
||||||
} else {
|
} else {
|
||||||
res.writeHead(500, "Internal Server Error", {
|
res.writeHead(403, "Forbidden", {
|
||||||
"Server": "SVR.JS",
|
"Server": "SVR.JS",
|
||||||
"Content-Type": "text/plain"
|
"Content-Type": "text/plain"
|
||||||
});
|
});
|
||||||
res.end(ex.stack);
|
res.end("403 Forbidden!");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
try {
|
||||||
|
elseCallback();
|
||||||
|
} catch (ex) {
|
||||||
|
if (callServerError) {
|
||||||
|
callServerError(500, "easy-waf-integration/1.2.2", ex);
|
||||||
|
} else {
|
||||||
|
res.writeHead(500, "Internal Server Error", {
|
||||||
|
"Server": "SVR.JS",
|
||||||
|
"Content-Type": "text/plain"
|
||||||
|
});
|
||||||
|
res.end(ex.stack);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
} catch(ex) {
|
||||||
|
if (callServerError) {
|
||||||
|
callServerError(500, "easy-waf-integration/1.2.2", ex);
|
||||||
|
} else {
|
||||||
|
res.writeHead(500, "Internal Server Error", {
|
||||||
|
"Server": "SVR.JS",
|
||||||
|
"Content-Type": "text/plain"
|
||||||
|
});
|
||||||
|
res.end(ex.stack);
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
}
|
}
|
||||||
if(req._readableState.length > 0 || req._readableState.ended) {
|
if(req._readableState.length > 0 || req._readableState.ended) {
|
||||||
readableHandler();
|
readableHandler();
|
||||||
|
|
2
mod.info
2
mod.info
|
@ -1,4 +1,4 @@
|
||||||
{
|
{
|
||||||
"name": "Integration with EasyWAF",
|
"name": "Integration with EasyWAF",
|
||||||
"version": "1.2.1"
|
"version": "1.2.2"
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue