]> source.dussan.org Git - rspamd.git/commitdiff
[Minor] Apply schema for all fuzzy rules
authorVsevolod Stakhov <vsevolod@rspamd.com>
Thu, 5 Oct 2023 19:22:21 +0000 (20:22 +0100)
committerVsevolod Stakhov <vsevolod@rspamd.com>
Thu, 5 Oct 2023 19:22:21 +0000 (20:22 +0100)
lualib/lua_fuzzy.lua

index f941436eb784f0b2510d09f808355c1e8ad9d2f0..986d1a045bc4d38d2454d21c1b80e27de4a94a03 100644 (file)
@@ -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