1HEADER_CHECKS(5) File Formats Manual HEADER_CHECKS(5)
2
3
4
6 header_checks - Postfix built-in content inspection
7
9 header_checks = pcre:/etc/postfix/header_checks
10 mime_header_checks = pcre:/etc/postfix/mime_header_checks
11 nested_header_checks = pcre:/etc/postfix/nested_header_checks
12 body_checks = pcre:/etc/postfix/body_checks
13
14 milter_header_checks = pcre:/etc/postfix/milter_header_checks
15
16 smtp_header_checks = pcre:/etc/postfix/smtp_header_checks
17 smtp_mime_header_checks = pcre:/etc/postfix/smtp_mime_header_checks
18 smtp_nested_header_checks = pcre:/etc/postfix/smtp_nested_header_checks
19 smtp_body_checks = pcre:/etc/postfix/smtp_body_checks
20
21 postmap -q "string" pcre:/etc/postfix/filename
22 postmap -q - pcre:/etc/postfix/filename <inputfile
23
25 This document describes access control on the content of message head‐
26 ers and message body lines; it is implemented by the Postfix cleanup(8)
27 server before mail is queued. See access(5) for access control on
28 remote SMTP client information.
29
30 Each message header or message body line is compared against a list of
31 patterns. When a match is found the corresponding action is executed,
32 and the matching process is repeated for the next message header or
33 message body line.
34
35 Note: message headers are examined one logical header at a time, even
36 when a message header spans multiple lines. Body lines are always exam‐
37 ined one line at a time.
38
39 For examples, see the EXAMPLES section at the end of this manual page.
40
41 Postfix header or body_checks are designed to stop a flood of mail from
42 worms or viruses; they do not decode attachments, and they do not unzip
43 archives. See the documents referenced below in the README FILES sec‐
44 tion if you need more sophisticated content analysis.
45
47 Postfix implements the following four built-in content inspection
48 classes while receiving mail:
49
50 header_checks (default: empty)
51 These are applied to initial message headers (except for the
52 headers that are processed with mime_header_checks).
53
54 mime_header_checks (default: $header_checks)
55 These are applied to MIME related message headers only.
56
57 This feature is available in Postfix 2.0 and later.
58
59 nested_header_checks (default: $header_checks)
60 These are applied to message headers of attached email messages
61 (except for the headers that are processed with
62 mime_header_checks).
63
64 This feature is available in Postfix 2.0 and later.
65
66 body_checks
67 These are applied to all other content, including multi-part
68 message boundaries.
69
70 With Postfix versions before 2.0, all content after the initial
71 message headers is treated as body content.
72
74 Postfix supports a subset of the built-in content inspection classes
75 after the message is received:
76
77 milter_header_checks (default: empty)
78 These are applied to headers that are added with Milter applica‐
79 tions.
80
81 This feature is available in Postfix 2.7 and later.
82
84 Postfix supports all four content inspection classes while delivering
85 mail via SMTP.
86
87 smtp_header_checks (default: empty)
88
89 smtp_mime_header_checks (default: empty)
90
91 smtp_nested_header_checks (default: empty)
92
93 smtp_body_checks (default: empty)
94 These features are available in Postfix 2.5 and later.
95
97 With Postfix version 2.2 and earlier specify "postmap -fq" to query a
98 table that contains case sensitive patterns. By default, regexp: and
99 pcre: patterns are case insensitive.
100
102 This document assumes that header and body_checks rules are specified
103 in the form of Postfix regular expression lookup tables. Usually the
104 best performance is obtained with pcre (Perl Compatible Regular Expres‐
105 sion) tables. The regexp (POSIX regular expressions) tables are usually
106 slower, but more widely available. Use the command "postconf -m" to
107 find out what lookup table types your Postfix system supports.
108
109 The general format of Postfix regular expression tables is given below.
110 For a discussion of specific pattern or flags syntax, see pcre_table(5)
111 or regexp_table(5), respectively.
112
113 /pattern/flags action
114 When /pattern/ matches the input string, execute the correspond‐
115 ing action. See below for a list of possible actions.
116
117 !/pattern/flags action
118 When /pattern/ does not match the input string, execute the cor‐
119 responding action.
120
121 if /pattern/flags
122
123 endif If the input string matches /pattern/, then match that input
124 string against the patterns between if and endif. The if..endif
125 can nest.
126
127 Note: do not prepend whitespace to patterns inside if..endif.
128
129 if !/pattern/flags
130
131 endif If the input string does not match /pattern/, then match that
132 input string against the patterns between if and endif. The
133 if..endif can nest.
134
135 blank lines and comments
136 Empty lines and whitespace-only lines are ignored, as are lines
137 whose first non-whitespace character is a `#'.
138
139 multi-line text
140 A pattern/action line starts with non-whitespace text. A line
141 that starts with whitespace continues a logical line.
142
144 For each line of message input, the patterns are applied in the order
145 as specified in the table. When a pattern is found that matches the
146 input line, the corresponding action is executed and then the next
147 input line is inspected.
148
150 Substitution of substrings from the matched expression into the action
151 string is possible using the conventional Perl syntax ($1, $2, etc.).
152 The macros in the result string may need to be written as ${n} or $(n)
153 if they aren't followed by whitespace.
154
155 Note: since negated patterns (those preceded by !) return a result when
156 the expression does not match, substitutions are not available for
157 negated patterns.
158
160 Action names are case insensitive. They are shown in upper case for
161 consistency with other Postfix documentation.
162
163 BCC user@domain
164 Add the specified address as a BCC recipient, and inspect the
165 next input line. The address must have a local part and domain
166 part. The number of BCC addresses that can be added is limited
167 only by the amount of available storage space.
168
169 Note 1: the BCC address is added as if it was specified with
170 NOTIFY=NONE. The sender will not be notified when the BCC
171 address is undeliverable, as long as all down-stream software
172 implements RFC 3461.
173
174 Note 2: this ignores duplicate addresses (with the same delivery
175 status notification options).
176
177 This feature is available in Postfix 3.0 and later.
178
179 This feature is not supported with smtp header/body checks.
180
181 DISCARD optional text...
182 Claim successful delivery and silently discard the message. Do
183 not inspect the remainder of the input message. Log the
184 optional text if specified, otherwise log a generic message.
185
186 Note: this action disables further header or body_checks inspec‐
187 tion of the current message and affects all recipients. To dis‐
188 card only one recipient without discarding the entire message,
189 use the transport(5) table to direct mail to the discard(8) ser‐
190 vice.
191
192 This feature is available in Postfix 2.0 and later.
193
194 This feature is not supported with smtp header/body checks.
195
196 DUNNO Pretend that the input line did not match any pattern, and
197 inspect the next input line. This action can be used to shorten
198 the table search.
199
200 For backwards compatibility reasons, Postfix also accepts OK but
201 it is (and always has been) treated as DUNNO.
202
203 This feature is available in Postfix 2.1 and later.
204
205 FILTER transport:destination
206 Override the content_filter parameter setting, and inspect the
207 next input line. After the message is queued, send the entire
208 message through the specified external content filter. The
209 transport name specifies the first field of a mail delivery
210 agent definition in master.cf; the syntax of the next-hop desti‐
211 nation is described in the manual page of the corresponding
212 delivery agent. More information about external content filters
213 is in the Postfix FILTER_README file.
214
215 Note 1: do not use $number regular expression substitutions for
216 transport or destination unless you know that the information
217 has a trusted origin.
218
219 Note 2: this action overrides the main.cf content_filter set‐
220 ting, and affects all recipients of the message. In the case
221 that multiple FILTER actions fire, only the last one is exe‐
222 cuted.
223
224 Note 3: the purpose of the FILTER command is to override message
225 routing. To override the recipient's transport but not the
226 next-hop destination, specify an empty filter destination (Post‐
227 fix 2.7 and later), or specify a transport:destination that
228 delivers through a different Postfix instance (Postfix 2.6 and
229 earlier). Other options are using the recipient-dependent trans‐
230 port_maps or the sender-dependent sender_dependent_default‐
231 _transport_maps features.
232
233 This feature is available in Postfix 2.0 and later.
234
235 This feature is not supported with smtp header/body checks.
236
237 HOLD optional text...
238 Arrange for the message to be placed on the hold queue, and
239 inspect the next input line. The message remains on hold until
240 someone either deletes it or releases it for delivery. Log the
241 optional text if specified, otherwise log a generic message.
242
243 Mail that is placed on hold can be examined with the postcat(1)
244 command, and can be destroyed or released with the postsuper(1)
245 command.
246
247 Note: use "postsuper -r" to release mail that was kept on hold
248 for a significant fraction of $maximal_queue_lifetime or
249 $bounce_queue_lifetime, or longer. Use "postsuper -H" only for
250 mail that will not expire within a few delivery attempts.
251
252 Note: this action affects all recipients of the message.
253
254 This feature is available in Postfix 2.0 and later.
255
256 This feature is not supported with smtp header/body checks.
257
258 IGNORE Delete the current line from the input, and inspect the next
259 input line. See STRIP for an alternative that logs the action.
260
261 INFO optional text...
262 Log an "info:" record with the optional text... (or log a
263 generic text), and inspect the next input line. This action is
264 useful for routine logging or for debugging.
265
266 This feature is available in Postfix 2.8 and later.
267
268 PASS optional text...
269 Log a "pass:" record with the optional text... (or log a generic
270 text), and turn off header, body, and Milter inspection for the
271 remainder of this message.
272
273 Note: this feature relies on trust in information that is easy
274 to forge.
275
276 This feature is available in Postfix 3.2 and later.
277
278 This feature is not supported with smtp header/body checks.
279
280 PREPEND text...
281 Prepend one line with the specified text, and inspect the next
282 input line.
283
284 Notes:
285
286 · The prepended text is output on a separate line, immedi‐
287 ately before the input that triggered the PREPEND action.
288
289 · The prepended text is not considered part of the input
290 stream: it is not subject to header/body checks or
291 address rewriting, and it does not affect the way that
292 Postfix adds missing message headers.
293
294 · When prepending text before a message header line, the
295 prepended text must begin with a valid message header
296 label.
297
298 · This action cannot be used to prepend multi-line text.
299
300 This feature is available in Postfix 2.1 and later.
301
302 This feature is not supported with milter_header_checks.
303
304 REDIRECT user@domain
305 Write a message redirection request to the queue file, and
306 inspect the next input line. After the message is queued, it
307 will be sent to the specified address instead of the intended
308 recipient(s).
309
310 Note: this action overrides the FILTER action, and affects all
311 recipients of the message. If multiple REDIRECT actions fire,
312 only the last one is executed.
313
314 This feature is available in Postfix 2.1 and later.
315
316 This feature is not supported with smtp header/body checks.
317
318 REPLACE text...
319 Replace the current line with the specified text, and inspect
320 the next input line.
321
322 This feature is available in Postfix 2.2 and later. The descrip‐
323 tion below applies to Postfix 2.2.2 and later.
324
325 Notes:
326
327 · When replacing a message header line, the replacement
328 text must begin with a valid header label.
329
330 · The replaced text remains part of the input stream.
331 Unlike the result from the PREPEND action, a replaced
332 message header may be subject to address rewriting and
333 may affect the way that Postfix adds missing message
334 headers.
335
336 REJECT optional text...
337 Reject the entire message. Do not inspect the remainder of the
338 input message. Reply with optional text... when the optional
339 text is specified, otherwise reply with a generic error message.
340
341 Note: this action disables further header or body_checks inspec‐
342 tion of the current message and affects all recipients.
343
344 Postfix version 2.3 and later support enhanced status codes.
345 When no code is specified at the beginning of optional text...,
346 Postfix inserts a default enhanced status code of "5.7.1".
347
348 This feature is not supported with smtp header/body checks.
349
350 STRIP optional text...
351 Log a "strip:" record with the optional text... (or log a
352 generic text), delete the input line from the input, and inspect
353 the next input line. See IGNORE for a silent alternative.
354
355 This feature is available in Postfix 3.2 and later.
356
357 WARN optional text...
358 Log a "warning:" record with the optional text... (or log a
359 generic text), and inspect the next input line. This action is
360 useful for debugging and for testing a pattern before applying
361 more drastic actions.
362
364 Empty lines never match, because some map types mis-behave when given a
365 zero-length search string. This limitation may be removed for regular
366 expression tables in a future release.
367
368 Many people overlook the main limitations of header and body_checks
369 rules.
370
371 · These rules operate on one logical message header or one body
372 line at a time. A decision made for one line is not carried over
373 to the next line.
374
375 · If text in the message body is encoded (RFC 2045) then the rules
376 need to be specified for the encoded form.
377
378 · Likewise, when message headers are encoded (RFC 2047) then the
379 rules need to be specified for the encoded form.
380
381 Message headers added by the cleanup(8) daemon itself are excluded from
382 inspection. Examples of such message headers are From:, To:, Mes‐
383 sage-ID:, Date:.
384
385 Message headers deleted by the cleanup(8) daemon will be examined
386 before they are deleted. Examples are: Bcc:, Content-Length:,
387 Return-Path:.
388
390 body_checks
391 Lookup tables with content filter rules for message body lines.
392 These filters see one physical line at a time, in chunks of at
393 most $line_length_limit bytes.
394
395 body_checks_size_limit
396 The amount of content per message body segment (attachment) that
397 is subjected to $body_checks filtering.
398
399 header_checks
400
401 mime_header_checks (default: $header_checks)
402
403 nested_header_checks (default: $header_checks)
404 Lookup tables with content filter rules for message header
405 lines: respectively, these are applied to the initial message
406 headers (not including MIME headers), to the MIME headers any‐
407 where in the message, and to the initial headers of attached
408 messages.
409
410 Note: these filters see one logical message header at a time,
411 even when a message header spans multiple lines. Message headers
412 that are longer than $header_size_limit characters are trun‐
413 cated.
414
415 disable_mime_input_processing
416 While receiving mail, give no special treatment to MIME related
417 message headers; all text after the initial message headers is
418 considered to be part of the message body. This means that
419 header_checks is applied to all the initial message headers, and
420 that body_checks is applied to the remainder of the message.
421
422 Note: when used in this manner, body_checks will process a
423 multi-line message header one line at a time.
424
426 Header pattern to block attachments with bad file name extensions. For
427 convenience, the PCRE /x flag is specified, so that there is no need to
428 collapse the pattern into a single line of text. The purpose of the
429 [[:xdigit:]] sub-expressions is to recognize Windows CLSID strings.
430
431 /etc/postfix/main.cf:
432 header_checks = pcre:/etc/postfix/header_checks.pcre
433
434 /etc/postfix/header_checks.pcre:
435 /^Content-(Disposition|Type).*name\s*=\s*"?([^;]*(\.|=2E)(
436 ade|adp|asp|bas|bat|chm|cmd|com|cpl|crt|dll|exe|
437 hlp|ht[at]|
438 inf|ins|isp|jse?|lnk|md[betw]|ms[cipt]|nws|
439 \{[[:xdigit:]]{8}(?:-[[:xdigit:]]{4}){3}-[[:xdigit:]]{12}\}|
440 ops|pcd|pif|prf|reg|sc[frt]|sh[bsm]|swf|
441 vb[esx]?|vxd|ws[cfh]))(\?=)?"?\s*(;|$)/x
442 REJECT Attachment name "$2" may not end with ".$4"
443
444 Body pattern to stop a specific HTML browser vulnerability exploit.
445
446 /etc/postfix/main.cf:
447 body_checks = regexp:/etc/postfix/body_checks
448
449 /etc/postfix/body_checks:
450 /^<iframe src=(3D)?cid:.* height=(3D)?0 width=(3D)?0>$/
451 REJECT IFRAME vulnerability exploit
452
454 cleanup(8), canonicalize and enqueue Postfix message
455 pcre_table(5), format of PCRE lookup tables
456 regexp_table(5), format of POSIX regular expression tables
457 postconf(1), Postfix configuration utility
458 postmap(1), Postfix lookup table management
459 postsuper(1), Postfix janitor
460 postcat(1), show Postfix queue file contents
461 RFC 2045, base64 and quoted-printable encoding rules
462 RFC 2047, message header encoding for non-ASCII text
463
465 Use "postconf readme_directory" or "postconf html_directory" to locate
466 this information.
467 DATABASE_README, Postfix lookup table overview
468 CONTENT_INSPECTION_README, Postfix content inspection overview
469 BUILTIN_FILTER_README, Postfix built-in content inspection
470 BACKSCATTER_README, blocking returned forged mail
471
473 The Secure Mailer license must be distributed with this software.
474
476 Wietse Venema
477 IBM T.J. Watson Research
478 P.O. Box 704
479 Yorktown Heights, NY 10598, USA
480
481 Wietse Venema
482 Google, Inc.
483 111 8th Avenue
484 New York, NY 10011, USA
485
486
487
488 HEADER_CHECKS(5)