9 Postfix built-in content inspection
14 \fBheader_checks = pcre:/etc/postfix/header_checks\fR
15 \fBmime_header_checks = pcre:/etc/postfix/mime_header_checks\fR
16 \fBnested_header_checks = pcre:/etc/postfix/nested_header_checks\fR
17 \fBbody_checks = pcre:/etc/postfix/body_checks\fR
19 \fBpostmap -q "\fIstring\fB" pcre:/etc/postfix/\fIfilename\fR
20 \fBpostmap -q - pcre:/etc/postfix/\fIfilename\fR <\fIinputfile\fR
25 This document describes access control on the content of
26 message headers and message body lines; it is implemented
27 by the Postfix \fBcleanup\fR(8) server before mail is queued.
28 See \fBaccess\fR(5) for access control on remote SMTP client
31 Each message header or message body line is compared against
33 When a match is found the corresponding action is executed, and
34 the matching process is repeated for the next message header or
37 For examples, see the EXAMPLES section at the end of this
40 Postfix header or body_checks are designed to stop a flood of mail
41 from worms or viruses; they do not decode attachments, and they do
42 not unzip archives. See the documents referenced below in the README
43 FILES section if you need more sophisticated content analysis.
45 Postfix supports four built-in content inspection classes:
46 .IP \fBheader_checks\fR
47 These are applied to initial message headers (except for
48 the headers that are processed with \fBmime_header_checks\fR).
49 .IP "\fBmime_header_checks\fR (default: \fB$header_checks\fR)"
50 These are applied to MIME related message headers only.
52 This feature is available in Postfix 2.0 and later.
53 .IP "\fBnested_header_checks\fR (default: \fB$header_checks\fR)"
54 These are applied to message headers of attached email
55 messages (except for the headers that are processed with
56 \fBmime_header_checks\fR).
58 This feature is available in Postfix 2.0 and later.
60 These are applied to all other content, including multi-part
63 With Postfix versions before 2.0, all content after the initial
64 message headers is treated as body content.
66 Note: message headers are examined one logical header at a time,
67 even when a message header spans multiple lines. Body lines are
68 always examined one line at a time.
74 With Postfix version 2.2 and earlier specify "\fBpostmap
75 -fq\fR" to query a table that contains case sensitive
76 patterns. By default, regexp: and pcre: patterns are case
83 This document assumes that header and body_checks rules are specified
84 in the form of Postfix regular expression lookup tables. Usually the
85 best performance is obtained with \fBpcre\fR (Perl Compatible Regular
86 Expression) tables, but the slower \fBregexp\fR (POSIX regular
87 expressions) support is more widely available.
88 Use the command "\fBpostconf -m\fR" to find out what lookup table
89 types your Postfix system supports.
91 The general format of Postfix regular expression tables is
93 For a discussion of specific pattern or flags syntax,
94 see \fBpcre_table\fR(5) or \fBregexp_table\fR(5), respectively.
95 .IP "\fB/\fIpattern\fB/\fIflags action\fR"
96 When /\fIpattern\fR/ matches the input string, execute
97 the corresponding \fIaction\fR. See below for a list
99 .IP "\fB!/\fIpattern\fB/\fIflags action\fR"
100 When /\fIpattern\fR/ does \fBnot\fR match the input string,
101 execute the corresponding \fIaction\fR.
102 .IP "\fBif /\fIpattern\fB/\fIflags\fR"
104 Match the input string against the patterns between \fBif\fR
105 and \fBendif\fR, if and only if the same input string also
106 matches /\fIpattern\fR/. The \fBif\fR..\fBendif\fR can nest.
108 Note: do not prepend whitespace to patterns inside
109 \fBif\fR..\fBendif\fR.
110 .IP "\fBif !/\fIpattern\fB/\fIflags\fR"
112 Match the input string against the patterns between \fBif\fR
113 and \fBendif\fR, if and only if the same input string does
114 \fBnot\fR match /\fIpattern\fR/. The \fBif\fR..\fBendif\fR
116 .IP "blank lines and comments"
117 Empty lines and whitespace-only lines are ignored, as
118 are lines whose first non-whitespace character is a `#'.
119 .IP "multi-line text"
120 A pattern/action line starts with non-whitespace text. A line that
121 starts with whitespace continues a logical line.
122 .SH "TABLE SEARCH ORDER"
127 For each line of message input, the patterns are applied in the
128 order as specified in the table. When a pattern is found that matches
129 the input line, the corresponding action is executed and then the
130 next input line is inspected.
131 .SH "TEXT SUBSTITUTION"
136 Substitution of substrings from the matched expression into the
138 string is possible using the conventional Perl syntax
139 (\fB$1\fR, \fB$2\fR, etc.).
140 The macros in the result string may need to be written as \fB${n}\fR
141 or \fB$(n)\fR if they aren't followed by whitespace.
143 Note: since negated patterns (those preceded by \fB!\fR) return a
144 result when the expression does not match, substitutions are not
145 available for negated patterns.
151 Action names are case insensitive. They are shown in upper case
152 for consistency with other Postfix documentation.
153 .IP "\fBDISCARD \fIoptional text...\fR"
154 Claim successful delivery and silently discard the message.
155 Log the optional text if specified, otherwise log a generic
158 Note: this action disables further header or body_checks inspection
159 of the current message and affects all recipients.
160 To discard only one recipient without discarding the entire message,
161 use the transport(5) table to direct mail to the discard(8) service.
163 This feature is available in Postfix 2.0 and later.
165 Pretend that the input line did not match any pattern, and inspect the
166 next input line. This action can be used to shorten the table search.
168 For backwards compatibility reasons, Postfix also accepts
169 \fBOK\fR but it is (and always has been) treated as \fBDUNNO\fR.
171 This feature is available in Postfix 2.1 and later.
172 .IP "\fBFILTER \fItransport:destination\fR"
173 Write a content filter request to the queue file, and
174 inspect the next input line.
175 After the complete message is received it will be sent through
176 the specified external content filter. More information about
177 external content filters is in the Postfix FILTER_README file.
179 Note: this action overrides the \fBcontent_filter\fR setting,
180 and affects all recipients of the message. In the case that multiple
181 \fBFILTER\fR actions fire, only the last one is executed.
183 This feature is available in Postfix 2.0 and later.
184 .IP "\fBHOLD \fIoptional text...\fR"
185 Arrange for the message to be placed on the \fBhold\fR queue,
186 and inspect the next input line. The message remains on \fBhold\fR
187 until someone either deletes it or releases it for delivery.
188 Log the optional text if specified, otherwise log a generic
191 Mail that is placed on hold can be examined with the
192 \fBpostcat\fR(1) command, and can be destroyed or released with
193 the \fBpostsuper\fR(1) command.
195 Note: use "\fBpostsuper -r\fR" to release mail that was kept on
196 hold for a significant fraction of \fB$maximal_queue_lifetime\fR
197 or \fB$bounce_queue_lifetime\fR, or longer. Use "\fBpostsuper -H\fR"
198 only for mail that will not expire within a few delivery attempts.
200 Note: this action affects all recipients of the message.
202 This feature is available in Postfix 2.0 and later.
204 Delete the current line from the input, and inspect
206 .IP "\fBPREPEND \fItext...\fR"
207 Prepend one line with the specified text, and inspect the next
213 The prepended text is output on a separate line, immediately
214 before the input that triggered the \fBPREPEND\fR action.
216 The prepended text is not considered part of the input
217 stream: it is not subject to header/body checks or address
218 rewriting, and it does not affect the way that Postfix adds
219 missing message headers.
221 When prepending text before a message header line, the prepended
222 text must begin with a valid message header label.
224 This action cannot be used to prepend multi-line text.
227 This feature is available in Postfix 2.1 and later.
228 .IP "\fBREDIRECT \fIuser@domain\fR"
229 Write a message redirection request to the queue file, and
230 inspect the next input line. After the message is queued,
231 it will be sent to the specified address instead of the
232 intended recipient(s).
234 Note: this action overrides the \fBFILTER\fR action, and affects
235 all recipients of the message. If multiple \fBREDIRECT\fR actions
236 fire, only the last one is executed.
238 This feature is available in Postfix 2.1 and later.
239 .IP "\fBREPLACE \fItext...\fR"
240 Replace the current line with the specified text, and inspect the next
243 This feature is available in Postfix 2.2 and later. The
244 description below applies to Postfix 2.2.2 and later.
249 When replacing a message header line, the replacement text
250 must begin with a valid header label.
252 The replaced text remains part of the input stream. Unlike
253 the result from the \fBPREPEND\fR action, a replaced message
254 header may be subject to address rewriting and may affect
255 the way that Postfix adds missing message headers.
257 .IP "\fBREJECT \fIoptional text...\fR
258 Reject the entire message. Reply with \fIoptional text...\fR when
259 the optional text is specified, otherwise reply with a generic error
262 Note: this action disables further header or body_checks inspection
263 of the current message and affects all recipients.
265 Postfix version 2.3 and later support enhanced status codes.
266 When no code is specified at the beginning of \fIoptional
267 text...\fR, Postfix inserts a default enhanced status code of
269 .IP "\fBWARN \fIoptional text...\fR
270 Log a warning with the \fIoptional text...\fR (or log a
271 generic message), and inspect the next input line. This
272 action is useful for debugging and for testing a pattern
273 before applying more drastic actions.
277 Empty lines never match, because some map types mis-behave
278 when given a zero-length search string. This limitation may
279 be removed for regular expression tables in a future release.
281 Many people overlook the main limitations of header and body_checks
284 These rules operate on one logical message header or one body
285 line at a time. A decision made for one line is not carried over
288 If text in the message body is encoded
289 (RFC 2045) then the rules need to be specified for the encoded
292 Likewise, when message headers are encoded (RFC
293 2047) then the rules need to be specified for the encoded
296 Message headers added by the \fBcleanup\fR(8) daemon itself
297 are excluded from inspection. Examples of such message headers
298 are \fBFrom:\fR, \fBTo:\fR, \fBMessage-ID:\fR, \fBDate:\fR.
300 Message headers deleted by the \fBcleanup\fR(8) daemon will
301 be examined before they are deleted. Examples are: \fBBcc:\fr,
302 \fBContent-Length:\fR, \fBReturn-Path:\fR.
303 .SH "CONFIGURATION PARAMETERS"
308 .IP \fBbody_checks\fR
309 Lookup tables with content filter rules for message body lines.
310 These filters see one physical line at a time, in chunks of
311 at most \fB$line_length_limit\fR bytes.
312 .IP \fBbody_checks_size_limit\fP
313 The amount of content per message body segment (attachment) that is
314 subjected to \fB$body_checks\fR filtering.
315 .IP \fBheader_checks\fR
316 .IP "\fBmime_header_checks\fR (default: \fB$header_checks\fR)"
317 .IP "\fBnested_header_checks\fR (default: \fB$header_checks\fR)"
318 Lookup tables with content filter rules for message header lines:
319 respectively, these are applied to the initial message headers
320 (not including MIME headers), to the MIME headers anywhere in
321 the message, and to the initial headers of attached messages.
323 Note: these filters see one logical message header at a time, even
324 when a message header spans multiple lines. Message headers that
325 are longer than \fB$header_size_limit\fR characters are truncated.
326 .IP \fBdisable_mime_input_processing\fR
327 While receiving mail, give no special treatment to MIME related
328 message headers; all text after the initial message headers is
329 considered to be part of the message body. This means that
330 \fBheader_checks\fR is applied to all the initial message headers,
331 and that \fBbody_checks\fR is applied to the remainder of the
334 Note: when used in this manner, \fBbody_checks\fR will process
335 a multi-line message header one line at a time.
341 Header pattern to block attachments with bad file name
342 extensions. For convenience, the PCRE /x flag is specified,
343 so that there is no need to collapse the pattern into a
344 single line of text. The purpose of the [[:xdigit:]]
345 sub-expressions is to recognize Windows CLSID strings.
349 /etc/postfix/main.cf:
350 header_checks = pcre:/etc/postfix/header_checks.pcre
352 /etc/postfix/header_checks.pcre:
353 /^Content-(Disposition|Type).*name\es*=\es*"?(.*(\e.|=2E)(
354 ade|adp|asp|bas|bat|chm|cmd|com|cpl|crt|dll|exe|
356 inf|ins|isp|jse?|lnk|md[betw]|ms[cipt]|nws|
357 \e{[[:xdigit:]]{8}(?:-[[:xdigit:]]{4}){3}-[[:xdigit:]]{12}\e}|
358 ops|pcd|pif|prf|reg|sc[frt]|sh[bsm]|swf|
359 vb[esx]?|vxd|ws[cfh]))(\e?=)?"?\es*(;|$)/x
360 REJECT Attachment name "$2" may not end with ".$4"
364 Body pattern to stop a specific HTML browser vulnerability exploit.
368 /etc/postfix/main.cf:
369 body_checks = regexp:/etc/postfix/body_checks
371 /etc/postfix/body_checks:
372 /^<iframe src=(3D)?cid:.* height=(3D)?0 width=(3D)?0>$/
373 REJECT IFRAME vulnerability exploit
377 cleanup(8), canonicalize and enqueue Postfix message
378 pcre_table(5), format of PCRE lookup tables
379 regexp_table(5), format of POSIX regular expression tables
380 postconf(1), Postfix configuration utility
381 postmap(1), Postfix lookup table management
382 postsuper(1), Postfix janitor
383 postcat(1), show Postfix queue file contents
384 RFC 2045, base64 and quoted-printable encoding rules
385 RFC 2047, message header encoding for non-ASCII text
391 Use "\fBpostconf readme_directory\fR" or
392 "\fBpostconf html_directory\fR" to locate this information.
395 DATABASE_README, Postfix lookup table overview
396 CONTENT_INSPECTION_README, Postfix content inspection overview
397 BUILTIN_FILTER_README, Postfix built-in content inspection
398 BACKSCATTER_README, blocking returned forged mail
404 The Secure Mailer license must be distributed with this software.
409 IBM T.J. Watson Research
411 Yorktown Heights, NY 10598, USA