From abd6315416e968a4efe1338fdc9674af6d75ab6c Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Thu, 5 Oct 2023 20:22:21 +0100 Subject: [PATCH] [Minor] Apply schema for all fuzzy rules --- lualib/lua_fuzzy.lua | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) 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 -- 2.39.5