postfix sender restrictions – job NOT done

OK, I admit to being dumb. I got another scam email yesterday of the same formulation as the earlier ones (mail From: me@mydomain, To: me@mydomain) attempting to extort bitcoin from me.

How? What had I missed this time?

Well, this was slightly different. Checking the mail headers (and my logs) showed that the email had a valid “Sender” address (some bozo calling themselves “”) so my earlier “check_sender_access” test would obviously have allowed the email to pass. But what I hadn’t considered was that the sender might then spoof the From: address in the data portion of the email (which is trivially easy to do).

Dumb, so dumb. So what to do to stop this?

Postfix allows for quite a lot of further directives to manage senders through the smtpd_sender_restrictions and mine were still not tight enough to stop this form of abuse. One additional check is offered by the reject_sender_login_mismatch directive which will:

“Reject the request when $smtpd_sender_login_maps specifies an owner for the MAIL FROM address, but the client is not (SASL) logged in as that MAIL FROM address owner; or when the client is (SASL) logged in, but the client login name doesn’t own the MAIL FROM address according to $smtpd_sender_login_maps.”

Now since I store all my user details in a mysql database called “virtual_mailbox_maps” it is simple enough to tell postfix to use that database as the “smtpd_sender_login_map” and check the “From” address against that, That way only locally authenticated valid users can specify a local “From:” address. Why I missed that check is just beyond me.

My postfix configuration now includes the following:

smtpd_sender_login_maps = $virtual_mailbox_maps

smtpd_sender_restrictions = permit_sasl_authenticated, permit_mynetworks, reject_non_fqdn_sender, reject_unauthenticated_sender_login_mismatch, check_sender_access hash:/etc/postfix/localdomains

(Note that I chose to use the “reject_unauthenticated_sender_login_mismatch” rather than the wider “reject_sender_login_mismatch” because I only care about outside unauthenticated senders abusing my system. I can deal with authenticated users differently…)

Now let’s see what happens.

Permanent link to this article:


    • David on 2019/03/09 at 9:30 pm

    How would this affect mailing lists?
    i.e. If you were to send newsletters from Mail Chimp or Constant Contact, and the “from” address on that newsletter is your domain. If I’m understanding this parameter correctly, then if ‘reject_sender_login_mismatch’ is enabled, then those newsletter emails would be blocked.

    • Mick on 2019/03/11 at 2:53 pm


    I considered this point before I made the change because I am a member of several mailing lists (tor-relays, tor-talk, alug, etc.) and I didn’t want mail to be rejected. Fortunately, well run mail lists using decent software (such as mailman) always send mail to list members from the list itself rather than just relaying the mail out unchanged. So for example, I get email from the anglia linux user group with the sender set as “”. Thus postfix sees the connection from the external server with a valid external sender address. See for example this recent exchange:

    Mar 6 17:11:42 bin postfix/smtpd[31770]: connect from[]
    Mar 6 17:11:42 bin postfix/smtpd[31770]: Anonymous TLS connection established from[]: TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)
    Mar 6 17:11:42 bin postgrey[29071]: action=pass, reason=triplet found,, client_address=,, recipient=mick@mydomain
    Mar 6 17:11:43 bin postgrey[29071]: action=pass, reason=triplet found,, client_address=,, recipient=mick@mydomain
    Mar 6 17:11:43 bin postfix/smtpd[31770]: 7342D17E08B:[]
    Mar 6 17:11:43 bin postfix/cleanup[31773]: 7342D17E08B: message-id=20190306165542.265b4b8a.mick@mydomain
    Mar 6 17:11:43 bin postfix/qmgr[5536]: 7342D17E08B:, size=4339, nrcpt=1 (queue active)
    Mar 6 17:11:43 bin postfix/virtual[31774]: 7342D17E08B: to=mick@mydomain, relay=virtual, delay=1.1, delays=1/0.01/0/0.02, dsn=2.0.0, status=sent (delivered to maildir)
    Mar 6 17:11:43 bin postfix/qmgr[5536]: 7342D17E08B: removed
    Mar 6 17:11:43 bin postfix/smtpd[31770]: disconnect from[] ehlo=2 starttls=1 mail=1 rcpt=1 data=1 quit=1 commands=7

    (I have edited the IP address and my email address to protect the innocent.)


Comments have been disabled.