Whitelist Blacklist Domain in Zimbra: 5 Proven Amavis Fixes
Zimbra has no "whitelist" button for the whole server. The way I set a server-wide whitelist blacklist domain list on Zimbra 8.6 was a lookup table in Amavis, the content filter Zimbra runs in front of SpamAssassin: a negative score for trusted senders, a positive score for unwanted ones. This rewrite keeps that table from my servers and tests it in a real Amavis to answer what the old post did not: which keys match subdomains, which key format never matches at all, and what a forged sender gets.
Lab note: Zimbra is not installed for the test. The lab runs amavis 2.13.0 with SpamAssassin 4.0.1 on debian:13, with the post's table loaded into @score_sender_maps, and Postfix delivering to a local mailbox. Test messages go straight into Amavis on port 10024 with swaks, and the scores come from the X-Spam-Score header of the delivered mail. The Zimbra file name and restart command are from my Zimbra 8.6 servers.
Contents
- Where the Zimbra whitelist blacklist domain table lives
- How the scores behave in a real Amavis
- The key format decides what matches
- A domain without a dot does not cover subdomains
- The '@domain' key never matches
- Limits of a whitelist blacklist domain table
- It is a score, not a block
- The envelope sender can be forged
- zmprov does not show these entries
- Checklist
Where the Zimbra whitelist blacklist domain table lives
On Zimbra the Amavis configuration is generated from a template, /opt/zimbra/conf/amavisd.conf.in. Edit the template, not the generated file, and back it up first, as the zimbra user:
su - zimbra
cp /opt/zimbra/conf/amavisd.conf.in /opt/zimbra/conf/amavisd.conf.in.bak
vim /opt/zimbra/conf/amavisd.conf.in
The Zimbra whitelist and blacklist share one table. The template contains a @score_sender_maps block with a hash table. Each key is a sender, each value is a score added to the SpamAssassin result: negative works as a soft whitelist, positive as a soft blacklist. These are the entries I used:
{ # a hash-type lookup table (associative array)
'example.com' => -10.0,
'nobody@cert.org' => -3.0,
'huuphan.com' => -20.0,
'devopsskills.info' => -20.0,
'emailid@example.com' => 10.0,
'@mail.example.com' => 10.0,
},
After saving, restart Amavis with zmamavisdctl restart and watch /var/log/zimbra.log (the old post used tailf; Debian 13 with util-linux 2.41.5 has no tailf, so use tail -f). Templates under /opt/zimbra/conf can be replaced by an upgrade, so keep a copy of your entries.
How the scores behave in a real Amavis
To see what a Zimbra whitelist entry really does, start from a baseline. A short, normal message from an unlisted domain scores almost zero. In the lab this baseline was -0.002; every other result below is that baseline plus the table value:
$ swaks --port 10024 --from bob@other.test --to alice@example.test # body: normal
X-Spam-Flag: NO
X-Spam-Score: -0.002
X-Spam-Status: No, score=-0.002 tagged_above=-999 required=6
$ swaks --port 10024 --from bob@huuphan.com --to alice@example.test # body: normal
X-Spam-Flag: NO
X-Spam-Score: -20.002
X-Spam-Status: No, score=-20.002 tagged_above=-999 required=6
The blacklist entry for a single address works too. Amavis adds it as a test called AM.WBL, and with a spam threshold of 6 the message is now flagged:
$ swaks --port 10024 --from emailid@example.com --to alice@example.test # body: normal
X-Spam-Flag: YES
X-Spam-Score: 9.998
X-Spam-Status: Yes, score=9.998 tagged_above=-999 required=6 tests=[AM.WBL=10,
Note the order: emailid@example.com got +10 even though example.com is whitelisted with -10. Other addresses at example.com still got the whitelist score (-10.002). The more specific key wins, which is the lookup order described next.
The key format decides what matches
The Amavis documentation (README.lookups) lists the order of a hash lookup for User+foo@Sub.Example.com: the full address, the address without the extension, user+foo@, user@, then sub.example.com, .sub.example.com, .example.com, .com and finally .. "The search sequence stops as soon as a match is found." Two consequences for a whitelist blacklist domain table showed up in the lab.
A domain without a dot does not cover subdomains
$ swaks --port 10024 --from bob@mail.huuphan.com --to alice@example.test # body: normal
X-Spam-Flag: NO
X-Spam-Score: -0.002
X-Spam-Status: No, score=-0.002 tagged_above=-999 required=6
'huuphan.com' matches only the exact domain. To include subdomains, write the key with a leading dot. A test entry '.example.net' => -5.0 applied to both levels:
$ swaks --port 10024 --from bob@example.net --to alice@example.test # body: normal
X-Spam-Score: -5.002
X-Spam-Status: No, score=-5.002 tagged_above=-999 required=6 tests=[AM.WBL=-5,
$ swaks --port 10024 --from bob@mail.example.net --to alice@example.test # body: normal
X-Spam-Score: -5.002
X-Spam-Status: No, score=-5.002 tagged_above=-999 required=6 tests=[AM.WBL=-5,
The '@domain' key never matches
The old blacklist line '@mail.example.com' => 10.0 had no effect at all:
$ swaks --port 10024 --from bob@mail.example.com --to alice@example.test # body: normal
X-Spam-Flag: NO
X-Spam-Score: -0.002
$ swaks --port 10024 --from bob@sub.mail.example.com --to alice@example.test # body: normal
X-Spam-Flag: NO
X-Spam-Score: -0.002

None of the lookup steps in README.lookups produces a key that starts with @, so this entry is silently ignored. Use 'mail.example.com' for that one domain or '.mail.example.com' for the domain and its subdomains.
Limits of a whitelist blacklist domain table
It is a score, not a block
A Zimbra whitelist entry lowers the score; it does not let everything through. The GTUBE test string, which SpamAssassin scores at 1000, is still spam from a whitelisted domain:
$ swaks --port 10024 --from bob@other.test --to alice@example.test # body: GTUBE
X-Spam-Flag: YES
X-Spam-Score: 999.999
$ swaks --port 10024 --from bob@huuphan.com --to alice@example.test # body: GTUBE
X-Spam-Flag: YES
X-Spam-Score: 979.999
The same works in reverse: a blacklist score of +10 marks mail as spam but does not reject it. What happens next depends on your spam settings (Junk folder, quarantine or discard). To refuse a domain completely, block it at the MTA instead of scoring it.
The envelope sender can be forged
The table is checked against the envelope sender (the SMTP MAIL FROM), which a spammer can set to anything. A message with a forged huuphan.com envelope and an obvious scam From: header still got the whitelist bonus:
$ swaks --port 10024 --from spammer@huuphan.com --header 'From: Prize Office <win@lottery.test>'
Return-Path: <spammer@huuphan.com>
X-Spam-Score: -19.002
From: Prize Office <win@lottery.test>
A -20 whitelist for a popular domain is an invitation, and the main risk of any whitelist blacklist domain setup. Keep whitelist values small (a few points is enough to rescue a false positive), whitelist exact partner domains rather than big providers, and never whitelist your own domain this way: spammers forge it first. Rejecting forged senders from your own domain at the MTA is covered in Zimbra bounces from spam email.
zmprov does not show these entries
The old FAQ suggested zmprov gacf | grep amavis to view the lists. That prints Zimbra's global settings whose names contain "amavis" (in the current attribute file, names like zimbraAmavisFinalSpamDestiny, zimbraAmavisLogLevel and zimbraAmavisMaxServers). The whitelist blacklist domain table is in the template file, so read it there: grep -n -A12 score_sender_maps /opt/zimbra/conf/amavisd.conf.in.
Checklist
- Back up
amavisd.conf.in, edit the@score_sender_mapshash, runzmamavisdctl restart. - Exact domain:
'partner.com'; domain plus subdomains:'.partner.com'; single address:'user@partner.com'. Never'@partner.com'. - Negative values whitelist, positive values blacklist; specific keys beat general ones.
- Small values; scores do not override strong spam signals, and senders can be forged.
- Check every Zimbra whitelist change in the
X-Spam-Scoreheader of a test message.
A whitelist blacklist domain table is a small tool: use it to fix specific false positives and known bad senders. For scoring rules on content instead of senders, see Zimbra custom SpamAssassin rules. The full lookup rules are in the Amavis README.lookups.
Hi Greenware,
ReplyDeleteadd more domain or email.
Thanks
HuuPV
Em chào anh ạ, anh ơi em muốn hỏi chút về việc phân loại spam mail của Zimbra ấy ạ.
ReplyDeleteCụ thể là trong Zimbra có một list nào chứa các spam email address/domain trong quá trình hoạt động ko ạ; hoặc là Zimbra có rrule nào đó để classify 1 email/email address là spam hoặc độc hại ko ạ?
Em cảm ơn anh ạ!