aboutsummaryrefslogtreecommitdiffstats
path: root/lualib
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@rspamd.com>2023-10-05 20:22:21 +0100
committerVsevolod Stakhov <vsevolod@rspamd.com>2023-10-05 20:22:21 +0100
commitabd6315416e968a4efe1338fdc9674af6d75ab6c (patch)
treef4f929bb575c878ab8c2909e34796e9ce538ff41 /lualib
parent2eba7a0b1aa5c78999b0b82565636ac8d269ccc7 (diff)
downloadrspamd-abd6315416e968a4efe1338fdc9674af6d75ab6c.tar.gz
rspamd-abd6315416e968a4efe1338fdc9674af6d75ab6c.zip
[Minor] Apply schema for all fuzzy rules
Diffstat (limited to 'lualib')
-rw-r--r--lualib/lua_fuzzy.lua15
1 files changed, 14 insertions, 1 deletions
diff --git a/lualib/lua_fuzzy.lua b/lualib/lua_fuzzy.lua
index f941436eb..986d1a045 100644
--- a/lualib/lua_fuzzy.lua
+++ b/lualib/lua_fuzzy.lua
@@ -48,7 +48,7 @@ local policies = {
local default_policy = policies.recommended
-local policy_schema = ts.shape {
+local schema_fields = {
min_bytes = ts.number + ts.string / tonumber,
min_height = ts.number + ts.string / tonumber,
min_width = ts.number + ts.string / tonumber,
@@ -60,6 +60,11 @@ local policy_schema = ts.shape {
text_shingles = ts.boolean,
skip_images = ts.boolean,
}
+local policy_schema = ts.shape(schema_fields)
+
+local policy_schema_open = ts.shape(schema_fields, {
+ open = true,
+})
local exports = {}
@@ -99,6 +104,14 @@ exports.process_rule = function(rule)
if policy then
processed_rule = lua_util.override_defaults(policy, processed_rule)
+
+ local parsed_policy, err = policy_schema_open:transform(processed_rule)
+
+ if not parsed_policy then
+ rspamd_logger.errx(rspamd_config, 'invalid fuzzy rule default fields: %s', err)
+ else
+ processed_rule = parsed_policy
+ end
else
rspamd_logger.warnx(rspamd_config, "unknown policy %s", processed_rule.policy)
end