haraka / Haraka

A fast, highly extensible, and event driven SMTP server
https://haraka.github.io
MIT License
5.04k stars 662 forks source link

Spamassasin not (to late) contributing to karma score #2997

Closed frank-bn closed 1 year ago

frank-bn commented 2 years ago

Describe the bug

Incoming mails are checked by spamassasin and karma is giving awards for spamassasin hits. But the problem is (as seen in the haraka log) that karma is assigning spamassasin awards after the smtp_forward plugin. At this time the mail is already delivered and a bad karma of -8 or lower will not reject the mail. We are not sure if this is a bug or only a wrong haraka configuration.

Expected behavior

Karma adds awards for spamassassin to the karma score before the mail is delivered via smtp_forward. Karma also rejects the mail if the karma score is lower than -8 (default treshold).

Observed behavior

See this condensed example from our mail.log:

…[karma] adding header: score: -5, awards: 023,001,002,133, fail:rcpt_to
...
…[spamassassin] header: X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on …
…[spamassassin] header: X-Spam-Level: ***
…[spamassassin] header: X-Spam-Status: No, score=3.1 required=5.0 tests=BODY_URI_ONLY,HTML_EXTRA_CLOSE,
…[spamassassin] status=No, score=3.1, required=5.0, reject=undefined, …
…[core]  hook=data_post plugin=spamassassin function=hook_data_post params="" retval=CONT msg=""
...
…[core] running queue hooks
…[core] running queue hook in karma plugin
…[core]  hook=queue plugin=karma function=hook_queue params="" retval=CONT msg=""
…[core] running queue hook in queue/smtp_forward plugin
…[queue/smtp_forward] Got smtp_client: F108AA6B-E8A6-4BDB-B991-1B41D20464DA
…[queue/smtp_forward] forwarding to …
…
…[core] running reset_transaction hook in karma plugin
…[karma] score: -9, awards: 023,001,002,133,256,257,259, fail:rcpt_to
…[core]  hook=reset_transaction plugin=karma function=hook_reset_transaction params="" retval=CONT msg=""

Steps To Reproduce

The problem appears at every incoming mail.

System Info:

Haraka Haraka.js — Version: 2.8.27
Node v10.19.0
OS Linux xxxxx.belnet.de 5.4.0-89-generic #100-Ubuntu SMP Fri Sep 24 14:50:10 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux
openssl OpenSSL 1.1.1f 31 Mar 2020

Additional context

The following Plugins are activated in this order:

syslog
redis
karma
access
p0f
geoip
asn
fcrdns
dnsbl
greylist
early_talker
helo.checks
mail_from.is_resolvable
spf
rcpt_to.in_host_list
bounce
headers
data.uribl
attachment
clamd
spamassassin
limit
queue/smtp_forward
msimerson commented 1 year ago

But the problem is (as seen in the haraka log) that karma is assigning spamassasin awards after the smtp_forward plugin.

I think the issue here is perception. Karma updates the transactions score the instant that a plugin reports it and that is definitely happening during data_post when spamassassin reports it. However, karma doesn't make noise and report it every single time a karma update is made. That would be...obnoxious.

In your example, doesn't think the message is very spammy status=No, score=3.1, required=5.0, and so it didn't contribute much to the karma score.