]> git.ipfire.org Git - thirdparty/rspamd.git/commitdiff
[Fix] Avoid mutating cached redis_params in greylist
authorAlexander Moisseev <moiseev@mezonplus.ru>
Fri, 10 Apr 2026 11:02:09 +0000 (14:02 +0300)
committerAlexander Moisseev <moiseev@mezonplus.ru>
Fri, 10 Apr 2026 11:02:09 +0000 (14:02 +0300)
Pass a shallow copy of opts with redis_timeout set before calling
parse_redis_server, so the corrected timeout is baked into the cached
table. The previous post-assignment mutated the shared cached object,
potentially affecting other modules reusing the same Redis config.

src/plugins/lua/greylist.lua

index 22aa086f34705a019615f45e597d832a2f471db5..d9badcd502827cfda4c3b7fd1c50493d85681530 100644 (file)
@@ -568,14 +568,17 @@ if opts then
   whitelist_domains_map = lua_map.rspamd_map_add(N, 'whitelist_domains_url',
       'map', 'Greylist whitelist domains map')
 
-  redis_params = lua_redis.parse_redis_server(N)
+  -- Pass opts with redis_timeout instead of the greylisting period (settings.timeout),
+  -- so lua_redis does not mistake the greylisting period for a Redis connection timeout.
+  -- redis.greylist.timeout or the global redis.timeout can still override this via
+  -- enrich_defaults since settings.redis_timeout equals lua_redis's default_timeout (1.0).
+  local redis_opts = lua_util.shallowcopy(opts)
+  redis_opts.timeout = settings.redis_timeout
+  redis_params = lua_redis.parse_redis_server(N, redis_opts)
   if not redis_params then
     rspamd_logger.infox(rspamd_config, 'no servers are specified, disabling module')
     rspamd_lua_utils.disable_module(N, "redis")
   else
-    -- settings.timeout is the greylisting period, not a Redis connection timeout;
-    -- override to prevent it from being misused as such by lua_redis
-    redis_params.timeout = settings.redis_timeout
     lua_redis.register_prefix(settings.key_prefix .. 'b[a-z0-9]{20}', N,
         'Greylisting elements (body hashes)"', {
           type = 'string',