{"id":1743,"date":"2013-11-24T17:31:27","date_gmt":"2013-11-24T15:31:27","guid":{"rendered":"http:\/\/www.void.gr\/kargig\/blog\/?p=1743"},"modified":"2013-11-24T17:46:43","modified_gmt":"2013-11-24T15:46:43","slug":"anonymize-headers-in-postfix","status":"publish","type":"post","link":"https:\/\/www.void.gr\/kargig\/blog\/2013\/11\/24\/anonymize-headers-in-postfix\/","title":{"rendered":"Anonymize headers in postfix"},"content":{"rendered":"<p>E-mail headers usually leak some information about the person sending the email. Most servers reveal the sender&#8217;s originating IP, but sometimes we might not want this behavior. Here&#8217;s a simple way to modify your postfix server to remove just the IP of the sender. The original idea is from <a href=\"https:\/\/we.riseup.net\/debian\/mail\">https:\/\/we.riseup.net\/debian\/mail<\/a> but with postfix 2.9 version (Debian Wheezy) using the way proposed in the riseup article you will also be anonymizing all intermediate &#8216;Received: from&#8217; headers and not just the sender&#8217;s. The setup proposed by riseup article seems to work fine with postfix 2.7 (Debian Squeeze).<\/p>\n<p><strong>1.<\/strong> Install <em>postfix-pcre<\/em> if you haven&#8217;t already.<br \/>\n<code># apt-get install postfix-pcre<\/code><\/p>\n<p><strong><br \/>\n2.<\/strong> Create a file <em>\/etc\/postfix\/smtp_header_checks<\/em> with content:<br \/>\n<code>\/^\\s*(Received: from)[^\\n]*(.*)\/ REPLACE $1 [127.0.0.1] (localhost [127.0.0.1])$2<\/code><\/p>\n<p><strong><br \/>\n3.<\/strong> Edit <em>\/etc\/postfix\/master.cf<\/em><br \/>\nFind the section about submission and add at the end of it: <code>-o cleanup_service_name=subcleanup<\/code><br \/>\ne.g.<br \/>\n<pre><code2>submission inet n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; -&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; -&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; -&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; -&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; smtpd\n&nbsp;&nbsp;-o smtpd_tls_security_level=encrypt\n&nbsp;&nbsp;-o smtpd_sasl_auth_enable=yes\n&nbsp;&nbsp;-o smtpd_client_restrictions=permit_sasl_authenticated,reject\n&nbsp;&nbsp;-o milter_macro_daemon_name=ORIGINATING<\/code2><\/pre><\/p>\n<p><pre><code2>submission inet n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; -&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; -&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; -&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; -&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; smtpd\n&nbsp;&nbsp;-o smtpd_tls_security_level=encrypt\n&nbsp;&nbsp;-o smtpd_sasl_auth_enable=yes\n&nbsp;&nbsp;-o smtpd_client_restrictions=permit_sasl_authenticated,reject\n&nbsp;&nbsp;-o milter_macro_daemon_name=ORIGINATING\n&nbsp;&nbsp;-o cleanup_service_name=subcleanup<\/code2><\/pre><\/p>\n<p>Then at the end of <em>\/etc\/postfix\/master.cf<\/em> file add the following:<br \/>\n<pre><code2>subcleanup unix n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; -&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; -&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; -&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 0&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; cleanup\n&nbsp;&nbsp;&nbsp;&nbsp;-o header_checks=pcre:\/etc\/postfix\/smtp_header_checks<\/code2><\/pre><\/p>\n<p>That&#8217;s it, reload your postfix and you&#8217;re done. When you&#8217;ll be sending emails over submission (you do use submission instead of smtp to send your emails, right?) then the first &#8216;Received&#8217; header will be modified like the following example.<br \/>\nInstead of:<br \/>\n<pre><code2>Received: from foo.bar (abcd.efgh.domain.tld [111.222.100.200])\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;by mail.domain.tld (Postfix) with ESMTPA id BAB8A1A0224\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;for &lt;user@dst.domain2.tld&gt;; Sun, 24 Nov 2013 15:47:50 +0100 (CET)<\/code2><\/pre><\/p>\n<p>It will be:<br \/>\n<pre><code2>Received: from [127.0.0.1] (localhost [127.0.0.1])\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;by mail.domain.tld (Postfix) with ESMTPA id BAB8A1A0224\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;for &lt;user@dst.domain2.tld&gt;; Sun, 24 Nov 2013 15:47:50 +0100 (CET)<\/code2><\/pre><\/p>\n<p><strong>Extra<\/strong><br \/>\nIf you want to anonymize even more headers, try adding the following to \/etc\/postfix\/smtp_header_checks<br \/>\n<pre><code2>\/^\\s*User-Agent\/&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;IGNORE\n\/^\\s*X-Enigmail\/&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;IGNORE\n\/^\\s*X-Mailer\/&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;IGNORE\n\/^\\s*X-Originating-IP\/&nbsp;&nbsp;IGNORE<\/code2><\/pre><\/p>\n<p><strong>Logging<\/strong><br \/>\nAs the riseup article says, <em>be very careful of what is being logged<\/em> at the server. If you don&#8217;t want to log the replacements done by pcre then add something like the following in your rsyslog.conf before any other rule:<br \/>\n<code>:msg, contains, \"replace: header Received:\" ~<\/code><\/p>\n","protected":false},"excerpt":{"rendered":"<p>E-mail headers usually leak some information about the person sending the email. Most servers reveal the sender&#8217;s originating IP, but sometimes we might not want this behavior. Here&#8217;s a simple way to modify your postfix server to remove just the IP of the sender. The original idea is from https:\/\/we.riseup.net\/debian\/mail but with postfix 2.9 version [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"ep_exclude_from_search":false,"footnotes":""},"categories":[5,3,8],"tags":[519,33,561,244,427,497,563,562],"class_list":["post-1743","post","type-post","status-publish","format-standard","hentry","category-internet","category-linux","category-networking","tag-anonymity","tag-debian","tag-headers","tag-postfix","tag-smtp","tag-squeeze","tag-submission","tag-wheezy"],"aioseo_notices":[],"views":76831,"_links":{"self":[{"href":"https:\/\/www.void.gr\/kargig\/blog\/wp-json\/wp\/v2\/posts\/1743","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.void.gr\/kargig\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.void.gr\/kargig\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.void.gr\/kargig\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.void.gr\/kargig\/blog\/wp-json\/wp\/v2\/comments?post=1743"}],"version-history":[{"count":5,"href":"https:\/\/www.void.gr\/kargig\/blog\/wp-json\/wp\/v2\/posts\/1743\/revisions"}],"predecessor-version":[{"id":1748,"href":"https:\/\/www.void.gr\/kargig\/blog\/wp-json\/wp\/v2\/posts\/1743\/revisions\/1748"}],"wp:attachment":[{"href":"https:\/\/www.void.gr\/kargig\/blog\/wp-json\/wp\/v2\/media?parent=1743"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.void.gr\/kargig\/blog\/wp-json\/wp\/v2\/categories?post=1743"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.void.gr\/kargig\/blog\/wp-json\/wp\/v2\/tags?post=1743"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}