3

I have a mail server with Postfix and Dovecot and users can send emails, but (after login) they can change the address and send from other username@example.com.

For example, user1@example.com login to email via IMAP/SMTP and then he change the address to admin@example.com and is still allowed to send mails impersonating that other user.

How can I disable this? I tried

smtpd_sender_restrictions = reject_authenticated_sender_login_mismatch

but then user1 cant send mail even from user1@example.com.

1

In order to restrict the addressess allowed in the MAIL FROM command based on the user, Postfix needs to know which address(es) belongs to which users. Therefore, you must use these restrictions with smtpd_sender_login_maps.

smtpd_sender_restrictions

If you are using virtual_alias_maps to map the addresses to local users, the format is identical for smtpd_sender_login_maps, and you can simply use the same file. In this example, I assume a hash: Berkeley DB in /etc/postfix/virtual (requires postmap /etc/postfix/virtual after modifications):

user1@example.com user1
joe.bloggs@example.com user1
user2@example.com user2
jane.doe@example.com user2
admin@example.com root

With this, it's possible to utilize the same file for both purposes, and the modifications to the incoming maps will immediately affect the allowed outbound addresses, too.

  • In main.cf:

    virtual_alias_domains = example.com
    virtual_alias_maps = hash:/etc/postfix/virtual
    
  • For the authenticated submission (on port 587) in master.cf (assuming TLS & Dovecot SASL):

    submission inet n - - - - smtpd
      -o smtpd_tls_security_level=encrypt
      -o smtpd_sasl_auth_enable=yes
      -o smtpd_sasl_type=dovecot
      -o smtpd_sasl_path=private/auth
      -o smtpd_sasl_security_options=noanonymous
      -o smtpd_sasl_local_domain=$myhostname
      -o smtpd_client_restrictions=permit_sasl_authenticated,reject
      -o smtpd_sender_login_maps=hash:/etc/postfix/virtual
      -o smtpd_sender_restrictions=reject_sender_login_mismatch
    
  • Of course it's possible to use the

    smtpd_sender_login_maps = hash:/etc/postfix/virtual
    smtpd_sender_restrictions = reject_authenticated_sender_login_mismatch
    

    directly in the main.cf, but I recommend using separate configuration for submission: It enables you to use different set of restrictions and other settings for authenticated users than for incoming mail, and it also works better e.g. with home internet connections that restricts the use of SMTP port 25.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.