1HEADER_CHECKS(5)              File Formats Manual             HEADER_CHECKS(5)
2
3
4

NAME

6       header_checks - Postfix built-in content inspection
7

SYNOPSIS

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

DESCRIPTION

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

FILTERS WHILE RECEIVING MAIL

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

FILTERS AFTER RECEIVING MAIL

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

FILTERS WHILE DELIVERING MAIL

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

COMPATIBILITY

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

TABLE FORMAT

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  Match the input string  against  the  patterns  between  if  and
124              endif,  if  and only if the same input string also matches /pat‐
125              tern/. The if..endif can nest.
126
127              Note: do not prepend whitespace to patterns inside if..endif.
128
129       if !/pattern/flags
130
131       endif  Match the input string  against  the  patterns  between  if  and
132              endif, if and only if the same input string does not match /pat‐
133              tern/. The 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

TABLE SEARCH ORDER

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

TEXT SUBSTITUTION

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

ACTIONS

160       Action names are case insensitive. They are shown  in  upper  case  for
161       consistency with other Postfix documentation.
162
163       DISCARD optional text...
164              Claim successful delivery and silently discard the message.  Log
165              the optional text if specified, otherwise log a generic message.
166
167              Note: this action disables further header or body_checks inspec‐
168              tion of the current message and affects all recipients.  To dis‐
169              card only one recipient without discarding the  entire  message,
170              use the transport(5) table to direct mail to the discard(8) ser‐
171              vice.
172
173              This feature is available in Postfix 2.0 and later.
174
175              This feature is not supported with smtp header/body checks.
176
177       DUNNO  Pretend that the input line  did  not  match  any  pattern,  and
178              inspect  the next input line. This action can be used to shorten
179              the table search.
180
181              For backwards compatibility reasons, Postfix also accepts OK but
182              it is (and always has been) treated as DUNNO.
183
184              This feature is available in Postfix 2.1 and later.
185
186       FILTER transport:destination
187              After the message is queued, send the entire message through the
188              specified external content filter. The transport name  specifies
189              the  first  field  of  a  mail delivery agent definition in mas‐
190              ter.cf; the syntax of the next-hop destination is  described  in
191              the  manual  page  of  the  corresponding  delivery agent.  More
192              information about external content filters  is  in  the  Postfix
193              FILTER_README file.
194
195              Note  1: do not use $number regular expression substitutions for
196              transport or destination unless you know  that  the  information
197              has a trusted origin.
198
199              Note  2:  this  action overrides the main.cf content_filter set‐
200              ting, and affects all recipients of the  message.  In  the  case
201              that  multiple  FILTER  actions  fire, only the last one is exe‐
202              cuted.
203
204              Note 3: the purpose of the FILTER command is to override message
205              routing.   To  override  the  recipient's  transport but not the
206              next-hop destination, specify an empty filter destination (Post‐
207              fix  2.7  and  later),  or  specify a transport:destination that
208              delivers through a different Postfix instance (Postfix  2.6  and
209              earlier). Other options are using the recipient-dependent trans‐
210              port_maps  or  the  sender-dependent   sender_dependent_default‐
211              _transport_maps features.
212
213              This feature is available in Postfix 2.0 and later.
214
215              This feature is not supported with smtp header/body checks.
216
217       HOLD optional text...
218              Arrange  for  the  message  to  be placed on the hold queue, and
219              inspect the next input line.  The message remains on hold  until
220              someone  either deletes it or releases it for delivery.  Log the
221              optional text if specified, otherwise log a generic message.
222
223              Mail that is placed on hold can be examined with the  postcat(1)
224              command,  and can be destroyed or released with the postsuper(1)
225              command.
226
227              Note: use "postsuper -r" to release mail that was kept  on  hold
228              for   a   significant  fraction  of  $maximal_queue_lifetime  or
229              $bounce_queue_lifetime, or longer. Use "postsuper -H"  only  for
230              mail that will not expire within a few delivery attempts.
231
232              Note: this action affects all recipients of the message.
233
234              This feature is available in Postfix 2.0 and later.
235
236              This feature is not supported with smtp header/body checks.
237
238       IGNORE Delete  the  current  line  from the input, and inspect the next
239              input line.
240
241       INFO optional text...
242              Log an "info:" record  with  the  optional  text...  (or  log  a
243              generic  text),  and inspect the next input line. This action is
244              useful for routine logging or for debugging.
245
246              This feature is available in Postfix 2.8 and later.
247
248       PREPEND text...
249              Prepend one line with the specified text, and inspect  the  next
250              input line.
251
252              Notes:
253
254              ·      The  prepended text is output on a separate line, immedi‐
255                     ately before the input that triggered the PREPEND action.
256
257              ·      The prepended text is not considered part  of  the  input
258                     stream:  it  is  not  subject  to  header/body  checks or
259                     address rewriting, and it does not affect  the  way  that
260                     Postfix adds missing message headers.
261
262              ·      When  prepending  text  before a message header line, the
263                     prepended text must begin with  a  valid  message  header
264                     label.
265
266              ·      This action cannot be used to prepend multi-line text.
267
268              This feature is available in Postfix 2.1 and later.
269
270              This feature is not supported with milter_header_checks.
271
272       REDIRECT user@domain
273              Write  a  message  redirection  request  to  the queue file, and
274              inspect the next input line. After the  message  is  queued,  it
275              will  be  sent  to the specified address instead of the intended
276              recipient(s).
277
278              Note: this action overrides the FILTER action, and  affects  all
279              recipients  of  the  message. If multiple REDIRECT actions fire,
280              only the last one is executed.
281
282              This feature is available in Postfix 2.1 and later.
283
284              This feature is not supported with smtp header/body checks.
285
286       REPLACE text...
287              Replace the current line with the specified  text,  and  inspect
288              the next input line.
289
290              This feature is available in Postfix 2.2 and later. The descrip‐
291              tion below applies to Postfix 2.2.2 and later.
292
293              Notes:
294
295              ·      When replacing a message  header  line,  the  replacement
296                     text must begin with a valid header label.
297
298              ·      The  replaced  text  remains  part  of  the input stream.
299                     Unlike the result from the  PREPEND  action,  a  replaced
300                     message  header  may  be subject to address rewriting and
301                     may affect the way  that  Postfix  adds  missing  message
302                     headers.
303
304       REJECT optional text...
305              Reject  the entire message. Reply with optional text... when the
306              optional text is specified, otherwise reply with a generic error
307              message.
308
309              Note: this action disables further header or body_checks inspec‐
310              tion of the current message and affects all recipients.
311
312              Postfix version 2.3 and later  support  enhanced  status  codes.
313              When  no code is specified at the beginning of optional text...,
314              Postfix inserts a default enhanced status code of "5.7.1".
315
316              This feature is not supported with smtp header/body checks.
317
318       WARN optional text...
319              Log a "warning:" record with the  optional  text...  (or  log  a
320              generic  text),  and inspect the next input line. This action is
321              useful for debugging and for testing a pattern  before  applying
322              more drastic actions.
323

