From 300b44899095f3d03b60df8d9481273f56d6a3a3 Mon Sep 17 00:00:00 2001 From: alteredCoder Date: Wed, 9 Mar 2022 15:18:13 +0100 Subject: [PATCH] Fix fallback remediation --- lib/crowdsec.lua | 4 ++-- lib/plugins/crowdsec/config.lua | 10 +++++++++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/lib/crowdsec.lua b/lib/crowdsec.lua index 48dd882..7f73849 100644 --- a/lib/crowdsec.lua +++ b/lib/crowdsec.lua @@ -223,7 +223,7 @@ function stream_query() end local remediation_id = get_remediation_id(decision.type) if remediation_id == nil then - remediation_id = 1 + remediation_id = get_remediation_id(runtime.fallback) end local key = item_to_string(decision.value, decision.scope) local succ, err, forcible = runtime.cache:set(key, false, ttl, remediation_id) @@ -286,7 +286,7 @@ function live_query(ip) if runtime.conf["BOUNCING_ON_TYPE"] == decision.type or runtime.conf["BOUNCING_ON_TYPE"] == "all" then local remediation_id = get_remediation_id(decision.type) if remediation_id == nil then - remediation_id = 1 + remediation_id = get_remediation_id(runtime.fallback) end local key = item_to_string(decision.value, decision.scope) local succ, err, forcible = runtime.cache:set(key, false, runtime.conf["CACHE_EXPIRATION"], remediation_id) diff --git a/lib/plugins/crowdsec/config.lua b/lib/plugins/crowdsec/config.lua index 5c3ade5..a852a41 100644 --- a/lib/plugins/crowdsec/config.lua +++ b/lib/plugins/crowdsec/config.lua @@ -92,7 +92,15 @@ function config.loadConfig(file) conf[v] = exclude_location break end - + if v == "FALLBACK_REMEDIATION" then + local value = s[2] + if not has_value({'captcha', 'ban'}, s[2]) then + ngx.log(ngx.ERR, "unsupported value '" .. s[2] .. "' for variable '" .. v .. "'. Using default value 'ban' instead") + local n = next(s, k) + conf[v] = "ban" + break + end + end local n = next(s, k) conf[v] = s[n] break