From: Tim Duesterhus Date: Sat, 17 Apr 2021 09:21:10 +0000 (+0200) Subject: MEDIUM: http_act: Rename uri-normalizers X-Git-Tag: v2.4-dev17~87 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=5be6ab269e5606aef954f39d6717b024f97b3789;p=thirdparty%2Fhaproxy.git MEDIUM: http_act: Rename uri-normalizers This patch renames all existing uri-normalizers into a more consistent naming scheme: 1. The part of the URI that is being touched. 2. The modification being performed as an explicit verb. --- diff --git a/doc/configuration.txt b/doc/configuration.txt index 0ab4b7ab73..dae584307b 100644 --- a/doc/configuration.txt +++ b/doc/configuration.txt @@ -6012,18 +6012,18 @@ http-request early-hint [ { if | unless } ] See RFC 8297 for more information. http-request normalize-uri [ { if | unless } ] -http-request normalize-uri dotdot [ full ] [ { if | unless } ] -http-request normalize-uri merge-slashes [ { if | unless } ] -http-request normalize-uri percent-upper [ strict ] [ { if | unless } ] -http-request normalize-uri sort-query [ { if | unless } ] +http-request normalize-uri path-merge-slashes [ { if | unless } ] +http-request normalize-uri path-strip-dotdot [ full ] [ { if | unless } ] +http-request normalize-uri percent-to-uppercase [ strict ] [ { if | unless } ] +http-request normalize-uri query-sort-by-name [ { if | unless } ] Performs normalization of the request's URI. The following normalizers are available: - - dotdot: Normalizes "/../" segments within the "path" component. This merges - segments that attempt to access the parent directory with their preceding - segment. Empty segments do not receive special treatment. Use the - "merge-slashes" normalizer first if this is undesired. + - path-strip-dotdot: Normalizes "/../" segments within the "path" component. + This merges segments that attempt to access the parent directory with + their preceding segment. Empty segments do not receive special treatment. + Use the "path-merge-slashes" normalizer first if this is undesired. Example: - /foo/../ -> / @@ -6040,14 +6040,14 @@ http-request normalize-uri sort-query [ { if | unless } ] - /../bar/ -> /bar/ - /bar/../../ -> / - - merge-slashes: Merges adjacent slashes within the "path" component into a - single slash. + - path-merge-slashes: Merges adjacent slashes within the "path" component + into a single slash. Example: - // -> / - /foo//bar -> /foo/bar - - percent-upper: Uppercases letters within percent-encoded sequences + - percent-to-uppercase: Uppercases letters within percent-encoded sequences (RFC 3986#6.2.21). Example: @@ -6060,7 +6060,7 @@ http-request normalize-uri sort-query [ { if | unless } ] Example: - /%zz -> HTTP 400 - - sort-query: Sorts the query string parameters by parameter name. + - query-sort-by-name: Sorts the query string parameters by parameter name. Parameters are assumed to be delimited by '&'. Shorter names sort before longer names and identical parameter names maintain their relative order. diff --git a/include/haproxy/action-t.h b/include/haproxy/action-t.h index cce2a2e236..43e6b1addc 100644 --- a/include/haproxy/action-t.h +++ b/include/haproxy/action-t.h @@ -102,12 +102,12 @@ enum act_timeout_name { }; enum act_normalize_uri { - ACT_NORMALIZE_URI_MERGE_SLASHES, - ACT_NORMALIZE_URI_DOTDOT, - ACT_NORMALIZE_URI_DOTDOT_FULL, - ACT_NORMALIZE_URI_SORT_QUERY, - ACT_NORMALIZE_URI_PERCENT_UPPER, - ACT_NORMALIZE_URI_PERCENT_UPPER_STRICT, + ACT_NORMALIZE_URI_PATH_MERGE_SLASHES, + ACT_NORMALIZE_URI_PATH_STRIP_DOTDOT, + ACT_NORMALIZE_URI_PATH_STRIP_DOTDOT_FULL, + ACT_NORMALIZE_URI_QUERY_SORT_BY_NAME, + ACT_NORMALIZE_URI_PERCENT_TO_UPPERCASE, + ACT_NORMALIZE_URI_PERCENT_TO_UPPERCASE_STRICT, }; /* NOTE: if <.action_ptr> is defined, the referenced function will always be diff --git a/reg-tests/http-rules/normalize_uri.vtc b/reg-tests/http-rules/normalize_uri.vtc index e900677e93..b997b31b8b 100644 --- a/reg-tests/http-rules/normalize_uri.vtc +++ b/reg-tests/http-rules/normalize_uri.vtc @@ -17,11 +17,11 @@ haproxy h1 -conf { timeout client 1s timeout server 1s - frontend fe_merge_slashes - bind "fd@${fe_merge_slashes}" + frontend fe_path_merge_slashes + bind "fd@${fe_path_merge_slashes}" http-request set-var(txn.before) url - http-request normalize-uri merge-slashes + http-request normalize-uri path-merge-slashes http-request set-var(txn.after) url http-response add-header before %[var(txn.before)] @@ -29,15 +29,15 @@ haproxy h1 -conf { default_backend be - frontend fe_dotdot - bind "fd@${fe_dotdot}" + frontend fe_path_strip_dotdot + bind "fd@${fe_path_strip_dotdot}" http-request set-var(txn.before) url - http-request normalize-uri dotdot + http-request normalize-uri path-strip-dotdot http-request set-var(txn.after) url http-request set-uri %[var(txn.before)] - http-request normalize-uri dotdot full + http-request normalize-uri path-strip-dotdot full http-request set-var(txn.after_full) url http-response add-header before %[var(txn.before)] @@ -46,11 +46,11 @@ haproxy h1 -conf { default_backend be - frontend fe_sort_query - bind "fd@${fe_sort_query}" + frontend fe_sort_query_by_name + bind "fd@${fe_sort_query_by_name}" http-request set-var(txn.before) url - http-request normalize-uri sort-query + http-request normalize-uri query-sort-by-name http-request set-var(txn.after) url http-response add-header before %[var(txn.before)] @@ -58,11 +58,11 @@ haproxy h1 -conf { default_backend be - frontend fe_percent_upper - bind "fd@${fe_percent_upper}" + frontend fe_percent_to_uppercase + bind "fd@${fe_percent_to_uppercase}" http-request set-var(txn.before) url - http-request normalize-uri percent-upper + http-request normalize-uri percent-to-uppercase http-request set-var(txn.after) url http-response add-header before %[var(txn.before)] @@ -70,11 +70,11 @@ haproxy h1 -conf { default_backend be - frontend fe_percent_upper_strict - bind "fd@${fe_percent_upper_strict}" + frontend fe_percent_to_uppercase_strict + bind "fd@${fe_percent_to_uppercase_strict}" http-request set-var(txn.before) url - http-request normalize-uri percent-upper strict + http-request normalize-uri percent-to-uppercase strict http-request set-var(txn.after) url http-response add-header before %[var(txn.before)] @@ -87,7 +87,7 @@ haproxy h1 -conf { } -start -client c1 -connect ${h1_fe_merge_slashes_sock} { +client c1 -connect ${h1_fe_path_merge_slashes_sock} { txreq -url "/foo/bar" rxresp expect resp.http.before == "/foo/bar" @@ -139,7 +139,7 @@ client c1 -connect ${h1_fe_merge_slashes_sock} { expect resp.http.after == "*" } -run -client c2 -connect ${h1_fe_dotdot_sock} { +client c2 -connect ${h1_fe_path_strip_dotdot_sock} { txreq -url "/foo/bar" rxresp expect resp.http.before == "/foo/bar" @@ -207,7 +207,7 @@ client c2 -connect ${h1_fe_dotdot_sock} { expect resp.http.after-full == "*" } -run -client c3 -connect ${h1_fe_sort_query_sock} { +client c3 -connect ${h1_fe_sort_query_by_name_sock} { txreq -url "/?a=a" rxresp expect resp.http.before == "/?a=a" @@ -274,7 +274,7 @@ client c3 -connect ${h1_fe_sort_query_sock} { expect resp.http.after == "*" } -run -client c4 -connect ${h1_fe_percent_upper_sock} { +client c4 -connect ${h1_fe_percent_to_uppercase_sock} { txreq -url "/a?a=a" rxresp expect resp.http.before == "/a?a=a" @@ -297,7 +297,7 @@ client c4 -connect ${h1_fe_percent_upper_sock} { expect resp.http.after == "*" } -run -client c5 -connect ${h1_fe_percent_upper_strict_sock} { +client c5 -connect ${h1_fe_percent_to_uppercase_strict_sock} { txreq -url "/a?a=a" rxresp expect resp.http.before == "/a?a=a" diff --git a/src/http_act.c b/src/http_act.c index 06ecb9e052..aeb940fd5e 100644 --- a/src/http_act.c +++ b/src/http_act.c @@ -215,7 +215,7 @@ static enum act_return http_action_normalize_uri(struct act_rule *rule, struct p goto fail_alloc; switch ((enum act_normalize_uri) rule->action) { - case ACT_NORMALIZE_URI_MERGE_SLASHES: { + case ACT_NORMALIZE_URI_PATH_MERGE_SLASHES: { const struct ist path = http_get_path(uri); struct ist newpath = ist2(replace->area, replace->size); @@ -232,15 +232,15 @@ static enum act_return http_action_normalize_uri(struct act_rule *rule, struct p break; } - case ACT_NORMALIZE_URI_DOTDOT: - case ACT_NORMALIZE_URI_DOTDOT_FULL: { + case ACT_NORMALIZE_URI_PATH_STRIP_DOTDOT: + case ACT_NORMALIZE_URI_PATH_STRIP_DOTDOT_FULL: { const struct ist path = http_get_path(uri); struct ist newpath = ist2(replace->area, replace->size); if (!isttest(path)) goto leave; - err = uri_normalizer_path_dotdot(iststop(path, '?'), rule->action == ACT_NORMALIZE_URI_DOTDOT_FULL, &newpath); + err = uri_normalizer_path_dotdot(iststop(path, '?'), rule->action == ACT_NORMALIZE_URI_PATH_STRIP_DOTDOT_FULL, &newpath); if (err != URI_NORMALIZER_ERR_NONE) break; @@ -250,7 +250,7 @@ static enum act_return http_action_normalize_uri(struct act_rule *rule, struct p break; } - case ACT_NORMALIZE_URI_SORT_QUERY: { + case ACT_NORMALIZE_URI_QUERY_SORT_BY_NAME: { const struct ist path = http_get_path(uri); struct ist newquery = ist2(replace->area, replace->size); @@ -267,15 +267,15 @@ static enum act_return http_action_normalize_uri(struct act_rule *rule, struct p break; } - case ACT_NORMALIZE_URI_PERCENT_UPPER: - case ACT_NORMALIZE_URI_PERCENT_UPPER_STRICT: { + case ACT_NORMALIZE_URI_PERCENT_TO_UPPERCASE: + case ACT_NORMALIZE_URI_PERCENT_TO_UPPERCASE_STRICT: { const struct ist path = http_get_path(uri); struct ist newpath = ist2(replace->area, replace->size); if (!isttest(path)) goto leave; - err = uri_normalizer_percent_upper(path, rule->action == ACT_NORMALIZE_URI_PERCENT_UPPER_STRICT, &newpath); + err = uri_normalizer_percent_upper(path, rule->action == ACT_NORMALIZE_URI_PERCENT_TO_UPPERCASE_STRICT, &newpath); if (err != URI_NORMALIZER_ERR_NONE) break; @@ -345,40 +345,40 @@ static enum act_parse_ret parse_http_normalize_uri(const char **args, int *orig_ return ACT_RET_PRS_ERR; } - if (strcmp(args[cur_arg], "merge-slashes") == 0) { + if (strcmp(args[cur_arg], "path-merge-slashes") == 0) { cur_arg++; - rule->action = ACT_NORMALIZE_URI_MERGE_SLASHES; + rule->action = ACT_NORMALIZE_URI_PATH_MERGE_SLASHES; } - else if (strcmp(args[cur_arg], "dotdot") == 0) { + else if (strcmp(args[cur_arg], "path-strip-dotdot") == 0) { cur_arg++; if (strcmp(args[cur_arg], "full") == 0) { cur_arg++; - rule->action = ACT_NORMALIZE_URI_DOTDOT_FULL; + rule->action = ACT_NORMALIZE_URI_PATH_STRIP_DOTDOT_FULL; } else if (!*args[cur_arg]) { - rule->action = ACT_NORMALIZE_URI_DOTDOT; + rule->action = ACT_NORMALIZE_URI_PATH_STRIP_DOTDOT; } else if (strcmp(args[cur_arg], "if") != 0 && strcmp(args[cur_arg], "unless") != 0) { memprintf(err, "unknown argument '%s' for 'dotdot' normalizer", args[cur_arg]); return ACT_RET_PRS_ERR; } } - else if (strcmp(args[cur_arg], "sort-query") == 0) { + else if (strcmp(args[cur_arg], "query-sort-by-name") == 0) { cur_arg++; - rule->action = ACT_NORMALIZE_URI_SORT_QUERY; + rule->action = ACT_NORMALIZE_URI_QUERY_SORT_BY_NAME; } - else if (strcmp(args[cur_arg], "percent-upper") == 0) { + else if (strcmp(args[cur_arg], "percent-to-uppercase") == 0) { cur_arg++; if (strcmp(args[cur_arg], "strict") == 0) { cur_arg++; - rule->action = ACT_NORMALIZE_URI_PERCENT_UPPER_STRICT; + rule->action = ACT_NORMALIZE_URI_PERCENT_TO_UPPERCASE_STRICT; } else if (!*args[cur_arg]) { - rule->action = ACT_NORMALIZE_URI_PERCENT_UPPER; + rule->action = ACT_NORMALIZE_URI_PERCENT_TO_UPPERCASE; } else if (strcmp(args[cur_arg], "if") != 0 && strcmp(args[cur_arg], "unless") != 0) { memprintf(err, "unknown argument '%s' for 'percent-upper' normalizer", args[cur_arg]);