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.
This commit is contained in:
Tim Duesterhus 2021-04-17 11:21:10 +02:00 committed by Christopher Faulet
parent a407193376
commit 5be6ab269e
4 changed files with 57 additions and 57 deletions

View File

@ -6012,18 +6012,18 @@ http-request early-hint <name> <fmt> [ { if | unless } <condition> ]
See RFC 8297 for more information. See RFC 8297 for more information.
http-request normalize-uri <normalizer> [ { if | unless } <condition> ] http-request normalize-uri <normalizer> [ { if | unless } <condition> ]
http-request normalize-uri dotdot [ full ] [ { if | unless } <condition> ] http-request normalize-uri path-merge-slashes [ { if | unless } <condition> ]
http-request normalize-uri merge-slashes [ { if | unless } <condition> ] http-request normalize-uri path-strip-dotdot [ full ] [ { if | unless } <condition> ]
http-request normalize-uri percent-upper [ strict ] [ { if | unless } <condition> ] http-request normalize-uri percent-to-uppercase [ strict ] [ { if | unless } <condition> ]
http-request normalize-uri sort-query [ { if | unless } <condition> ] http-request normalize-uri query-sort-by-name [ { if | unless } <condition> ]
Performs normalization of the request's URI. The following normalizers are Performs normalization of the request's URI. The following normalizers are
available: available:
- dotdot: Normalizes "/../" segments within the "path" component. This merges - path-strip-dotdot: Normalizes "/../" segments within the "path" component.
segments that attempt to access the parent directory with their preceding This merges segments that attempt to access the parent directory with
segment. Empty segments do not receive special treatment. Use the their preceding segment. Empty segments do not receive special treatment.
"merge-slashes" normalizer first if this is undesired. Use the "path-merge-slashes" normalizer first if this is undesired.
Example: Example:
- /foo/../ -> / - /foo/../ -> /
@ -6040,14 +6040,14 @@ http-request normalize-uri sort-query [ { if | unless } <condition> ]
- /../bar/ -> /bar/ - /../bar/ -> /bar/
- /bar/../../ -> / - /bar/../../ -> /
- merge-slashes: Merges adjacent slashes within the "path" component into a - path-merge-slashes: Merges adjacent slashes within the "path" component
single slash. into a single slash.
Example: Example:
- // -> / - // -> /
- /foo//bar -> /foo/bar - /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). (RFC 3986#6.2.21).
Example: Example:
@ -6060,7 +6060,7 @@ http-request normalize-uri sort-query [ { if | unless } <condition> ]
Example: Example:
- /%zz -> HTTP 400 - /%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 Parameters are assumed to be delimited by '&'. Shorter names sort before
longer names and identical parameter names maintain their relative order. longer names and identical parameter names maintain their relative order.

View File