BUGS

325       Empty lines never match, because some map types mis-behave when given a
326       zero-length search string.  This limitation may be removed for  regular
327       expression tables in a future release.
328
329       Many  people  overlook  the  main limitations of header and body_checks
330       rules.
331
332       ·      These rules operate on one logical message header  or  one  body
333              line at a time. A decision made for one line is not carried over
334              to the next line.
335
336       ·      If text in the message body is encoded (RFC 2045) then the rules
337              need to be specified for the encoded form.
338
339       ·      Likewise,  when  message headers are encoded (RFC 2047) then the
340              rules need to be specified for the encoded form.
341
342       Message headers added by the cleanup(8) daemon itself are excluded from
343       inspection.  Examples  of such message headers are From:, To:, Message-
344       ID:, Date:.
345
346       Message headers deleted by  the  cleanup(8)  daemon  will  be  examined
347       before  they  are deleted. Examples are: Bcc:, Content-Length:, Return-
348       Path:.
349

CONFIGURATION PARAMETERS

351       body_checks
352              Lookup tables with content filter rules for message body  lines.
353              These  filters  see one physical line at a time, in chunks of at
354              most $line_length_limit bytes.
355
356       body_checks_size_limit
357              The amount of content per message body segment (attachment) that
358              is subjected to $body_checks filtering.
359
360       header_checks
361
362       mime_header_checks (default: $header_checks)
363
364       nested_header_checks (default: $header_checks)
365              Lookup  tables  with  content  filter  rules  for message header
366              lines: respectively, these are applied to  the  initial  message
367              headers  (not  including MIME headers), to the MIME headers any‐
368              where in the message, and to the  initial  headers  of  attached
369              messages.
370
371              Note:  these  filters  see one logical message header at a time,
372              even when a message header spans multiple lines. Message headers
373              that  are  longer  than  $header_size_limit characters are trun‐
374              cated.
375
376       disable_mime_input_processing
377              While receiving mail, give no special treatment to MIME  related
378              message  headers;  all text after the initial message headers is
379              considered to be part of  the  message  body.  This  means  that
380              header_checks is applied to all the initial message headers, and
381              that body_checks is applied to the remainder of the message.
382
383              Note: when used in  this  manner,  body_checks  will  process  a
384              multi-line message header one line at a time.
385

