]> git.kaiwu.me - haproxy.git/commitdiff
MINOR: http: add -dH at boot to dump HTTP specific settings
authorWilly Tarreau <w@1wt.eu>
Tue, 24 Nov 2026 10:12:19 +0000 (11:12 +0100)
committerWilly Tarreau <w@1wt.eu>
Tue, 24 Nov 2026 12:56:46 +0000 (13:56 +0100)
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.

doc/configuration.txt
doc/management.txt
include/haproxy/http.h
src/haproxy.c
src/http.c

index b8ca23b9bbc3f4a792f5bd257bc87767af169f72..3f04d348366b0d5d61a57688215fbf2bee2a9fbf 100644 (file)
@@ -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 <name> [from <name2>]
+http-hardening <name> [from <source>]
   Declares a new hardening profile <name>. 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 <name2>, 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 <source>, 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.
 
 <keyword> { on | off }
   Enables or disables the hardening check designated by <keyword> in the
index 0b24df2f1460ed41f7294c55c3fec8f1388c4017..c9708df5e8ae4cf657eb656563ec3ca074e10f64 100644 (file)
@@ -265,6 +265,10 @@ list of options is :
     getaddrinfo() exist on various systems and cause anomalies that are
     difficult to troubleshoot.
 
+  -dH[<class>[,...]] : 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
index 8ff8327bf5f14cec962d91eba4e71095d78a9e12..a4c7baa9547a9616f96aac13db6f55f4fbf23161 100644 (file)
@@ -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
index 146ea0160b8e9db6cc70bed8060e2e9aedd24f6a..c5f44ddf14743e877427efc86b22dd1b7862b310 100644 (file)
@@ -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;
index 56b3da6d5854c87c6964567439850861ae1bb02b..1809b452c9fae077425174b8ed61db7913faafcd 100644 (file)
@@ -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 },