@ -102,12 +102,12 @@ enum act_timeout_name {
}; };
enum act_normalize_uri { enum act_normalize_uri {
ACT_NORMALIZE_URI_MERGE_SLASHES, ACT_NORMALIZE_URI_PATH_MERGE_SLASHES,
ACT_NORMALIZE_URI_DOTDOT, ACT_NORMALIZE_URI_PATH_STRIP_DOTDOT,
ACT_NORMALIZE_URI_DOTDOT_FULL, ACT_NORMALIZE_URI_PATH_STRIP_DOTDOT_FULL,
ACT_NORMALIZE_URI_SORT_QUERY, ACT_NORMALIZE_URI_QUERY_SORT_BY_NAME,
ACT_NORMALIZE_URI_PERCENT_UPPER, ACT_NORMALIZE_URI_PERCENT_TO_UPPERCASE,
ACT_NORMALIZE_URI_PERCENT_UPPER_STRICT, ACT_NORMALIZE_URI_PERCENT_TO_UPPERCASE_STRICT,
}; };
/* NOTE: if <.action_ptr> is defined, the referenced function will always be /* NOTE: if <.action_ptr> is defined, the referenced function will always be

View File

@ -17,11 +17,11 @@ haproxy h1 -conf {
timeout client 1s timeout client 1s
timeout server 1s timeout server 1s
frontend fe_merge_slashes frontend fe_path_merge_slashes
bind "fd@${fe_merge_slashes}" bind "fd@${fe_path_merge_slashes}"
http-request set-var(txn.before) url 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-request set-var(txn.after) url
http-response add-header before %[var(txn.before)] http-response add-header before %[var(txn.before)]
@ -29,15 +29,15 @@ haproxy h1 -conf {
default_backend be default_backend be
frontend fe_dotdot frontend fe_path_strip_dotdot
bind "fd@${fe_dotdot}" bind "fd@${fe_path_strip_dotdot}"
http-request set-var(txn.before) url 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-var(txn.after) url
http-request set-uri %[var(txn.before)] 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-request set-var(txn.after_full) url
http-response add-header before %[var(txn.before)] http-response add-header before %[var(txn.before)]
@ -46,11 +46,11 @@ haproxy h1 -conf {
default_backend be default_backend be
frontend fe_sort_query frontend fe_sort_query_by_name
bind "fd@${fe_sort_query}" bind "fd@${fe_sort_query_by_name}"
http-request set-var(txn.before) url 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-request set-var(txn.after) url
http-response add-header before %[var(txn.before)] http-response add-header before %[var(txn.before)]
@ -58,11 +58,11 @@ haproxy h1 -conf {
default_backend be default_backend be
frontend fe_percent_upper frontend fe_percent_to_uppercase
bind "fd@${fe_percent_upper}" bind "fd@${fe_percent_to_uppercase}"
http-request set-var(txn.before) url 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-request set-var(txn.after) url
http-response add-header before %[var(txn.before)] http-response add-header before %[var(txn.before)]
@ -70,11 +70,11 @@ haproxy h1 -conf {
default_backend be default_backend be
frontend fe_percent_upper_strict frontend fe_percent_to_uppercase_strict
bind "fd@${fe_percent_upper_strict}" bind "fd@${fe_percent_to_uppercase_strict}"
http-request set-var(txn.before) url 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-request set-var(txn.after) url
http-response add-header before %[var(txn.before)] http-response add-header before %[var(txn.before)]
@ -87,7 +87,7 @@ haproxy h1 -conf {
} -start } -start
client c1 -connect ${h1_fe_merge_slashes_sock} { client c1 -connect ${h1_fe_path_merge_slashes_sock} {
txreq -url "/foo/bar" txreq -url "/foo/bar"
rxresp rxresp
expect resp.http.before == "/foo/bar" expect resp.http.before == "/foo/bar"
@ -139,7 +139,7 @@ client c1 -connect ${h1_fe_merge_slashes_sock} {
expect resp.http.after == "*" expect resp.http.after == "*"
} -run } -run
client c2 -connect ${h1_fe_dotdot_sock} { client c2 -connect ${h1_fe_path_strip_dotdot_sock} {
txreq -url "/foo/bar" txreq -url "/foo/bar"
rxresp rxresp
expect resp.http.before == "/foo/bar" expect resp.http.before == "/foo/bar"
@ -207,7 +207,7 @@ client c2 -connect ${h1_fe_dotdot_sock} {
expect resp.http.after-full == "*" expect resp.http.after-full == "*"
} -run } -run
client c3 -connect ${h1_fe_sort_query_sock} { client c3 -connect ${h1_fe_sort_query_by_name_sock} {
txreq -url "/?a=a" txreq -url "/?a=a"
rxresp rxresp
expect resp.http.before == "/?a=a" expect resp.http.before == "/?a=a"
@ -274,7 +274,7 @@ client c3 -connect ${h1_fe_sort_query_sock} {
expect resp.http.after == "*" expect resp.http.after == "*"
} -run } -run
client c4 -connect ${h1_fe_percent_upper_sock} { client c4 -connect ${h1_fe_percent_to_uppercase_sock} {
txreq -url "/a?a=a" txreq -url "/a?a=a"
rxresp rxresp
expect resp.http.before == "/a?a=a" expect resp.http.before == "/a?a=a"
@ -297,7 +297,7 @@ client c4 -connect ${h1_fe_percent_upper_sock} {
expect resp.http.after == "*" expect resp.http.after == "*"
} -run } -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" txreq -url "/a?a=a"
rxresp rxresp
expect resp.http.before == "/a?a=a" expect resp.http.before == "/a?a=a"

View File

@ -215,7 +215,7 @@ static enum act_return http_action_normalize_uri(struct act_rule *rule, struct p
goto fail_alloc; goto fail_alloc;
switch ((enum act_normalize_uri) rule->action) { 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); const struct ist path = http_get_path(uri);
struct ist newpath = ist2(replace->area, replace->size); 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; break;
} }
case ACT_NORMALIZE_URI_DOTDOT: case ACT_NORMALIZE_URI_PATH_STRIP_DOTDOT:
case ACT_NORMALIZE_URI_DOTDOT_FULL: { case ACT_NORMALIZE_URI_PATH_STRIP_DOTDOT_FULL: {
const struct ist path = http_get_path(uri); const struct ist path = http_get_path(uri);
struct ist newpath = ist2(replace->area, replace->size); struct ist newpath = ist2(replace->area, replace->size);
if (!isttest(path)) if (!isttest(path))
goto leave; 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) if (err != URI_NORMALIZER_ERR_NONE)
break; break;
@ -250,7 +250,7 @@ static enum act_return http_action_normalize_uri(struct act_rule *rule, struct p
break; break;
} }
case ACT_NORMALIZE_URI_SORT_QUERY: { case ACT_NORMALIZE_URI_QUERY_SORT_BY_NAME: {
const struct ist path = http_get_path(uri); const struct ist path = http_get_path(uri);
struct ist newquery = ist2(replace->area, replace->size); 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; break;
} }
case ACT_NORMALIZE_URI_PERCENT_UPPER: case ACT_NORMALIZE_URI_PERCENT_TO_UPPERCASE:
case ACT_NORMALIZE_URI_PERCENT_UPPER_STRICT: { case ACT_NORMALIZE_URI_PERCENT_TO_UPPERCASE_STRICT: {
const struct ist path = http_get_path(uri); const struct ist path = http_get_path(uri);
struct ist newpath = ist2(replace->area, replace->size); struct ist newpath = ist2(replace->area, replace->size);
if (!isttest(path)) if (!isttest(path))
goto leave; 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) if (err != URI_NORMALIZER_ERR_NONE)
break; break;
@ -345,40 +345,40 @@ static enum act_parse_ret parse_http_normalize_uri(const char **args, int *orig_
return ACT_RET_PRS_ERR; return ACT_RET_PRS_ERR;
} }
if (strcmp(args[cur_arg], "merge-slashes") == 0) { if (strcmp(args[cur_arg], "path-merge-slashes") == 0) {
cur_arg++; 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++; cur_arg++;
if (strcmp(args[cur_arg], "full") == 0) { if (strcmp(args[cur_arg], "full") == 0) {
cur_arg++; cur_arg++;
rule->action = ACT_NORMALIZE_URI_DOTDOT_FULL; rule->action = ACT_NORMALIZE_URI_PATH_STRIP_DOTDOT_FULL;
} }
else if (!*args[cur_arg]) { 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) { 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]); memprintf(err, "unknown argument '%s' for 'dotdot' normalizer", args[cur_arg]);
return ACT_RET_PRS_ERR; 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++; 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++; cur_arg++;
if (strcmp(args[cur_arg], "strict") == 0) { if (strcmp(args[cur_arg], "strict") == 0) {
cur_arg++; cur_arg++;
rule->action = ACT_NORMALIZE_URI_PERCENT_UPPER_STRICT; rule->action = ACT_NORMALIZE_URI_PERCENT_TO_UPPERCASE_STRICT;
} }
else if (!*args[cur_arg]) { 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) { 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]); memprintf(err, "unknown argument '%s' for 'percent-upper' normalizer", args[cur_arg]);