commit abd6315: [Minor] Apply schema for all fuzzy rules

Vsevolod Stakhov vsevolod at rspamd.com
Thu Oct 5 19:28:03 UTC 2023


Author: Vsevolod Stakhov
Date: 2023-10-05 20:22:21 +0100
URL: https://github.com/rspamd/rspamd/commit/abd6315416e968a4efe1338fdc9674af6d75ab6c (HEAD -> master)

[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


More information about the Commits mailing list