More CrowdSec improvements.
Ylian Saint-Hilaire committed
Jul 8, 2022 at 00:15 UTC
ecdf0e450a4c5407322ea9e775482f5148df2d3c
3 files changed
+7
-4
MeshCentralServer.njsproj
+1
@@ -100,6 +100,7 @@
100
<Compile Include="amt\amt-xml.js" />
101
<Compile Include="amt\amt.js" />
102
<Compile Include="authenticode.js" />
103
+ <Compile Include="crowdsec.js" />
104
<Compile Include="exeHandler.js" />
105
<Compile Include="amtprovisioningserver.js" />
106
<Compile Include="firebase.js" />
crowdsec.js
+4
-3
@@ -5,7 +5,7 @@ module.exports.CreateCrowdSecBouncer = function (parent, config) {
5
const { getLogger } = require('@crowdsec/express-bouncer/src/nodejs-bouncer/lib/logger');
6
const { configure, renderBanWall, testConnectionToCrowdSec, getRemediationForIp } = require('@crowdsec/express-bouncer/src/nodejs-bouncer');
7
const applyCaptcha = require('@crowdsec/express-bouncer/src/express-crowdsec-middleware/lib/captcha');
8
- const { BYPASS_REMEDIATION, CAPTCHA_REMEDIATION, BAN_REMEDIATION } = require('@crowdsec/express-bouncer/src/nodejs-bouncer/lib/constants');
8
+ const { BYPASS_REMEDIATION, CAPTCHA_REMEDIATION, BAN_REMEDIATION } = require('@crowdsec/express-bouncer/src/nodejs-bouncer/lib/constants'); // "bypass", "captcha", "ban";
9
const svgCaptcha = require('svg-captcha');
10
const { renderCaptchaWall } = require('@crowdsec/express-bouncer/src/nodejs-bouncer');
11
@@ -15,7 +15,7 @@ module.exports.CreateCrowdSecBouncer = function (parent, config) {
15
// Set the default values
16
if (typeof config.userAgent != 'string') { config.userAgent = "CrowdSec Express-NodeJS bouncer/v0.0.1"; }
17
if (typeof config.timeout != 'number') { config.timeout = 2000; }
18
- if (typeof config.fallbackRemediation != 'number') { config.fallbackRemediation = BAN_REMEDIATION; }
18
+ if ((typeof config.fallbackRemediation != 'string') || (["bypass", "captcha", "ban"].indexOf(config.fallbackRemediation) == -1)) { config.fallbackRemediation = BAN_REMEDIATION; }
19
if (typeof config.maxRemediation != 'number') { config.maxRemediation = BAN_REMEDIATION; }
20
if (typeof config.captchaGenerationCacheDuration != 'number') { config.captchaGenerationCacheDuration = 60 * 1000; }
21
if (typeof config.captchaResolutionCacheDuration != 'number') { config.captchaResolutionCacheDuration = 30 * 60 * 1000; }
@@ -53,7 +53,8 @@ module.exports.CreateCrowdSecBouncer = function (parent, config) {
53
// Process a web request
54
obj.process = async function (domain, req, res, next) {
55
try {
56
- const remediation = await getRemediationForIp(req.clientIp);
56
+ var remediation = config.fallbackRemediation;
57
+ try { remediation = await getRemediationForIp(req.clientIp); } catch (ex) { }
58
//console.log('CrowdSec', req.clientIp, remediation, req.url);
59
switch (remediation) {
60
case BAN_REMEDIATION:
meshcentral-config-schema.json
+2
-1
@@ -201,7 +201,8 @@
201
"description": "Enabled the MeshCentral built-in Crowdsec bouncer. This section is passed directly to the bouncer, all of the settings are documented at https://www.npmjs.com/package/@crowdsec/express-bouncer",
202
"properties": {
203
"url": { "type": "string", "description": "The URL of your LAPI instance. Ex: http://localhost:8080" },
204
- "apiKey": { "type": "string", "description": "The bouncer key (generated via cscli)" }
204
+ "apiKey": { "type": "string", "description": "The bouncer key (generated via cscli)." },
205
+ "fallbackRemediation": { "type": "string", "default": "ban", "enum": ["bypass", "captcha", "ban"], "description": "Action to perform if the CrowdSec agent can't be contacted." }
206
},
207
"required": [ "url", "apiKey" ]
208
},