]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: mux-fcgi: Make the capture of the path-info optional in pathinfo regex
authorChristopher Faulet <cfaulet@haproxy.com>
Fri, 14 Feb 2020 15:55:52 +0000 (16:55 +0100)
committerChristopher Faulet <cfaulet@haproxy.com>
Fri, 14 Feb 2020 17:31:29 +0000 (18:31 +0100)
Now, only one capture is mandatory in the path-info regex, the one matching the
script-name. The path-info capture is optional. Of couse, it must be defined to
fill the PATH_INFO parameter. But it is not mandatory. This way, it is possible
to get the script-name part from the path, excluding the path-info.

This patch is small enough to be backported to 2.1.

doc/configuration.txt
src/mux_fcgi.c

index f2124db95edb14b1c01d056452ef616cf03ac559..aa4826fc2d13f1edf08ce9942606a25f451c1c82 100644 (file)
@@ -18727,10 +18727,13 @@ pass-header <name> [ { if | unless } <condition> ]
 
 path-info <regex>
   Define a regular expression to extract the script-name and the path-info from
-  the URL-decoded path. Thus, <regex> should have two captures: the first one
-  to capture the script name and the second one to capture the path-info. It is
-  an optional setting. If it is not defined, no matching is performed on the
-  path. and the FastCGI parameters PATH_INFO and PATH_TRANSLATED are not filled.
+  the URL-decoded path. Thus, <regex> may have two captures: the first one to
+  capture the script name and the second one to capture the path-info. The
+  first one is mandatory, the second one is optional. This way, it is possible
+  to extract the script-name from the path ignoring the path-info. It is an
+  optional setting. If it is not defined, no matching is performed on the
+  path. and the FastCGI parameters PATH_INFO and PATH_TRANSLATED are not
+  filled.
 
   For security reason, when this regular expression is defined, the newline and
   the null characters are forbiden from the path, once URL-decoded. The reason
@@ -18740,7 +18743,8 @@ path-info <regex>
   returned to the client. The principle of least astonishment is applied here.
 
   Example :
-     path-info ^(/.+\.php)(/.*)?$
+     path-info ^(/.+\.php)(/.*)?$ # both script-name and path-info may be set
+     path-info ^(/.+\.php)        # the path-info is ignored
 
 option get-values
 no option get-values
index 12d29d6863ae0289e2676eea02a9201c96c153a0..27f5edce0c30171d57875705ac2b3363733a8e3e 100644 (file)
@@ -1360,16 +1360,19 @@ static int fcgi_set_default_param(struct fcgi_conn *fconn, struct fcgi_strm *fst
                if (!regex_exec_match2(fconn->app->pathinfo_re, path.ptr, len, MAX_MATCH, pmatch, 0))
                        goto check_index;
 
-               /* We must have at least 2 captures, otherwise we do nothing and
-                * jump to the last part. Only first 2 ones will be considered
+               /* We must have at least 1 capture for the script name,
+                * otherwise we do nothing and jump to the last part.
                 */
-               if (pmatch[1].rm_so == -1 || pmatch[1].rm_eo == -1 ||
-                   pmatch[2].rm_so == -1 || pmatch[2].rm_eo == -1)
+               if (pmatch[1].rm_so == -1 || pmatch[1].rm_eo == -1)
                        goto check_index;
 
-               /* Finally we can set the script_name and the path_info */
+               /* Finally we can set the script_name and the path_info. The
+                * path_info is set if not already defined, and if it was
+                * captured
+                */
                params->scriptname = ist2(path.ptr + pmatch[1].rm_so, pmatch[1].rm_eo - pmatch[1].rm_so);
-               params->pathinfo   = ist2(path.ptr + pmatch[2].rm_so, pmatch[2].rm_eo - pmatch[2].rm_so);
+               if (!(params->mask & FCGI_SP_PATH_INFO) &&  (pmatch[2].rm_so == -1 || pmatch[2].rm_eo == -1))
+                       params->pathinfo = ist2(path.ptr + pmatch[2].rm_so, pmatch[2].rm_eo - pmatch[2].rm_so);
 
          check_index:
                len = params->scriptname.len;