[Rspamd-Users] Settings: Multiple rules with same priority

Friedrichs, Jens jens.friedrichs at uni-leipzig.de
Wed Jun 1 13:06:48 UTC 2022


Hello Martin,

I also discovered this "bug" 😊

There is a little mistake(?) in the code. It only checks if a rule matched once per priority at the beginning.. not during the priority.
The " for _,s in ipairs(settings[pri]) do" loop should get a break after "applied = true" ... but it won't. So rspamd will also check all other rules with the same priority.
Maybe it is intentionally and the documentation is not correct 😊 

..........
local applied = false

  for pri = max_pri,min_pri,-1 do
    if not applied and settings[pri] then
      for _,s in ipairs(settings[pri]) do
        local matched = {}

        lua_util.debugm(N, task, "check for settings element %s",
            s.name)
        local result = check_specific_setting(s.rule, matched)
        -- Can use xor here but more complicated for reading
        if result then
          if s.rule['apply'] then
            if s.rule.id then
              -- Extract static settings
              local cached = lua_settings.settings_by_id(s.rule.id)

              if not cached or not cached.settings or not cached.settings.apply then
                rspamd_logger.errx(task, 'unregistered settings id found: %s!', s.rule.id)
              else
                rspamd_logger.infox(task, "<%s> apply static settings %s (id = %s); %s matched; priority %s",
                    task:get_message_id(),
                    cached.name, s.rule.id,
                    table.concat(matched, ','),
                    priority_to_string(pri))
                apply_settings(task, cached.settings.apply, s.rule.id, s.name)
              end

            else
              -- Dynamic settings
              rspamd_logger.infox(task, "<%s> apply settings according to rule %s (%s matched)",
                  task:get_message_id(), s.name, table.concat(matched, ','))
              apply_settings(task, s.rule.apply, nil, s.name)
            end

            applied = true    <<<<< Should get a break soon 😉
          end
          if s.rule['symbols'] then
            -- Add symbols, specified in the settings
            fun.each(function(val)
              task:insert_result(val, 1.0)
            end, s.rule['symbols'])
          end
        end
      end
    end
  end




-- 
Jens Friedrichs

System Administrator

Universität Leipzig
Universitätsrechenzentrum
Augustusplatz 10, 04109 Leipzig


T +49 341 97-33359
F +49 341 97-33399


jens.friedrichs at uni-leipzig.de

https://www.urz.uni-leipzig.de

-----Ursprüngliche Nachricht-----
Von: Users <users-bounces at lists.rspamd.com> Im Auftrag von Martin Mareš
Gesendet: Dienstag, 31. Mai 2022 21:11
An: users at lists.rspamd.com
Betreff: [Extern] [Rspamd-Users] Settings: Multiple rules with same priority

Hello!

I am trying to understand how Rspamd applies settings. According to documentation at

	https://rspamd.com/doc/configuration/settings.html

once a rule matches, only that rule is applied and the rest are ignored.

With Rspamd 3.2, I am observing multiple applied rules. Indeed, according to plugins/settings.lua, the other rules with the same priority are still processed and only rules with smaller priority are skipped.

Which is correct? Implementation or documentation? :)

				Have a nice fortnight
-- 
Martin `MJ' Mareš                <mares at kam.mff.cuni.cz>   http://mj.ucw.cz/
KAM, Faculty of Math and Physics, Charles University, Prague, Czechia, Earth The computer is mightier than the pen, the sword, and usually, the programmer.
--
Users mailing list
Users at lists.rspamd.com
https://lists.rspamd.com/mailman/listinfo/users


More information about the Users mailing list