]> git.ipfire.org Git - thirdparty/rspamd.git/commitdiff
[Fix] Fix schema usage in reputation and ratelimit plugins
authorVsevolod Stakhov <vsevolod@rspamd.com>
Wed, 19 Nov 2025 10:41:10 +0000 (10:41 +0000)
committerVsevolod Stakhov <vsevolod@rspamd.com>
Wed, 19 Nov 2025 10:41:10 +0000 (10:41 +0000)
- reputation: use :check() method instead of calling schema as function
- ratelimit: fix burst and rate transform schemas (inner describes result)

lualib/plugins/ratelimit.lua
src/plugins/lua/reputation.lua

index 0b674f9c1e0e385a38d503774feea0e70a98ecf5..265b5fce2c2570798f19b3c8be332ea303337c26 100644 (file)
@@ -100,11 +100,21 @@ end
 local bucket_schema = T.table({
   burst = T.one_of({
     T.number(),
-    T.transform(T.string(), lua_util.dehumanize_number)
+    T.transform(T.number(), function(val)
+      if type(val) == "string" then
+        return lua_util.dehumanize_number(val)
+      end
+      return val
+    end)
   }):doc({ summary = "Burst size (number of messages)" }),
   rate = T.one_of({
     T.number(),
-    T.transform(T.string(), str_to_rate)
+    T.transform(T.number(), function(val)
+      if type(val) == "string" then
+        return str_to_rate(val)
+      end
+      return val
+    end)
   }):doc({ summary = "Rate limit (messages per time unit)" }),
   skip_recipients = T.boolean():optional():doc({ summary = "Skip per-recipient limits" }),
   symbol = T.string():optional():doc({ summary = "Custom symbol name" }),
index e43edc3478424ec6af86117cbb307e98a60d63f7..fde9a4ad9d31fab27b2b7e0c95a187edf78798ee 100644 (file)
@@ -1316,10 +1316,10 @@ local function parse_rule(name, tbl)
   rule.config = lua_util.override_defaults(rule.config, tbl)
 
   if rule.config.whitelist then
-    if lua_maps_exprs.schema(rule.config.whitelist) then
+    if lua_maps_exprs.schema:check(rule.config.whitelist) then
       rule.config.whitelist_map = lua_maps_exprs.create(rspamd_config,
           rule.config.whitelist, N)
-    elseif lua_maps.map_schema(rule.config.whitelist) then
+    elseif lua_maps.map_schema:check(rule.config.whitelist) then
       local map = lua_maps.map_add_from_ucl(rule.config.whitelist,
           'radix',
           sel_type .. ' reputation whitelist')