From: Christopher Faulet Date: Mon, 30 Nov 2026 14:15:15 +0000 (+0100) Subject: DOC: config: document the FCGI path handling and its security implications X-Git-Url: https://git.kaiwu.me/http/%22..//%22data:,/%22?a=commitdiff_plain;h=6d19ea0a74ef8e116cdbbcb88cf82be3c138d17f;p=haproxy.git DOC: config: document the FCGI path handling and its security implications Some users report the FCGI support as a security issue because the request path is URL-decoded and used to build the SCRIPT_NAME, SCRIPT_FILENAME, PATH_INFO and PATH_TRANSLATED parameters without any check: a path with '.' or '..' segments, or an absolute path, may point outside the document root, and if the FastCGI application executes the corresponding script, it may serve arbitrary files. This is intentional. HAProxy does not normalize request paths by default and passes them as-is, because only the component that will interpret the request reliably knows how to normalize its paths depending on its environment. 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. It is the application's responsibility to check the script it is asked to execute, exactly like for a web server, and it may also be handled by the administrator with http-request rules. To prevent the same question from being raised again, this is now clearly documented in a new section 10.4 'Path handling and security considerations', with a pointer from the docroot directive. No backport is needed. --- diff --git a/doc/configuration.txt b/doc/configuration.txt index b010dd90b..536457b00 100644 --- a/doc/configuration.txt +++ b/doc/configuration.txt @@ -136,6 +136,7 @@ Summary 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 @@ -32901,6 +32902,10 @@ docroot 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 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 @@ -32947,6 +32952,10 @@ path-info 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 @@ -33104,12 +33113,16 @@ applications. All these variables may be overwritten, with caution though. | | 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 | @@ -33133,6 +33146,8 @@ applications. All these variables may be overwritten, with caution though. +-------------------+-----------------------------------------------------+ | 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 | @@ -33195,6 +33210,56 @@ must not exceeds the size of a buffer. However, there is no reserve to respect 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 --------------------------