BUG/MINOR: http: make url_decode() optionally convert '+' to SP
authorWilly Tarreau <w@1wt.eu>
Thu, 23 Apr 2020 15:54:47 +0000 (17:54 +0200)
committerWilly Tarreau <w@1wt.eu>
Fri, 1 May 2020 10:12:15 +0000 (12:12 +0200)
commit3d2174ce029014525f1f9e1c58b13125b78ac39f
tree8c2e76c4898e7369eeae9042647d4165660063d5
parent9b09b3076c3e1f9bfafa68a830d9d3989b4d53a1
BUG/MINOR: http: make url_decode() optionally convert '+' to SP

The url_decode() function used by the url_dec converter and a few other
call points is ambiguous on its processing of the '+' character which
itself isn't stable in the spec. This one belongs to the reserved
characters for the query string but not for the path nor the scheme,
in which it must be left as-is. It's only in argument strings that
follow the application/x-www-form-urlencoded encoding that it must be
turned into a space, that is, in query strings and POST arguments.

The problem is that the function is used to process full URLs and
paths in various configs, and to process query strings from the stats
page for example.

This patch updates the function to differentiate the situation where
it's parsing a path and a query string. A new argument indicates if a
query string should be assumed, otherwise it's only assumed after seeing
a question mark.

The various locations in the code making use of this function were
updated to take care of this (most call places were using it to decode
POST arguments).

The url_dec converter is usually called on path or url samples, so it
needs to remain compatible with this and will default to parsing a path
and turning the '+' to a space only after a question mark. However in
situations where it would explicitly be extracted from a POST or a
query string, it now becomes possible to enforce the decoding by passing
a non-null value in argument.

It seems to be what was reported in issue #585. This fix may be
backported to older stable releases.

(cherry picked from commit 62ba9ba6ca259f45f7bd8de436b743b3ad9ac04a)
Signed-off-by: Willy Tarreau <w@1wt.eu>
contrib/prometheus-exporter/service-prometheus.c
doc/configuration.txt
include/common/standard.h
src/http_conv.c
src/mux_fcgi.c
src/standard.c
src/stats.c