header_checks revision 1.1 1 1.1 tron #++
2 1.1 tron # NAME
3 1.1 tron # header_checks 5
4 1.1 tron # SUMMARY
5 1.1 tron # Postfix built-in content inspection
6 1.1 tron # SYNOPSIS
7 1.1 tron # .nf
8 1.1 tron # \fBheader_checks = pcre:/etc/postfix/header_checks\fR
9 1.1 tron # \fBmime_header_checks = pcre:/etc/postfix/mime_header_checks\fR
10 1.1 tron # \fBnested_header_checks = pcre:/etc/postfix/nested_header_checks\fR
11 1.1 tron # \fBbody_checks = pcre:/etc/postfix/body_checks\fR
12 1.1 tron # .sp
13 1.1 tron # \fBpostmap -q "\fIstring\fB" pcre:/etc/postfix/\fIfilename\fR
14 1.1 tron # \fBpostmap -q - pcre:/etc/postfix/\fIfilename\fR <\fIinputfile\fR
15 1.1 tron # .fi
16 1.1 tron # DESCRIPTION
17 1.1 tron # This document describes access control on the content of
18 1.1 tron # message headers and message body lines; it is implemented
19 1.1 tron # by the Postfix \fBcleanup\fR(8) server before mail is queued.
20 1.1 tron # See \fBaccess\fR(5) for access control on remote SMTP client
21 1.1 tron # information.
22 1.1 tron #
23 1.1 tron # Each message header or message body line is compared against
24 1.1 tron # a list of patterns.
25 1.1 tron # When a match is found the corresponding action is executed, and
26 1.1 tron # the matching process is repeated for the next message header or
27 1.1 tron # message body line.
28 1.1 tron #
29 1.1 tron # For examples, see the EXAMPLES section at the end of this
30 1.1 tron # manual page.
31 1.1 tron #
32 1.1 tron # Postfix header or body_checks are designed to stop a flood of mail
33 1.1 tron # from worms or viruses; they do not decode attachments, and they do
34 1.1 tron # not unzip archives. See the documents referenced below in the README
35 1.1 tron # FILES section if you need more sophisticated content analysis.
36 1.1 tron #
37 1.1 tron # Postfix supports four built-in content inspection classes:
38 1.1 tron # .IP \fBheader_checks\fR
39 1.1 tron # These are applied to initial message headers (except for
40 1.1 tron # the headers that are processed with \fBmime_header_checks\fR).
41 1.1 tron # .IP "\fBmime_header_checks\fR (default: \fB$header_checks\fR)"
42 1.1 tron # These are applied to MIME related message headers only.
43 1.1 tron # .sp
44 1.1 tron # This feature is available in Postfix 2.0 and later.
45 1.1 tron # .IP "\fBnested_header_checks\fR (default: \fB$header_checks\fR)"
46 1.1 tron # These are applied to message headers of attached email
47 1.1 tron # messages (except for the headers that are processed with
48 1.1 tron # \fBmime_header_checks\fR).
49 1.1 tron # .sp
50 1.1 tron # This feature is available in Postfix 2.0 and later.
51 1.1 tron # .IP \fBbody_checks\fR
52 1.1 tron # These are applied to all other content, including multi-part
53 1.1 tron # message boundaries.
54 1.1 tron # .sp
55 1.1 tron # With Postfix versions before 2.0, all content after the initial
56 1.1 tron # message headers is treated as body content.
57 1.1 tron # .PP
58 1.1 tron # Note: message headers are examined one logical header at a time,
59 1.1 tron # even when a message header spans multiple lines. Body lines are
60 1.1 tron # always examined one line at a time.
61 1.1 tron # COMPATIBILITY
62 1.1 tron # .ad
63 1.1 tron # .fi
64 1.1 tron # With Postfix version 2.2 and earlier specify "\fBpostmap
65 1.1 tron # -fq\fR" to query a table that contains case sensitive
66 1.1 tron # patterns. By default, regexp: and pcre: patterns are case
67 1.1 tron # insensitive.
68 1.1 tron # TABLE FORMAT
69 1.1 tron # .ad
70 1.1 tron # .fi
71 1.1 tron # This document assumes that header and body_checks rules are specified
72 1.1 tron # in the form of Postfix regular expression lookup tables. Usually the
73 1.1 tron # best performance is obtained with \fBpcre\fR (Perl Compatible Regular
74 1.1 tron # Expression) tables, but the slower \fBregexp\fR (POSIX regular
75 1.1 tron # expressions) support is more widely available.
76 1.1 tron # Use the command "\fBpostconf -m\fR" to find out what lookup table
77 1.1 tron # types your Postfix system supports.
78 1.1 tron #
79 1.1 tron # The general format of Postfix regular expression tables is
80 1.1 tron # given below.
81 1.1 tron # For a discussion of specific pattern or flags syntax,
82 1.1 tron # see \fBpcre_table\fR(5) or \fBregexp_table\fR(5), respectively.
83 1.1 tron # .IP "\fB/\fIpattern\fB/\fIflags action\fR"
84 1.1 tron # When /\fIpattern\fR/ matches the input string, execute
85 1.1 tron # the corresponding \fIaction\fR. See below for a list
86 1.1 tron # of possible actions.
87 1.1 tron # .IP "\fB!/\fIpattern\fB/\fIflags action\fR"
88 1.1 tron # When /\fIpattern\fR/ does \fBnot\fR match the input string,
89 1.1 tron # execute the corresponding \fIaction\fR.
90 1.1 tron # .IP "\fBif /\fIpattern\fB/\fIflags\fR"
91 1.1 tron # .IP "\fBendif\fR"
92 1.1 tron # Match the input string against the patterns between \fBif\fR
93 1.1 tron # and \fBendif\fR, if and only if the same input string also
94 1.1 tron # matches /\fIpattern\fR/. The \fBif\fR..\fBendif\fR can nest.
95 1.1 tron # .sp
96 1.1 tron # Note: do not prepend whitespace to patterns inside
97 1.1 tron # \fBif\fR..\fBendif\fR.
98 1.1 tron # .IP "\fBif !/\fIpattern\fB/\fIflags\fR"
99 1.1 tron # .IP "\fBendif\fR"
100 1.1 tron # Match the input string against the patterns between \fBif\fR
101 1.1 tron # and \fBendif\fR, if and only if the same input string does
102 1.1 tron # \fBnot\fR match /\fIpattern\fR/. The \fBif\fR..\fBendif\fR
103 1.1 tron # can nest.
104 1.1 tron # .IP "blank lines and comments"
105 1.1 tron # Empty lines and whitespace-only lines are ignored, as
106 1.1 tron # are lines whose first non-whitespace character is a `#'.
107 1.1 tron # .IP "multi-line text"
108 1.1 tron # A pattern/action line starts with non-whitespace text. A line that
109 1.1 tron # starts with whitespace continues a logical line.
110 1.1 tron # TABLE SEARCH ORDER
111 1.1 tron # .ad
112 1.1 tron # .fi
113 1.1 tron # For each line of message input, the patterns are applied in the
114 1.1 tron # order as specified in the table. When a pattern is found that matches
115 1.1 tron # the input line, the corresponding action is executed and then the
116 1.1 tron # next input line is inspected.
117 1.1 tron # TEXT SUBSTITUTION
118 1.1 tron # .ad
119 1.1 tron # .fi
120 1.1 tron # Substitution of substrings from the matched expression into the
121 1.1 tron # \fIaction\fR
122 1.1 tron # string is possible using the conventional Perl syntax
123 1.1 tron # (\fB$1\fR, \fB$2\fR, etc.).
124 1.1 tron # The macros in the result string may need to be written as \fB${n}\fR
125 1.1 tron # or \fB$(n)\fR if they aren't followed by whitespace.
126 1.1 tron #
127 1.1 tron # Note: since negated patterns (those preceded by \fB!\fR) return a
128 1.1 tron # result when the expression does not match, substitutions are not
129 1.1 tron # available for negated patterns.
130 1.1 tron # ACTIONS
131 1.1 tron # .ad
132 1.1 tron # .fi
133 1.1 tron # Action names are case insensitive. They are shown in upper case
134 1.1 tron # for consistency with other Postfix documentation.
135 1.1 tron # \" .IP "\fBDELAY \fItime\fR"
136 1.1 tron # \" Place the message into the deferred queue, and delay the
137 1.1 tron # \" initial delivery attempt by \fItime\fR. The time value may
138 1.1 tron # \" be followed by a one-character suffix that specifies the
139 1.1 tron # \" time unit: s (seconds), m (minutes), h (hours), d (days),
140 1.1 tron # \" w (weeks). The default time unit is s (seconds).
141 1.1 tron # \" .sp
142 1.1 tron # \" Limitations:
143 1.1 tron # \" .RS
144 1.1 tron # \" .IP \(bu
145 1.1 tron # \" This action affects all the recipients of the message.
146 1.1 tron # \" .IP \(bu
147 1.1 tron # \" The delay value has no effect with remote file systems that
148 1.1 tron # \" don't correctly emulate UNIX local file system semantics.
149 1.1 tron # \" In that case, the delay will be half of $queue_run_delay
150 1.1 tron # \" on average.
151 1.1 tron # \" .IP \(bu
152 1.1 tron # \" Mail will still be delivered with "sendmail -q", "postfix
153 1.1 tron # \" flush" or "postqueue -f".
154 1.1 tron # \" .IP \(bu
155 1.1 tron # \" Delayed mail increases the amount of disk I/O during deferred
156 1.1 tron # \" queue scans. When large amounts of mail are queued for
157 1.1 tron # \" delayed delivery it may be preferable to use the HOLD feature
158 1.1 tron # \" instead.
159 1.1 tron # \" .RE
160 1.1 tron # \" .IP
161 1.1 tron # \" This feature is available in Postfix 2.3 and later.
162 1.1 tron # .IP "\fBDISCARD \fIoptional text...\fR"
163 1.1 tron # Claim successful delivery and silently discard the message.
164 1.1 tron # Log the optional text if specified, otherwise log a generic
165 1.1 tron # message.
166 1.1 tron # .sp
167 1.1 tron # Note: this action disables further header or body_checks inspection
168 1.1 tron # of the current message and affects all recipients.
169 1.1 tron # To discard only one recipient without discarding the entire message,
170 1.1 tron # use the transport(5) table to direct mail to the discard(8) service.
171 1.1 tron # .sp
172 1.1 tron # This feature is available in Postfix 2.0 and later.
173 1.1 tron # .IP \fBDUNNO\fR
174 1.1 tron # Pretend that the input line did not match any pattern, and inspect the
175 1.1 tron # next input line. This action can be used to shorten the table search.
176 1.1 tron # .sp
177 1.1 tron # For backwards compatibility reasons, Postfix also accepts
178 1.1 tron # \fBOK\fR but it is (and always has been) treated as \fBDUNNO\fR.
179 1.1 tron # .sp
180 1.1 tron # This feature is available in Postfix 2.1 and later.
181 1.1 tron # .IP "\fBFILTER \fItransport:destination\fR"
182 1.1 tron # Write a content filter request to the queue file, and
183 1.1 tron # inspect the next input line.
184 1.1 tron # After the complete message is received it will be sent through
185 1.1 tron # the specified external content filter. More information about
186 1.1 tron # external content filters is in the Postfix FILTER_README file.
187 1.1 tron # .sp
188 1.1 tron # Note: this action overrides the \fBcontent_filter\fR setting,
189 1.1 tron # and affects all recipients of the message. In the case that multiple
190 1.1 tron # \fBFILTER\fR actions fire, only the last one is executed.
191 1.1 tron # .sp
192 1.1 tron # This feature is available in Postfix 2.0 and later.
193 1.1 tron # .IP "\fBHOLD \fIoptional text...\fR"
194 1.1 tron # Arrange for the message to be placed on the \fBhold\fR queue,
195 1.1 tron # and inspect the next input line. The message remains on \fBhold\fR
196 1.1 tron # until someone either deletes it or releases it for delivery.
197 1.1 tron # Log the optional text if specified, otherwise log a generic
198 1.1 tron # message.
199 1.1 tron #
200 1.1 tron # Mail that is placed on hold can be examined with the
201 1.1 tron # \fBpostcat\fR(1) command, and can be destroyed or released with
202 1.1 tron # the \fBpostsuper\fR(1) command.
203 1.1 tron # .sp
204 1.1 tron # Note: use "\fBpostsuper -r\fR" to release mail that was kept on
205 1.1 tron # hold for a significant fraction of \fB$maximal_queue_lifetime\fR
206 1.1 tron # or \fB$bounce_queue_lifetime\fR, or longer. Use "\fBpostsuper -H\fR"
207 1.1 tron # only for mail that will not expire within a few delivery attempts.
208 1.1 tron # .sp
209 1.1 tron # Note: this action affects all recipients of the message.
210 1.1 tron # .sp
211 1.1 tron # This feature is available in Postfix 2.0 and later.
212 1.1 tron # .IP \fBIGNORE\fR
213 1.1 tron # Delete the current line from the input, and inspect
214 1.1 tron # the next input line.
215 1.1 tron # .IP "\fBPREPEND \fItext...\fR"
216 1.1 tron # Prepend one line with the specified text, and inspect the next
217 1.1 tron # input line.
218 1.1 tron # .sp
219 1.1 tron # Notes:
220 1.1 tron # .RS
221 1.1 tron # .IP \(bu
222 1.1 tron # The prepended text is output on a separate line, immediately
223 1.1 tron # before the input that triggered the \fBPREPEND\fR action.
224 1.1 tron # .IP \(bu
225 1.1 tron # The prepended text is not considered part of the input
226 1.1 tron # stream: it is not subject to header/body checks or address
227 1.1 tron # rewriting, and it does not affect the way that Postfix adds
228 1.1 tron # missing message headers.
229 1.1 tron # .IP \(bu
230 1.1 tron # When prepending text before a message header line, the prepended
231 1.1 tron # text must begin with a valid message header label.
232 1.1 tron # .IP \(bu
233 1.1 tron # This action cannot be used to prepend multi-line text.
234 1.1 tron # .RE
235 1.1 tron # .IP
236 1.1 tron # This feature is available in Postfix 2.1 and later.
237 1.1 tron # .IP "\fBREDIRECT \fIuser@domain\fR"
238 1.1 tron # Write a message redirection request to the queue file, and
239 1.1 tron # inspect the next input line. After the message is queued,
240 1.1 tron # it will be sent to the specified address instead of the
241 1.1 tron # intended recipient(s).
242 1.1 tron # .sp
243 1.1 tron # Note: this action overrides the \fBFILTER\fR action, and affects
244 1.1 tron # all recipients of the message. If multiple \fBREDIRECT\fR actions
245 1.1 tron # fire, only the last one is executed.
246 1.1 tron # .sp
247 1.1 tron # This feature is available in Postfix 2.1 and later.
248 1.1 tron # .IP "\fBREPLACE \fItext...\fR"
249 1.1 tron # Replace the current line with the specified text, and inspect the next
250 1.1 tron # input line.
251 1.1 tron # .sp
252 1.1 tron # This feature is available in Postfix 2.2 and later. The
253 1.1 tron # description below applies to Postfix 2.2.2 and later.
254 1.1 tron # .sp
255 1.1 tron # Notes:
256 1.1 tron # .RS
257 1.1 tron # .IP \(bu
258 1.1 tron # When replacing a message header line, the replacement text
259 1.1 tron # must begin with a valid header label.
260 1.1 tron # .IP \(bu
261 1.1 tron # The replaced text remains part of the input stream. Unlike
262 1.1 tron # the result from the \fBPREPEND\fR action, a replaced message
263 1.1 tron # header may be subject to address rewriting and may affect
264 1.1 tron # the way that Postfix adds missing message headers.
265 1.1 tron # .RE
266 1.1 tron # .IP "\fBREJECT \fIoptional text...\fR
267 1.1 tron # Reject the entire message. Reply with \fIoptional text...\fR when
268 1.1 tron # the optional text is specified, otherwise reply with a generic error
269 1.1 tron # message.
270 1.1 tron # .sp
271 1.1 tron # Note: this action disables further header or body_checks inspection
272 1.1 tron # of the current message and affects all recipients.
273 1.1 tron # .sp
274 1.1 tron # Postfix version 2.3 and later support enhanced status codes.
275 1.1 tron # When no code is specified at the beginning of \fIoptional
276 1.1 tron # text...\fR, Postfix inserts a default enhanced status code of
277 1.1 tron # "5.7.1".
278 1.1 tron # .IP "\fBWARN \fIoptional text...\fR
279 1.1 tron # Log a warning with the \fIoptional text...\fR (or log a
280 1.1 tron # generic message), and inspect the next input line. This
281 1.1 tron # action is useful for debugging and for testing a pattern
282 1.1 tron # before applying more drastic actions.
283 1.1 tron # BUGS
284 1.1 tron # Empty lines never match, because some map types mis-behave
285 1.1 tron # when given a zero-length search string. This limitation may
286 1.1 tron # be removed for regular expression tables in a future release.
287 1.1 tron #
288 1.1 tron # Many people overlook the main limitations of header and body_checks
289 1.1 tron # rules.
290 1.1 tron # .IP \(bu
291 1.1 tron # These rules operate on one logical message header or one body
292 1.1 tron # line at a time. A decision made for one line is not carried over
293 1.1 tron # to the next line.
294 1.1 tron # .IP \(bu
295 1.1 tron # If text in the message body is encoded
296 1.1 tron # (RFC 2045) then the rules need to be specified for the encoded
297 1.1 tron # form.
298 1.1 tron # .IP \(bu
299 1.1 tron # Likewise, when message headers are encoded (RFC
300 1.1 tron # 2047) then the rules need to be specified for the encoded
301 1.1 tron # form.
302 1.1 tron # .PP
303 1.1 tron # Message headers added by the \fBcleanup\fR(8) daemon itself
304 1.1 tron # are excluded from inspection. Examples of such message headers
305 1.1 tron # are \fBFrom:\fR, \fBTo:\fR, \fBMessage-ID:\fR, \fBDate:\fR.
306 1.1 tron #
307 1.1 tron # Message headers deleted by the \fBcleanup\fR(8) daemon will
308 1.1 tron # be examined before they are deleted. Examples are: \fBBcc:\fr,
309 1.1 tron # \fBContent-Length:\fR, \fBReturn-Path:\fR.
310 1.1 tron # CONFIGURATION PARAMETERS
311 1.1 tron # .ad
312 1.1 tron # .fi
313 1.1 tron # .IP \fBbody_checks\fR
314 1.1 tron # Lookup tables with content filter rules for message body lines.
315 1.1 tron # These filters see one physical line at a time, in chunks of
316 1.1 tron # at most \fB$line_length_limit\fR bytes.
317 1.1 tron # .IP \fBbody_checks_size_limit\fP
318 1.1 tron # The amount of content per message body segment (attachment) that is
319 1.1 tron # subjected to \fB$body_checks\fR filtering.
320 1.1 tron # .IP \fBheader_checks\fR
321 1.1 tron # .IP "\fBmime_header_checks\fR (default: \fB$header_checks\fR)"
322 1.1 tron # .IP "\fBnested_header_checks\fR (default: \fB$header_checks\fR)"
323 1.1 tron # Lookup tables with content filter rules for message header lines:
324 1.1 tron # respectively, these are applied to the initial message headers
325 1.1 tron # (not including MIME headers), to the MIME headers anywhere in
326 1.1 tron # the message, and to the initial headers of attached messages.
327 1.1 tron # .sp
328 1.1 tron # Note: these filters see one logical message header at a time, even
329 1.1 tron # when a message header spans multiple lines. Message headers that
330 1.1 tron # are longer than \fB$header_size_limit\fR characters are truncated.
331 1.1 tron # .IP \fBdisable_mime_input_processing\fR
332 1.1 tron # While receiving mail, give no special treatment to MIME related
333 1.1 tron # message headers; all text after the initial message headers is
334 1.1 tron # considered to be part of the message body. This means that
335 1.1 tron # \fBheader_checks\fR is applied to all the initial message headers,
336 1.1 tron # and that \fBbody_checks\fR is applied to the remainder of the
337 1.1 tron # message.
338 1.1 tron # .sp
339 1.1 tron # Note: when used in this manner, \fBbody_checks\fR will process
340 1.1 tron # a multi-line message header one line at a time.
341 1.1 tron # EXAMPLES
342 1.1 tron # .ad
343 1.1 tron # .fi
344 1.1 tron # Header pattern to block attachments with bad file name
345 1.1 tron # extensions. For convenience, the PCRE /x flag is specified,
346 1.1 tron # so that there is no need to collapse the pattern into a
347 1.1 tron # single line of text. The purpose of the [[:xdigit:]]
348 1.1 tron # sub-expressions is to recognize Windows CLSID strings.
349 1.1 tron #
350 1.1 tron # .na
351 1.1 tron # .nf
352 1.1 tron # /etc/postfix/main.cf:
353 1.1 tron # header_checks = pcre:/etc/postfix/header_checks.pcre
354 1.1 tron #
355 1.1 tron # /etc/postfix/header_checks.pcre:
356 1.1 tron # /^Content-(Disposition|Type).*name\es*=\es*"?(.*(\e.|=2E)(
357 1.1 tron # ade|adp|asp|bas|bat|chm|cmd|com|cpl|crt|dll|exe|
358 1.1 tron # hlp|ht[at]|
359 1.1 tron # inf|ins|isp|jse?|lnk|md[betw]|ms[cipt]|nws|
360 1.1 tron # \e{[[:xdigit:]]{8}(?:-[[:xdigit:]]{4}){3}-[[:xdigit:]]{12}\e}|
361 1.1 tron # ops|pcd|pif|prf|reg|sc[frt]|sh[bsm]|swf|
362 1.1 tron # vb[esx]?|vxd|ws[cfh]))(\e?=)?"?\es*(;|$)/x
363 1.1 tron # REJECT Attachment name "$2" may not end with ".$4"
364 1.1 tron # .ad
365 1.1 tron # .fi
366 1.1 tron #
367 1.1 tron # Body pattern to stop a specific HTML browser vulnerability exploit.
368 1.1 tron #
369 1.1 tron # .na
370 1.1 tron # .nf
371 1.1 tron # /etc/postfix/main.cf:
372 1.1 tron # body_checks = regexp:/etc/postfix/body_checks
373 1.1 tron #
374 1.1 tron # /etc/postfix/body_checks:
375 1.1 tron # /^<iframe src=(3D)?cid:.* height=(3D)?0 width=(3D)?0>$/
376 1.1 tron # REJECT IFRAME vulnerability exploit
377 1.1 tron # SEE ALSO
378 1.1 tron # cleanup(8), canonicalize and enqueue Postfix message
379 1.1 tron # pcre_table(5), format of PCRE lookup tables
380 1.1 tron # regexp_table(5), format of POSIX regular expression tables
381 1.1 tron # postconf(1), Postfix configuration utility
382 1.1 tron # postmap(1), Postfix lookup table management
383 1.1 tron # postsuper(1), Postfix janitor
384 1.1 tron # postcat(1), show Postfix queue file contents
385 1.1 tron # RFC 2045, base64 and quoted-printable encoding rules
386 1.1 tron # RFC 2047, message header encoding for non-ASCII text
387 1.1 tron # README FILES
388 1.1 tron # .ad
389 1.1 tron # .fi
390 1.1 tron # Use "\fBpostconf readme_directory\fR" or
391 1.1 tron # "\fBpostconf html_directory\fR" to locate this information.
392 1.1 tron # .na
393 1.1 tron # .nf
394 1.1 tron # DATABASE_README, Postfix lookup table overview
395 1.1 tron # CONTENT_INSPECTION_README, Postfix content inspection overview
396 1.1 tron # BUILTIN_FILTER_README, Postfix built-in content inspection
397 1.1 tron # BACKSCATTER_README, blocking returned forged mail
398 1.1 tron # LICENSE
399 1.1 tron # .ad
400 1.1 tron # .fi
401 1.1 tron # The Secure Mailer license must be distributed with this software.
402 1.1 tron # AUTHOR(S)
403 1.1 tron # Wietse Venema
404 1.1 tron # IBM T.J. Watson Research
405 1.1 tron # P.O. Box 704
406 1.1 tron # Yorktown Heights, NY 10598, USA
407 1.1 tron #--
408