EXAMPLES

387       Header pattern to block attachments with bad file name extensions.  For
388       convenience, the PCRE /x flag is specified, so that there is no need to
389       collapse  the  pattern  into a single line of text.  The purpose of the
390       [[:xdigit:]] sub-expressions is to recognize Windows CLSID strings.
391
392       /etc/postfix/main.cf:
393           header_checks = pcre:/etc/postfix/header_checks.pcre
394
395       /etc/postfix/header_checks.pcre:
396           /^Content-(Disposition|Type).*name\s*=\s*"?(.*(\.|=2E)(
397             ade|adp|asp|bas|bat|chm|cmd|com|cpl|crt|dll|exe|
398             hlp|ht[at]|
399             inf|ins|isp|jse?|lnk|md[betw]|ms[cipt]|nws|
400             \{[[:xdigit:]]{8}(?:-[[:xdigit:]]{4}){3}-[[:xdigit:]]{12}\}|
401             ops|pcd|pif|prf|reg|sc[frt]|sh[bsm]|swf|
402             vb[esx]?|vxd|ws[cfh]))(\?=)?"?\s*(;|$)/x
403               REJECT Attachment name "$2" may not end with ".$4"
404
405       Body pattern to stop a specific HTML browser vulnerability exploit.
406
407       /etc/postfix/main.cf:
408           body_checks = regexp:/etc/postfix/body_checks
409
410       /etc/postfix/body_checks:
411           /^<iframe src=(3D)?cid:.* height=(3D)?0 width=(3D)?0>$/
412               REJECT IFRAME vulnerability exploit
413

SEE ALSO

415       cleanup(8), canonicalize and enqueue Postfix message
416       pcre_table(5), format of PCRE lookup tables
417       regexp_table(5), format of POSIX regular expression tables
418       postconf(1), Postfix configuration utility
419       postmap(1), Postfix lookup table management
420       postsuper(1), Postfix janitor
421       postcat(1), show Postfix queue file contents
422       RFC 2045, base64 and quoted-printable encoding rules
423       RFC 2047, message header encoding for non-ASCII text
424

README FILES

426       Use "postconf readme_directory" or "postconf html_directory" to  locate
427       this information.
428       DATABASE_README, Postfix lookup table overview
429       CONTENT_INSPECTION_README, Postfix content inspection overview
430       BUILTIN_FILTER_README, Postfix built-in content inspection
431       BACKSCATTER_README, blocking returned forged mail
432

LICENSE

434       The Secure Mailer license must be distributed with this software.
435

AUTHOR(S)

437       Wietse Venema
438       IBM T.J. Watson Research
439       P.O. Box 704
440       Yorktown Heights, NY 10598, USA
441
442
443
444                                                              HEADER_CHECKS(5)
Impressum