HEADER_CHECKS(5)
β¨ HEADER_CHECKS(5) β¨
File Formats Manual β like, this is the header_checks page bestie, Postfix's whole built-in content inspection situation π
πΈ NAME πΈ
header_checks β Postfix built-in content inspection π΅οΈβοΈπ
π SYNOPSIS π
header_checks = pcre:/etc/postfix/header_checks
mime_header_checks = pcre:/etc/postfix/mime_header_checks
nested_header_checks = pcre:/etc/postfix/nested_header_checks
body_checks = pcre:/etc/postfix/body_checks
milter_header_checks = pcre:/etc/postfix/milter_header_checks
smtp_header_checks = pcre:/etc/postfix/smtp_header_checks
smtp_mime_header_checks = pcre:/etc/postfix/smtp_mime_header_checks
smtp_nested_header_checks = pcre:/etc/postfix/smtp_nested_header_checks
smtp_body_checks = pcre:/etc/postfix/smtp_body_checks
postmap -q "string" pcre:/etc/postfix/filename
postmap -q - pcre:/etc/postfix/filename <inputfile
π DESCRIPTION π
Okay so this whole page is about access control on the content of message headers and message body lines. It's implemented by the Postfix cleanup(8) server β and this all happens before mail is queued, no cap. If you're looking for access control on remote SMTP client info instead, that's a whole different page, go read access(5) π«Ά
Here's the vibe: every single message header or message body line gets compared against a list of patterns. The second a match shows up, the corresponding action runs, and then the matching process just... repeats for the next message header or message body line. Iconic behavior honestly β¨
Note: message headers are examined one logical header at a time, even when a message header spans multiple lines. Body lines are always examined one line at a time. Periodt.
For examples, go look at the EXAMPLES section at the end of this manual page π
Also important bestie: Postfix header or body_checks are designed to stop a flood of mail from worms or viruses. They do not decode attachments, and they do not unzip archives. So if you need more sophisticated content analysis, check the documents referenced below in the README FILES section. Don't come for me, I'm just the messenger π
π¦ FILTERS WHILE RECEIVING MAIL π¦
Postfix implements the following four built-in content inspection classes while receiving mail:
header_checks(default: empty) β These get applied to initial message headers (except for the headers that are processed withmime_header_checks).mime_header_checks(default:$header_checks) β These get applied to MIME related message headers only.
This feature is available in Postfix 2.0 and later.
nested_header_checks(default:$header_checks) β These get applied to message headers of attached email messages (except for the headers that are processed withmime_header_checks).
This feature is available in Postfix 2.0 and later.
body_checksβ These get applied to all other content, including multi-part message boundaries.
With Postfix versions before 2.0, all content after the initial message headers is treated as body content.
π FILTERS AFTER RECEIVING MAIL π
Postfix supports a subset of the built-in content inspection classes after the message is received:
milter_header_checks(default: empty) β These get applied to headers that are added with Milter applications.
This feature is available in Postfix 2.7 and later.
π FILTERS WHILE DELIVERING MAIL π
Postfix supports all four content inspection classes while delivering mail via SMTP.
smtp_header_checks(default: empty)smtp_mime_header_checks(default: empty)smtp_nested_header_checks(default: empty)smtp_body_checks(default: empty) β These features are available in Postfix 2.5 and later.
β COMPATIBILITY β
With Postfix version 2.2 and earlier, specify "postmap -fq" to query a table that contains case sensitive patterns. By default, regexp: and pcre: patterns are case insensitive. iykyk π
π TABLE FORMAT π
This document assumes that header and body_checks rules are specified in the form of Postfix regular expression lookup tables. Usually the best performance is obtained with pcre (Perl Compatible Regular Expression) tables. The regexp (POSIX regular expressions) tables are usually slower, but more widely available. Use the command "postconf -m" to find out what lookup table types your Postfix system supports π
The general format of Postfix regular expression tables is given below. For a discussion of specific pattern or flags syntax, see pcre_table(5) or regexp_table(5), respectively.
/pattern/flags actionβ When/pattern/matches the input string, execute the corresponding action. See below for a list of possible actions.!/pattern/flags actionβ When/pattern/does not match the input string, execute the corresponding action.if /pattern/flagsendifβ If the input string matches/pattern/, then match that input string against the patterns betweenifandendif. Theif..endifcan nest.
Note: do not prepend whitespace to patterns inside if..endif. π¨
if !/pattern/flagsendifβ If the input string does not match/pattern/, then match that input string against the patterns betweenifandendif. Theif..endifcan nest.- blank lines and comments β Empty lines and whitespace-only lines are ignored, as are lines whose first non-whitespace character is a
#. - multi-line text β A pattern/action line starts with non-whitespace text. A line that starts with whitespace continues a logical line.
π TABLE SEARCH ORDER π
For each line of message input, the patterns are applied in the order as specified in the table. When a pattern is found that matches the input line, the corresponding action is executed and then the next input line is inspected. Fr fr, order matters π
π§ TEXT SUBSTITUTION π§
Substitution of substrings from the matched expression into the action string is possible using the conventional Perl syntax ($1, $2, etc.). The macros in the result string may need to be written as ${n} or $(n) if they aren't followed by whitespace.
Note: since negated patterns (those preceded by !) return a result when the expression does not match, substitutions are not available for negated patterns. Sorry bestie π
β¨ ACTIONS β¨
okay so action names are case insensitive, bestie β they literally do not care about caps. They're shown in UPPER CASE here for consistency with other Postfix documentation, no cap. π
BCC user@domainβ Add the specified address as a BCC recipient, and inspect the next input line. The address must have a local part and a domain part. The number of BCC addresses that can be added is limited only by the amount of available storage space. πΎ- Note 1: the BCC address is added as if it was specified with
NOTIFY=NONE. The sender will not be notified when the BCC address is undeliverable, as long as all down-stream software implementsRFC 3461. - Note 2: this ignores duplicate addresses (with the same delivery status notification options). π
- This feature is available in Postfix 3.0 and later. β¨
- This feature is not supported with
smtpheader/body checks. π«
- Note 1: the BCC address is added as if it was specified with
DISCARD optional text...β Claim successful delivery and silently discard the message. Do not inspect the remainder of the input message. Log the optional text if specified, otherwise log a generic message. π- Note: this action disables further
headerorbody_checksinspection of the current message and affects all recipients. To discard only one recipient without discarding the entire message, use thetransport(5)table to direct mail to thediscard(8)service. - This feature is available in Postfix 2.0 and later.
- This feature is not supported with
smtpheader/body checks.
- Note: this action disables further
DUNNOβ Pretend that the input line did not match any pattern, and inspect the next input line. This action can be used to shorten the table search. π- For backwards compatibility reasons, Postfix also accepts
OKbut it is (and always has been) treated asDUNNO. - This feature is available in Postfix 2.1 and later.
- For backwards compatibility reasons, Postfix also accepts
FILTER transport:destinationβ Override thecontent_filterparameter setting, and inspect the next input line. After the message is queued, send the entire message through the specified external content filter. The transport name specifies the first field of a mail delivery agent definition inmaster.cf; the syntax of the next-hop destination is described in the manual page of the corresponding delivery agent. More information about external content filters is in the PostfixFILTER_READMEfile. π- Note 1: do not use
$numberregular expression substitutions for transport or destination unless you know that the information has a trusted origin. - Note 2: this action overrides the
main.cfcontent_filtersetting, and affects all recipients of the message. In the case that multipleFILTERactions fire, only the last one is executed. - Note 3: the purpose of the
FILTERcommand is to override message routing. To override the recipient's transport but not the next-hop destination, specify an empty filter destination (Postfix 2.7 and later), or specify atransport:destinationthat delivers through a different Postfix instance (Postfix 2.6 and earlier). Other options are using the recipient-dependenttransport_mapsor the sender-dependentsender_dependent_default_transport_mapsfeatures. - This feature is available in Postfix 2.0 and later.
- This feature is not supported with
smtpheader/body checks.
- Note 1: do not use
HOLD optional text...β Arrange for the message to be placed on the hold queue, and inspect the next input line. The message remains on hold until someone either deletes it or releases it for delivery. Log the optional text if specified, otherwise log a generic message. β- Mail that is placed on hold can be examined with the
postcat(1)command, and can be destroyed or released with thepostsuper(1)command. - Note: use
postsuper -rto release mail that was kept on hold for a significant fraction of$maximal_queue_lifetimeor$bounce_queue_lifetime, or longer. Usepostsuper -Honly for mail that will not expire within a few delivery attempts. - Note: this action affects all recipients of the message.
- This feature is available in Postfix 2.0 and later.
- This feature is not supported with
smtpheader/body checks.
- Mail that is placed on hold can be examined with the
IGNOREβ Delete the current line from the input, and inspect the next input line. SeeSTRIPfor an alternative that logs the action. π€«INFO optional text...β Log an"info:"record with the optional text... (or log a generic text), and inspect the next input line. This action is useful for routine logging or for debugging. π- This feature is available in Postfix 2.8 and later.
PASS optional text...β Log a"pass:"record with the optional text... (or log a generic text), and turn off header, body, and Milter inspection for the remainder of this message. ποΈ- Note: this feature relies on trust in information that is easy to forge.
- This feature is available in Postfix 3.2 and later.
- This feature is not supported with
smtpheader/body checks.
PREPEND text...β Prepend one line with the specified text, and inspect the next input line. β¨- Notes:
- The prepended text is output on a separate line, immediately before the input that triggered the
PREPENDaction. - The prepended text is not considered part of the input stream: it is not subject to header/body checks or address rewriting, and it does not affect the way that Postfix adds missing message headers.
- When prepending text before a message header line, the prepended text must begin with a valid message header label.
- This action cannot be used to prepend multi-line text.
- The prepended text is output on a separate line, immediately before the input that triggered the
- This feature is available in Postfix 2.1 and later.
- This feature is not supported with
milter_header_checks.
- Notes:
REDIRECT user@domainβ Write a message redirection request to the queue file, and inspect the next input line. After the message is queued, it will be sent to the specified address instead of the intended recipient(s). π―- Note 1: this action overrides the
FILTERaction, and affects all recipients of the message. If multipleREDIRECTactions fire, only the last one is executed. - Note 2: a
REDIRECTaddress is subject to canonicalization (add missing domain) but NOT subject tocanonical,masquerade,bcc, orvirtualalias mapping. - This feature is available in Postfix 2.1 and later.
- This feature is not supported with
smtpheader/body checks.
- Note 1: this action overrides the
REPLACE text...β Replace the current line with the specified text, and inspect the next input line. π- This feature is available in Postfix 2.2 and later. The description below applies to Postfix 2.2.2 and later.
- Notes:
- When replacing a message header line, the replacement text must begin with a valid header label.
- The replaced text remains part of the input stream. Unlike the result from the
PREPENDaction, a replaced message header may be subject to address rewriting and may affect the way that Postfix adds missing message headers.
REJECT optional text...β Reject the entire message. Do not inspect the remainder of the input message. Reply with optional text... when the optional text is specified, otherwise reply with a generic error message. β- Note: this action disables further header or
body_checksinspection of the current message and affects all recipients. - Postfix version 2.3 and later support enhanced status codes. When no code is specified at the beginning of optional text..., Postfix inserts a default enhanced status code of
"5.7.1". - This feature is not supported with
smtpheader/body checks.
- Note: this action disables further header or
STRIP optional text...β Log a"strip:"record with the optional text... (or log a generic text), delete the input line from the input, and inspect the next input line. SeeIGNOREfor a silent alternative. π§Ή- This feature is available in Postfix 3.2 and later.
WARN optional text...β Log a"warning:"record with the optional text... (or log a generic text), and inspect the next input line. This action is useful for debugging and for testing a pattern before applying more drastic actions. β οΈ
π BUGS π
Empty lines never match, because some map types mis-behave when given a zero-length search string. This limitation may be removed for regular expression tables in a future release. π
Many people overlook the main limitations of header and body_checks rules.
- These rules operate on one logical message header or one body line at a time. A decision made for one line is not carried over to the next line.
- If text in the message body is encoded (
RFC 2045) then the rules need to be specified for the encoded form. - Likewise, when message headers are encoded (
RFC 2047) then the rules need to be specified for the encoded form.
Message headers added by the cleanup(8) daemon itself are excluded from inspection. Examples of such message headers are From:, To:, Message-ID:, Date:.
Message headers deleted by the cleanup(8) daemon will be examined before they are deleted. Examples are: Bcc:, Content-Length:, Return-Path:.
βοΈ CONFIGURATION PARAMETERS βοΈ
body_checks(empty) β Optional lookup tables for content inspection as specified in thebody_checks(5)manual page.body_checks_size_limit(51200) β How much text in a message body segment (or attachment, if you prefer to use that term) is subjected tobody_checksinspection.header_checks(empty) β Optional lookup tables for content inspection of primary non-MIME message headers, as specified in theheader_checks(5)manual page.mime_header_checks($header_checks) β Optional lookup tables for content inspection of MIME related message headers, as described in theheader_checks(5)manual page.nested_header_checks($header_checks) β Optional lookup tables for content inspection of non-MIME message headers in attached messages, as described in theheader_checks(5)manual page.disable_mime_input_processing(no) β Turn off MIME processing while receiving mail.
β¨ EXAMPLES β¨
okay bestie, real-world glow-up time. Here's how you actually use this stuff. π
Header pattern to block attachments with bad file name extensions. For convenience, the PCRE /x flag is specified, so that there is no need to collapse the pattern into a single line of text. The purpose of the [[:xdigit:]] sub-expressions is to recognize Windows CLSID strings.
/etc/postfix/main.cf:
header_checks = pcre:/etc/postfix/header_checks.pcre
/etc/postfix/header_checks.pcre:
/^Content-(Disposition|Type).*name\s*=\s*"?([^;]*(\.|=2E)(
ade|adp|asp|bas|bat|chm|cmd|com|cpl|crt|dll|exe|
hlp|ht[at]|
inf|ins|isp|jse?|lnk|md[betw]|ms[cipt]|nws|
\{[[:xdigit:]]{8}(?:-[[:xdigit:]]{4}){3}-[[:xdigit:]]{12}\}|
ops|pcd|pif|prf|reg|sc[frt]|sh[bsm]|swf|
vb[esx]?|vxd|ws[cfh]))(\?=)?"?\s*(;|$)/x
REJECT Attachment name "$2" may not end with ".$4"
Body pattern to stop a specific HTML browser vulnerability exploit.
/etc/postfix/main.cf:
body_checks = regexp:/etc/postfix/body_checks
/etc/postfix/body_checks:
/^<iframe src=(3D)?cid:.* height=(3D)?0 width=(3D)?0>$/
REJECT IFRAME vulnerability exploit
π SEE ALSO π
if u wanna go deeper, these are the besties to check out π
cleanup(8), canonicalize and enqueue Postfix messagepcre_table(5), format of PCRE lookup tablesregexp_table(5), format of POSIX regular expression tablespostconf(1), Postfix configuration utilitypostmap(1), Postfix lookup table managementpostsuper(1), Postfix janitorpostcat(1), show Postfix queue file contentsRFC 2045, base64 and quoted-printable encoding rulesRFC 2047, message header encoding for non-ASCII text
π README FILES π
Use "postconf readme_directory" or "postconf html_directory" to locate this information.
DATABASE_README, Postfix lookup table overviewCONTENT_INSPECTION_README, Postfix content inspection overviewBUILTIN_FILTER_README, Postfix built-in content inspectionBACKSCATTER_README, blocking returned forged mail
π LICENSE π
The Secure Mailer license must be distributed with this software.
π AUTHOR(S) π
Wietse Venema IBM T.J. Watson Research P.O. Box 704 Yorktown Heights, NY 10598, USA
Wietse Venema Google, Inc. 111 8th Avenue New York, NY 10011, USA
catch u at the bottom of the manpage, where it says HEADER_CHECKS(5) and the source/version + date are just vibing π periodt.
π¦ where this page comes from
- alpine 3.22: postfix-doc 3.10.13-r0 Β· IPL-1.0 EPL-2.0
- alpine 3.23: postfix-doc 3.10.13-r0 Β· IPL-1.0 EPL-2.0
- alpine 3.24: postfix-doc 3.11.7-r0 Β· IPL-1.0 EPL-2.0
- arch rolling: postfix 3.11.7-1 Β· EPL-2.0 OR IPL-1.0 AND BSD-4-Clause-UC
- debian trixie: postfix 3.10.13-0+deb13u1
- fedora 43: postfix 2:3.10.14-1.fc43 Β· (IPL-1.0 OR EPL-2.0) AND GPL-2.0-or-later AND BSD-4-Clause-UC
- fedora 43: postfix 2:3.10.3-3.fc43 Β· (IPL-1.0 OR EPL-2.0) AND GPL-2.0-or-later AND BSD-4-Clause-UC
- fedora 44: postfix 2:3.10.14-1.fc44 Β· (IPL-1.0 OR EPL-2.0) AND GPL-2.0-or-later AND BSD-4-Clause-UC
- fedora 44: postfix 2:3.10.7-2.fc44 Β· (IPL-1.0 OR EPL-2.0) AND GPL-2.0-or-later AND BSD-4-Clause-UC
- nixos 26.05: postfix 3.11.7
- nixpkgs unstable: postfix 3.11.7
- opensuse-leap 16.0: postfix 3.10.2-160000.3.1 Β· EPL-2.0 OR IPL-1.0
- opensuse-leap 16.0: postfix 3.10.2-160000.3.1 Β· EPL-2.0 OR IPL-1.0
- opensuse-leap 16.0: postfix 3.10.2-160000.3.1 Β· EPL-2.0 OR IPL-1.0
- opensuse-leap 16.0: postfix 3.10.2-160000.3.1 Β· EPL-2.0 OR IPL-1.0
- opensuse-leap 16.0: postfix-bdb 3.10.2-160000.3.1 Β· EPL-2.0 OR IPL-1.0
- opensuse-leap 16.0: postfix-bdb 3.10.2-160000.3.1 Β· EPL-2.0 OR IPL-1.0
- opensuse-leap 16.0: postfix-bdb 3.10.2-160000.3.1 Β· EPL-2.0 OR IPL-1.0
- opensuse-leap 16.0: postfix-bdb 3.10.2-160000.3.1 Β· EPL-2.0 OR IPL-1.0
- ubuntu questing: postfix 3.10.2-1ubuntu2
- ubuntu questing: postfix 3.10.2-1ubuntu2.1
- ubuntu resolute: postfix 3.10.6-4ubuntu2
- ubuntu resolute: postfix 3.10.6-4ubuntu2.1
- ubuntu resolute: postfix 3.10.6-4ubuntu2.2
- ubuntu stonking: postfix 3.11.7-1ubuntu2
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms