2 <!DOCTYPE modulesynopsis SYSTEM "../style/modulesynopsis.dtd">
3 <?xml-stylesheet type="text/xsl" href="../style/manual.en.xsl"?>
4 <!-- $LastChangedRevision$ -->
7 Licensed to the Apache Software Foundation (ASF) under one or more
8 contributor license agreements. See the NOTICE file distributed with
9 this work for additional information regarding copyright ownership.
10 The ASF licenses this file to You under the Apache License, Version 2.0
11 (the "License"); you may not use this file except in compliance with
12 the License. You may obtain a copy of the License at
14 http://www.apache.org/licenses/LICENSE-2.0
16 Unless required by applicable law or agreed to in writing, software
17 distributed under the License is distributed on an "AS IS" BASIS,
18 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19 See the License for the specific language governing permissions and
20 limitations under the License.
23 <modulesynopsis metafile="mod_policy.xml.meta">
25 <name>mod_policy</name>
26 <description>HTTP protocol compliance enforcement.</description>
27 <status>Extension</status>
28 <sourcefile>mod_policy.c</sourcefile>
29 <identifier>policy_module</identifier>
32 <p>The HTTP protocol recommends that clients should be "liberal in
33 what they accept", and servers "strict with what they send". In some
34 cases it can be difficult to detect when a server or an application
35 has been misconfigured, is serving uncacheable content or is behaving
36 suboptimally, as an HTTP client might be compensating for the server.
37 These problems can potentially lead to excessive bandwidth
38 consumption, or a server outage under load.</p>
40 <p>The <module>mod_policy</module> module consists of a set of
41 filters that test servers for HTTP protocol compliance. These
42 tests allow the server administrator to log violations of, or
43 outright reject responses where certain defined conditions exist.</p>
45 <p>This could be used as a way to set minimum HTTP protocol compliance
46 criteria for a restful application. Alternatively, a reverse proxy or
47 cache could be configured to protect itself from misconfigured origin
48 servers or unexpectedly uncacheable content, or as a mechanism to
49 detect configuration mistakes within the server itself.</p>
52 <seealso><a href="../filter.html">Filters</a></seealso>
53 <seealso><a href="../compliance.html">HTTP Protocol Compliance</a></seealso>
55 <section id="actions">
56 <title>Actions</title>
58 <p>If a policy is violated, one of the following actions can be
62 <dt><strong>ignore</strong></dt>
63 <dd>The policy check will be ignored for the given URL space, even
64 if the filter is present.</dd>
66 <dt><strong>log</strong></dt>
67 <dd>The policy check will be executed, and if a violation is detected
68 a warning will be logged to the server error_log, and a
69 <code>Warning</code> header added to the response for the benefit of
72 <dt><strong>enforce</strong></dt>
73 <dd>The policy check will be executed, and if a violation is detected
74 an error will be logged to the server error_log, a
75 <code>Warning</code> header added to the response, and a <code>502
76 Bad Gateway</code> will be returned to the client. Optional links to
77 explanatory documentation can be added to each error message,
78 detailing the origin of each policy.</dd>
82 <p>It is also possible to selectively disable all policies for a
83 given URL space, should the need arise, using the
84 <directive module="mod_policy">PolicyFilter</directive> directive.</p>
87 <directive module="mod_policy">PolicyEnvironment</directive>
88 directive can be used to specify an environment variable, which if
89 present, will cause the policies to be selectively downgraded or
95 <title>Policy Tests</title>
97 <p>The following policy filters are available:</p>
100 <dt><strong><a href="../compliance.html#policytype">POLICY_TYPE</a>
101 </strong>: Enforce valid content types</dt>
102 <dd>Content types that are syntactically invalid or blank can be detected
103 and the request rejected. Types can be restricted to a specific list
104 containing optional wildcards ? and *.</dd>
106 <dt><strong><a href="../compliance.html#policylength">POLICY_LENGTH</a>
107 </strong>: Enforce the presence of a Content-Length</dt>
108 <dd>The length of responses can be specified in one of three ways, by
109 specifying an explicit length in advance, using chunked encoding to set
110 the length, or by setting no length at all and terminating the request
111 when complete. The absence of a specific content length can affect the
112 cacheability of the response, and prevents the use of keepalive during
113 HTTP/1.0 requests. This policy enforces the presence of an explicit
114 content length on the response.</dd>
116 <dt><strong><a href="../compliance.html#policykeepalive">POLICY_KEEPALIVE
117 </a></strong>: Enforce the option to keepalive</dt>
118 <dd>Less restrictive than the POLICY_LENGTH test, this policy enforces the
119 possibility that the response can be kept alive. If the response doesn't
120 have a protocol defined zero length, and the response isn't already an
121 error, and the response has neither a Content-Length or is declared
122 HTTP/1.1 and lacks Content-Encoding: chunked, then this response will be
125 <dt><strong><a href="../compliance.html#policyvary">POLICY_VARY</a>
126 </strong>: Enforce the absence of certain headers within Vary headers</dt>
127 <dd>If the Vary header contains any of the headers specified, this policy
128 will reject the request. The typical case is the presence of the User-Agent
129 within Vary, which is likely to cause a denial of service condition to a
132 <dt><strong><a href="../compliance.html#policyvalidation">
133 POLICY_VALIDATION</a></strong>: Enforce the presence of Etag and/or
135 <dd>The ability for a cache to determine whether a cached entity can be
136 refreshed is dependent on whether a valid Etag and/or Last-Modified header
137 is present to revalidate against. The absence of both headers, or the
138 invalid syntax of a header will cause this policy to be rejected.</dd>
140 <dt><strong><a href="../compliance.html#policyconditional">
141 POLICY_CONDITIONAL</a></strong>: Enforce correct operation of conditional
143 <dd>When conditional headers are present in the request, a server should
144 respond with a <code>304 Not Modified</code> or <code>412 Precondition
145 Failed</code> response where appropriate. A server may ignore conditional
146 headers, and this affects the efficiency of the HTTP caching mechanism.
147 This policy rejects requests where a conditional header is present, and
148 a 304 or 412 response code was expected, but a 2xx response was seen
151 <dt><strong><a href="../compliance.html#policynocache">POLICY_NOCACHE</a>
152 </strong>: Enforce cacheable responses</dt>
153 <dd>When a response is encountered that declares itself explicitly
154 uncacheable, the request is rejected. A response is considered
155 uncacheable if it specifies any of the following:
156 <ul><li><code>Cache-Control: no-cache</code></li>
157 <li><code>Pragma: no-cache</code></li>
158 <li><code>Cache-Control: no-store</code></li>
159 <li><code>Cache-Control: private</code></li>
162 <dt><strong><a href="../compliance.html#policymaxage">POLICY_MAXAGE</a>
163 </strong>: Enforce a minimum maxage</dt>
164 <dd>When a response is encountered where the freshness lifetime is less
165 than the given value, or the freshness lifetime is heuristic, the request
166 is rejected. A response is checked in the following order:
167 <ul><li>If <code>s-maxage</code> is present but too small; or</li>
168 <li>If <code>max-age</code> is present but too small; or</li>
169 <li>If <code>Expires</code> is present and invalid; or</li>
170 <li><code>Date</code> is present and invalid; or</li>
171 <li><code>Expires</code> minus Date is too small; or</li>
172 <li>No <code>s-maxage</code>, <code>maxage</code>, or
173 <code>Expires</code>/<code>Date</code> declared at all</li>
176 <dt><strong><a href="../compliance.html#policyversion">POLICY_VERSION</a>
177 </strong>: Enforce a minimum HTTP version within a request</dt>
178 <dd>When a request is encountered with an HTTP version number less than
179 the required minimum version, the request is rejected. The following
180 version numbers are recognised:
181 <ul><li><code>HTTP/1.1</code></li>
182 <li><code>HTTP/1.0</code></li>
183 <li><code>HTTP/0.9</code></li>
190 <section id="example">
191 <title>Example Configuration</title>
193 <p>A typical configuration protecting a server serving static content
194 might be as follows:</p>
196 <highlight language="config">
198 SetOutputFilter POLICY_TYPE;POLICY_LENGTH;POLICY_KEEPALIVE;POLICY_VARY;POLICY_VALIDATION; \
199 POLICY_CONDITIONAL;POLICY_NOCACHE;POLICY_MAXAGE;POLICY_VERSION
201 # content type must be present and valid, but can be anything
202 PolicyType enforce */*
204 # reject if no explicitly declared content length
207 # covered by the policy length filter
208 PolicyKeepalive ignore
210 # reject if User-Agent appears within Vary headers
211 PolicyVary enforce User-Agent
213 # we want to enforce validation
214 PolicyValidation enforce
216 # non-functional conditional responses should be rejected
217 PolicyConditional enforce
219 # no-cache responses should be rejected
220 PolicyNocache enforce
222 # maxage must be at least a day
223 PolicyMaxage enforce 86400
225 # request version can be anything
226 PolicyVersion ignore HTTP/1.1
229 # suppress policy protection for server-status
230 <Location /server-status>
239 <name>PolicyFilter</name>
240 <description>Enable or disable policies for the given URL space.</description>
241 <syntax>PolicyFilter <var>on|off</var></syntax>
242 <default>on</default>
243 <contextlist><context>server config</context><context>virtual host</context>
244 <context>directory</context></contextlist>
245 <compatibility>PolicyFilter is only available in Apache 2.5.0 and
246 later.</compatibility>
249 <p>Master switch to enable or disable policies for a given URL space.</p>
251 <example><title>Example</title>
252 <highlight language="config">
258 # suppress policy protection for server-status
259 <Location /server-status>
270 <name>PolicyEnvironment</name>
271 <description>Override policies based on an environment variable.</description>
272 <syntax>PolicyEnvironment <var>variable</var> <var>log-value</var> <var>ignore-value</var></syntax>
273 <default>none</default>
274 <contextlist><context>server config</context><context>virtual host</context>
275 <context>directory</context></contextlist>
276 <compatibility>PolicyEnvironment is only available in Apache 2.5.0 and
277 later.</compatibility>
280 <p>Downgrade policies to logging only or ignored based on the presence
281 of an environment variable. If the given variable is present and equal
282 to the log-value, enforced policies will be logged instead. If the given
283 variable is present and equal to the ignore-value, all policies will
286 <example><title>Example</title>
287 <highlight language="config">
288 # downgrade if POLICY_CONTROL was present
289 PolicyEnvironment POLICY_CONTROL log ignore
298 <name>PolicyConditional</name>
299 <description>Enable the conditional request policy.</description>
300 <syntax>PolicyConditional <var>ignore|log|enforce</var></syntax>
301 <default>ignore</default>
302 <contextlist><context>server config</context><context>virtual host</context>
303 <context>directory</context></contextlist>
304 <compatibility>PolicyConditional is only available in Apache 2.5.0 and
305 later.</compatibility>
308 <p>When logged or enforced, a response that should have been conditional
309 but wasn't will be rejected.</p>
311 <example><title>Example</title>
312 <highlight language="config">
313 # non-functional conditional responses should be rejected
314 PolicyConditional enforce
323 <name>PolicyConditionalURL</name>
324 <description>URL describing the conditional request policy.</description>
325 <syntax>PolicyConditionalURL <var>url</var></syntax>
326 <default>none</default>
327 <contextlist><context>server config</context><context>virtual host</context>
328 <context>directory</context></contextlist>
329 <compatibility>PolicyConditionalURL is only available in Apache 2.5.0 and
330 later.</compatibility>
333 <p>Specify the URL of the documentation describing the conditional
334 request policy, to appear within error messages.</p>
341 <name>PolicyLength</name>
342 <description>Enable the content length policy.</description>
343 <syntax>PolicyLength <var>ignore|log|enforce</var></syntax>
344 <default>ignore</default>
345 <contextlist><context>server config</context><context>virtual host</context>
346 <context>directory</context></contextlist>
347 <compatibility>PolicyLength is only available in Apache 2.5.0 and
348 later.</compatibility>
351 <p>When logged or enforced, a response that lacks an explicit
352 <code>Content-Length</code> header will be rejected.</p>
354 <example><title>Example</title>
355 <highlight language="config">
356 # missing Content-Length header should be rejected
366 <name>PolicyLengthURL</name>
367 <description>URL describing the content length policy.</description>
368 <syntax>PolicyLengthURL <var>url</var></syntax>
369 <default>none</default>
370 <contextlist><context>server config</context><context>virtual host</context>
371 <context>directory</context></contextlist>
372 <compatibility>PolicyLengthURL is only available in Apache 2.5.0 and
373 later.</compatibility>
376 <p>Specify the URL of the documentation describing the content length
377 policy, to appear within error messages.</p>
384 <name>PolicyKeepalive</name>
385 <description>Enable the keepalive policy.</description>
386 <syntax>PolicyKeepalive <var>ignore|log|enforce</var></syntax>
387 <default>ignore</default>
388 <contextlist><context>server config</context><context>virtual host</context>
389 <context>directory</context></contextlist>
390 <compatibility>PolicyKeepalive is only available in Apache 2.5.0 and
391 later.</compatibility>
394 <p>When logged or enforced, a response that lacks both an explicit
395 <code>Content-Length</code> header and a <code>Transfer-Encoding</code>
396 of <code>chunked</code> will be rejected.</p>
398 <example><title>Example</title>
399 <highlight language="config">
400 # missing Content-Length or Transfer-Encoding should be rejected
401 PolicyKeepalive enforce
410 <name>PolicyKeepaliveURL</name>
411 <description>URL describing the keepalive policy.</description>
412 <syntax>PolicyKeepaliveURL <var>url</var></syntax>
413 <default>none</default>
414 <contextlist><context>server config</context><context>virtual host</context>
415 <context>directory</context></contextlist>
416 <compatibility>PolicyKeepaliveURL is only available in Apache 2.5.0 and
417 later.</compatibility>
420 <p>Specify the URL of the documentation describing the keepalive
421 policy, to appear within error messages.</p>
428 <name>PolicyType</name>
429 <description>Enable the content type policy.</description>
430 <syntax>PolicyType <var>ignore|log|enforce</var> <var>type</var> [ <var>type</var> [ ... ]]</syntax>
431 <default>ignore</default>
432 <contextlist><context>server config</context><context>virtual host</context>
433 <context>directory</context></contextlist>
434 <compatibility>PolicyType is only available in Apache 2.5.0 and
435 later.</compatibility>
438 <p>When logged or enforced, a response that lacks a <code>Content-Type</code>
439 header, where the <code>Content-Type</code> header is malformed, or where the
440 header does not match the given pattern or patterns will be rejected.</p>
442 <example><title>Example</title>
443 <highlight language="config">
444 # enforce json or XML
445 PolicyType enforce application/json text/xml
449 <example><title>Example</title>
450 <highlight language="config">
451 # malformed content type should be rejected
452 PolicyType enforce */*
462 <name>PolicyTypeURL</name>
463 <description>URL describing the content type policy.</description>
464 <syntax>PolicyTypeURL <var>url</var></syntax>
465 <default>none</default>
466 <contextlist><context>server config</context><context>virtual host</context>
467 <context>directory</context></contextlist>
468 <compatibility>PolicyTypeURL is only available in Apache 2.5.0 and
469 later.</compatibility>
472 <p>Specify the URL of the documentation describing the content type
473 policy, to appear within error messages.</p>
480 <name>PolicyVary</name>
481 <description>Enable the Vary policy.</description>
482 <syntax>PolicyVary <var>ignore|log|enforce</var> <var>header</var> [ <var>header</var> [ ... ]]</syntax>
483 <default>ignore</default>
484 <contextlist><context>server config</context><context>virtual host</context>
485 <context>directory</context></contextlist>
486 <compatibility>PolicyVary is only available in Apache 2.5.0 and
487 later.</compatibility>
490 <p>When logged or enforced, a response that contains a <code>Vary</code>
491 header which in turn contains one of the headers listed, will be
494 <example><title>Example</title>
495 <highlight language="config">
496 # reject reponses with "User-Agent" listed in the Vary header
497 PolicyVary enforce User-Agent
507 <name>PolicyVaryURL</name>
508 <description>URL describing the content type policy.</description>
509 <syntax>PolicyVaryURL <var>url</var></syntax>
510 <default>none</default>
511 <contextlist><context>server config</context><context>virtual host</context>
512 <context>directory</context></contextlist>
513 <compatibility>PolicyVaryURL is only available in Apache 2.5.0 and
514 later.</compatibility>
517 <p>Specify the URL of the documentation describing the vary policy, to
518 appear within error messages.</p>
525 <name>PolicyValidation</name>
526 <description>Enable the validation policy.</description>
527 <syntax>PolicyValidation <var>ignore|log|enforce</var></syntax>
528 <default>ignore</default>
529 <contextlist><context>server config</context><context>virtual host</context>
530 <context>directory</context></contextlist>
531 <compatibility>PolicyValidation is only available in Apache 2.5.0 and
532 later.</compatibility>
535 <p>When logged or enforced, a response that lacks either a valid
536 <code>ETag</code> header or a <code>Last-Modified</code> header, or where
537 either header is syntactically incorrect, will be rejected.</p>
539 <example><title>Example</title>
540 <highlight language="config">
541 # no ETag or Last-Modified will be rejected
542 PolicyValidation enforce
552 <name>PolicyValidationURL</name>
553 <description>URL describing the content type policy.</description>
554 <syntax>PolicyValidationURL <var>url</var></syntax>
555 <default>none</default>
556 <contextlist><context>server config</context><context>virtual host</context>
557 <context>directory</context></contextlist>
558 <compatibility>PolicyValidationURL is only available in Apache 2.5.0 and
559 later.</compatibility>
562 <p>Specify the URL of the documentation describing the validation policy, to
563 appear within error messages.</p>
570 <name>PolicyNocache</name>
571 <description>Enable the caching no-cache policy.</description>
572 <syntax>PolicyNocache <var>ignore|log|enforce</var></syntax>
573 <default>ignore</default>
574 <contextlist><context>server config</context><context>virtual host</context>
575 <context>directory</context></contextlist>
576 <compatibility>PolicyNocache is only available in Apache 2.5.0 and
577 later.</compatibility>
580 <p>When logged or enforced, a response that defines itself uncacheable
581 using the <code>Cache-Control</code> or <code>Pragma</code> headers will
584 <example><title>Example</title>
585 <highlight language="config">
586 # Cache-Control: no-cache will be rejected
587 PolicyNocache enforce
597 <name>PolicyNocacheURL</name>
598 <description>URL describing the caching no-cache policy.</description>
599 <syntax>PolicyNocacheURL <var>url</var></syntax>
600 <default>none</default>
601 <contextlist><context>server config</context><context>virtual host</context>
602 <context>directory</context></contextlist>
603 <compatibility>PolicyNocacheURL is only available in Apache 2.5.0 and
604 later.</compatibility>
607 <p>Specify the URL of the documentation describing the caching no-cache
608 policy, to appear within error messages.</p>
615 <name>PolicyMaxage</name>
616 <description>Enable the caching minimum max-age policy.</description>
617 <syntax>PolicyMaxage <var>ignore|log|enforce</var> <var>age</var></syntax>
618 <default>ignore</default>
619 <contextlist><context>server config</context><context>virtual host</context>
620 <context>directory</context></contextlist>
621 <compatibility>PolicyMaxage is only available in Apache 2.5.0 and
622 later.</compatibility>
625 <p>When logged or enforced, a response that lacks an explicit freshness
626 lifetime defined with <code>max-age</code>, <code>s-maxage</code> or an
627 <code>Expires</code> header, or where the explicit freshness lifetime is
628 smaller than the given value, will be rejected.</p>
630 <example><title>Example</title>
631 <highlight language="config">
632 # reject responses with a freshness lifetime shorter than a day
633 PolicyMaxage enforce 86400
643 <name>PolicyMaxageURL</name>
644 <description>URL describing the caching minimum freshness lifetime policy.</description>
645 <syntax>PolicyMaxageURL <var>url</var></syntax>
646 <default>none</default>
647 <contextlist><context>server config</context><context>virtual host</context>
648 <context>directory</context></contextlist>
649 <compatibility>PolicyMaxageURL is only available in Apache 2.5.0 and
650 later.</compatibility>
653 <p>Specify the URL of the documentation describing the caching minimum
654 freshness lifetime policy, to appear within error messages.</p>
661 <name>PolicyVersion</name>
662 <description>Enable the version policy.</description>
663 <syntax>PolicyVersion <var>ignore|log|enforce</var> <var>HTTP/0.9|HTTP/1.0|HTTP/1.1</var></syntax>
664 <default>ignore</default>
665 <contextlist><context>server config</context><context>virtual host</context>
666 <context>directory</context></contextlist>
667 <compatibility>PolicyVersion is only available in Apache 2.5.0 and
668 later.</compatibility>
671 <p>When logged or enforced, a request with a version lower than specified
672 will be rejected.</p>
674 <example><title>Example</title>
675 <highlight language="config">
676 # reject requests with an HTTP version older than HTTP/1.1
677 PolicyVersion enforce HTTP/1.1
687 <name>PolicyVersionURL</name>
688 <description>URL describing the minimum request HTTP version policy.</description>
689 <syntax>PolicyVersionURL <var>url</var></syntax>
690 <default>none</default>
691 <contextlist><context>server config</context><context>virtual host</context>
692 <context>directory</context></contextlist>
693 <compatibility>PolicyVersionURL is only available in Apache 2.5.0 and
694 later.</compatibility>
697 <p>Specify the URL of the documentation describing the minimum request
698 HTTP version policy, to appear within error messages.</p>