From: Willy Tarreau Date: Tue, 24 Nov 2026 10:12:19 +0000 (+0100) Subject: MINOR: http: add -dH at boot to dump HTTP specific settings X-Git-Url: https://git.kaiwu.me/http/ngx_http_log_module.html?a=commitdiff_plain;h=aa6d03899746e0c86f2d0986bf80fd826d2c4196;p=haproxy.git MINOR: http: add -dH at boot to dump HTTP specific settings The new -dH option will dump HTTP specific settings is supported is -dHall (alias for -dH and lists all info), -dHhelp (which lists all available settings), and -dHharden (which dumps HTTP hardening profiles and their default values). The doc was clarified on where the default values come from, and how to get such information. This should address github issue #3606. Thanks to Nick Ramirez for bringing this topic. --- diff --git a/doc/configuration.txt b/doc/configuration.txt index b8ca23b9b..3f04d3483 100644 --- a/doc/configuration.txt +++ b/doc/configuration.txt @@ -35009,17 +35009,53 @@ section). Since the same profile may be used on either side, controls are expressed relative to the traffic received or sent by that side, and never in terms of requests or responses. -http-hardening [from ] +http-hardening [from ] Declares a new hardening profile . A profile can only be declared once. - The name "auto" is reserved. When "from" is used, the profile starts with the - settings of the already declared profile , otherwise it starts with - the defaults. A profile must be declared before being referenced by a "bind" - or "server" line or by "from", like for "defaults" sections. - - The profiles "untrusted" and "trusted" always exist even if never declared. - They may be declared once to change their settings, in which case they start - from their defaults. They are supported in "from" to create new profiles. The - reserved name "auto" may not be defined nor used in "from". + The name "auto" is reserved and may neither be defined nor referenced as a + source in "from". When "from" is used, the profile starts with the settings + of the already existing profile , otherwise it starts with the + defaults. A profile must be declared before being referenced by a "bind" or + "server" line or by "from", like for "defaults" sections. + + The profiles "untrusted" and "trusted" always exist and are preset to their + respective default values so that they don't need to be declared for most + common use cases. Their default settings (the list of on/off controls) may be + displayed at boot time by passing "-dHharden" on the command line, and should + reflect the following values: + + http-hardening trusted + all off + + http-hardening untrusted + reject-duplicate-host-header off + reject-lowercase-method on + reject-underscore-in-header-name off + reject-underscore-in-trailer-name off + delete-underscore-in-header-name on + delete-underscore-in-trailer-name on + delete-unregistered-header-fields off + delete-unregistered-trailer-fields off + delete-all-trailer-fields off + reject-header-trailer-folding on + reject-ctl-in-header-trailer on + reject-content-length-with-te on + reject-content-length-leading-zero on + reject-duplicate-content-length on + reject-forbidden-payload on + reject-out-of-range-status on + + It is possible to change their settings from the defaults, by declaring the + profiles once, along with the settings to change, in which case they will + inherit from their defaults first. They may even be declared with a "from" + keyword to ignore their defaults and start from another profile instead, + including one of them. For example, in order to simply apply all "untrusted" + settings to the "trusted" profile, just do this: + + http-hardening trusted from untrusted + + Like other profiles, they are supported as sources in "from" to create new + profiles. All enabled hardening profiles' settings may be consulted at run + time using "show http-hardening" on the CLI. { on | off } Enables or disables the hardening check designated by in the diff --git a/doc/management.txt b/doc/management.txt index 0b24df2f1..c9708df5e 100644 --- a/doc/management.txt +++ b/doc/management.txt @@ -265,6 +265,10 @@ list of options is : getaddrinfo() exist on various systems and cause anomalies that are difficult to troubleshoot. + -dH[[,...]] : dump HTTP specific settings. It can be used to dump HTTP + hardening profiles using "-dHharden", all HTTP information using "-dHall", + or help about other HTTP specific information using "-dHhelp". + -dI : enable the insecure fork. This is the equivalent of the "insecure-fork-wanted" in the global section. It can be useful when running all the reg-tests with ASAN which need to fork addr2line to resolve the diff --git a/include/haproxy/http.h b/include/haproxy/http.h index 8ff8327bf..a4c7baa95 100644 --- a/include/haproxy/http.h +++ b/include/haproxy/http.h @@ -84,6 +84,7 @@ int http_compare_etags(struct ist etag1, struct ist etag2); struct ist http_trim_leading_spht(struct ist value); struct ist http_trim_trailing_spht(struct ist value); +void http_dump_settings(const char *what); /* * Given a path string and its length, find the position of beginning of the diff --git a/src/haproxy.c b/src/haproxy.c index 146ea0160..c5f44ddf1 100644 --- a/src/haproxy.c +++ b/src/haproxy.c @@ -795,6 +795,7 @@ static void usage(char *name) #if defined(USE_CPU_AFFINITY) " -dc dumps the list of selected and evicted CPUs\n" #endif + " -dH{class[,...]} dump HTTP settings\n" " -dK{class[,...]} dump registered keywords (use 'help' for list)\n" " -dr ignores server address resolution failures\n" " -dV disables SSL verify on servers side\n" @@ -1653,6 +1654,9 @@ void haproxy_init_args(int argc, char **argv) } # endif /* HA_HAVE_DL_ITERATE_PHDR */ #endif + else if (*flag == 'd' && flag[1] == 'H') { + http_dump_settings(flag + 2); + } else if (*flag == 'd' && flag[1] == 'K') { arg_mode |= MODE_DUMP_KWD; kwd_dump = flag + 2; diff --git a/src/http.c b/src/http.c index 56b3da6d5..1809b452c 100644 --- a/src/http.c +++ b/src/http.c @@ -2331,6 +2331,68 @@ static int http_parse_http_err_fail_codes(char **args, int section_type, struct } +/* dump various HTTP settings to stdout, used by -dH on the cmdline. Supports + * a comma-delimited list of classes, dumps everything by default. + */ +void http_dump_settings(const char *what) +{ + const char *end; + int all = 0; + + if (!*what) { + /* empty: dump everything */ + what = "*"; + all = 1; + } + + for (; what && *what; what = end) { + end = strchr(what, ','); + if (!end) + end = what + strlen(what); + + if (strncmp(what, "help", end - what) == 0) { + printf("# List of supported HTTP classes:\n"); + printf("harden: list all hardening profiles\n"); + continue; + } + else if (strncmp(what, "all", end - what) == 0) { + all = 1; + } + + if (all || strncmp(what, "harden", end - what) == 0) { + const struct http_hardening_kw *kw; + int len, max; + + printf("# List of HTTP hardening profiles, and default settings:\n"); + + len = max = 0; + for (kw = http_hardening_kws; kw->name; kw++) { + len = strlen(kw->name); + max = len > max ? len : max; + } + max += 2; + + printf("http-hardening trusted\n"); + if (!HTTP_HRD_TRUSTED_DEFAULT) + printf("\tall off\n"); + else for (kw = http_hardening_kws; kw->name; kw++) { + // only report single bit flags + if (!(kw->mask & (kw->mask - 1))) + printf("\t%-*s %s\n", max, kw->name, (kw->mask & HTTP_HRD_TRUSTED_DEFAULT) ? "on" : "off"); + } + + printf("\nhttp-hardening untrusted\n"); + if (!HTTP_HRD_UNTRUSTED_DEFAULT) + printf("\tall off\n"); + else for (kw = http_hardening_kws; kw->name; kw++) { + // only report single bit flags + if (!(kw->mask & (kw->mask - 1))) + printf("\t%-*s %s\n", max, kw->name, (kw->mask & HTTP_HRD_UNTRUSTED_DEFAULT) ? "on" : "off"); + } + } + } +} + static struct cfg_kw_list cfg_kws = {{ },{ { CFG_GLOBAL, "http-err-codes", http_parse_http_err_fail_codes }, { CFG_GLOBAL, "http-fail-codes", http_parse_http_err_fail_codes },