10.1.3. Example
10.2. Default parameters
10.3. Limitations
+10.4. Path handling and security considerations
11. Stick-tables and Peers
11.1. Stick-tables declaration
the default value of FastCGI parameters SCRIPT_FILENAME and
PATH_TRANSLATED. It is a mandatory setting.
+ Note that the request path is not checked against the document root when
+ these parameters are built. See section 10.4 about "Path handling and
+ security considerations" for details.
+
index <script-name>
Define the script name that will be appended after an URI that ends with a
slash ("/") to set the default value of the FastCGI parameter SCRIPT_NAME. It
of these two characters is found in the URL-decoded path, an error is
returned to the client. The principle of least astonishment is applied here.
+ See section 10.4 about "Path handling and security considerations" for
+ details about the way the URL-decoded path is used to fill the FastCGI
+ parameters.
+
Example :
path-info ^(/.+\.php)(/.*)?$ # both script-name and path-info may be set
path-info ^(/.+\.php) # the path-info is ignored
| | following the part that identifies the script |
| | itself. To be set, the directive "path-info" must |
| | be defined. |
+ | | See section 10.4 about "Path handling and security |
+ | | considerations". |
| | |
+-------------------+-----------------------------------------------------+
| PATH_TRANSLATED | If PATH_INFO is set, it is its translated version. |
| | It is the concatenation of DOCUMENT_ROOT and |
| | PATH_INFO. If PATH_INFO is not set, this parameters |
| | is not set too. |
+ | | See section 10.4 about "Path handling and security |
+ | | considerations". |
| | |
+-------------------+-----------------------------------------------------+
| QUERY_STRING | Contains the request's query string. It may not be |
+-------------------+-----------------------------------------------------+
| SCRIPT_FILENAME | Contains the absolute pathname of the script. it is |
| | the concatenation of DOCUMENT_ROOT and SCRIPT_NAME. |
+ | | See section 10.4 about "Path handling and security |
+ | | considerations". |
| | |
+-------------------+-----------------------------------------------------+
| SCRIPT_NAME | Contains the name of the script. If the directive |
here.
+10.4. Path handling and security considerations
+-----------------------------------------------
+
+To fill the FastCGI parameters SCRIPT_NAME, SCRIPT_FILENAME, PATH_INFO and
+PATH_TRANSLATED, HAProxy URL-decodes the request path and concatenates the
+document root with the result, without performing any other transformation
+on it. In particular, the decoded path is not normalized: the "." and ".."
+segments are not resolved, repeated slashes are not merged, and no check is
+done to make sure the resulting script name stays inside the document root.
+A request for "/../../etc/passwd" is thus passed to the application with a
+SCRIPT_FILENAME pointing outside the document root.
+
+This is intentional and it is the same principle as the one applied by HAProxy
+for the whole request processing: it does not normalize request paths by
+default (see section 7.5 about "Secure filtering of HTTP requests"). Only the
+component that will interpret the request, here the FastCGI application,
+reliably knows how to normalize its paths depending on its environment, and it
+is the only place where this can be done without breaking legitimate
+requests. HAProxy is not aware of the file system layout, the mount points or
+the symlinks on the remote host, so it cannot safely know if a path is finally
+inside or outside the document root. For instance, what appears to be an escape
+from the document root may well be a symlink back into it, and a blindly
+normalized path may point to a different resource than the one the application
+would have resolved.
+
+Consequently, executing a script must never be decided based on the script
+name alone. A FastCGI application is responsible for checking that the script
+it is asked to execute is permitted, exactly like a web server is responsible
+for this when it executes scripts itself. Most FastCGI applications already
+do it properly, by refusing to serve a path that escapes the document root.
+HAProxy is not a web server and must not be considered as a guard against
+misconfigured applications.
+
+When HAProxy must restrict the requests sent to an application, it must be
+done explicitly, with "http-request" rules performing positive matches with
+a default deny, as explained in section 7.5. For instance, the "path-info"
+regular expression can help to restrict the script name to a well-known
+extension, and a rule such as the following will refuse any request whose
+path does not contain a script name ending with ".php":
+
+ http-request deny unless { path_reg ^/.+\.php(/.*)?$ }
+
+If the requests must be normalized or filtered on their decoded form, the
+same precautions as for any other rewriting apply: only the administrator
+can decide, depending on the application behind, what is safe to rewrite or
+to reject, and what is not. For this purpose, the "normalize-uri" directives
+and the "url_dec" converter may be used with care. But it remains the
+application's responsibility to guarantee its own security, and the HAProxy
+rules are only a complement, never a replacement.
+
11. Stick-tables and Peers
--------------------------