]> git.kaiwu.me - haproxy.git/commitdiff
MINOR: http/hardening: add a new more protective "basic-web" profile
authorWilly Tarreau <w@1wt.eu>
Wed, 25 Nov 2026 17:32:57 +0000 (18:32 +0100)
committerWilly Tarreau <w@1wt.eu>
Wed, 25 Nov 2026 18:31:09 +0000 (19:31 +0100)
This profile enables all the protections that are sufficient for basic
web serving to browsers, i.e. no payload with methods not meant to
support one, no tunnels, no unknown upgrade tokens, no transfer-encoding
in requests, no unregistered headers, no trailers. It should be sufficient
for the vast majority of web sites and can trivially be enabled like this
on public-facing connections:

    http-hardening untrusted from basic-web

http_hardening_profiles.vtc was updated accordingly since "basic-web" now
appears in the "show http-hardening" listings, as implicit when not
declared.

doc/configuration.txt
include/haproxy/http-t.h
reg-tests/http-messaging/http_hardening_profiles.vtc
src/http.c

index 6c6a16d657e5e0fc40f2ba93d88f2a8e1dced576..9fa20b04ddbba88f9d828a8d003ad9f95d0b991d 100644 (file)
@@ -35034,34 +35034,56 @@ http-hardening <name> [from <source>]
   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:
+  The profiles "basic-web", "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-advanced-methods off
-        reject-unexpected-request-payload off
-        reject-unexpected-request-upgrade off
+        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
+        reject-advanced-methods              off
+        reject-unexpected-request-payload    off
+        reject-unexpected-request-upgrade    off
+
+    http-hardening basic-web
+        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    on
+        delete-unregistered-trailer-fields   on
+        delete-all-trailer-fields            on
+        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
+        reject-advanced-methods              on
+        reject-unexpected-request-payload    on
+        reject-unexpected-request-upgrade    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
@@ -35072,6 +35094,12 @@ http-hardening <name> [from <source>]
 
     http-hardening trusted from untrusted
 
+  The following will simply configure all untrusted connections to follow the
+  "basic-web" profile, and apply a high protection level by default that is
+  suitable for most applications :
+
+    http-hardening untrusted from basic-web
+
   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.
@@ -35167,7 +35195,8 @@ http-hardening <name> [from <source>]
         attack attempts. It is generally safe to drop them by default on public
         facing listeners, and even on servers meant to deliver public contents,
         in order to avoid any information leakage. Note that gRPC services use
-        them, in responses only.
+        them, in responses only. It is enabled by default in the "basic-web"
+        profile.
 
   - delete-underscore-in-header-name (inbound, request and response)
         Deletes from requests and responses any header field whose name
@@ -35178,7 +35207,8 @@ http-hardening <name> [from <source>]
         the same variable name. This could be abused to bypass some
         access-control policy for example. No standard HTTP header uses this,
         so it is recommended to enable on untrusted listeners. Note that this
-        applies only after "reject-underscore-in-header-name" was accepted.
+        applies only after "reject-underscore-in-header-name" was accepted. It
+        is enabled by default in the "basic-web" profile.
 
   - delete-underscore-in-trailer-name (inbound, request and response)
         Deletes from requests and responses any trailer field whose name
@@ -35188,7 +35218,8 @@ http-hardening <name> [from <source>]
         names, leading to an ambiguity with the underscore which can result in
         the same variable name. No standard HTTP trailer uses this, so it is
         recommended to enable on untrusted listeners. Note that this applies
-        only after "reject-underscore-in-trailer-name" was accepted.
+        only after "reject-underscore-in-trailer-name" was accepted. It is
+        enabled by default in the "basic-web" profile.
 
   - delete-unregistered-header-fields (inbound, request and response)
         Deletes from requests and responses any header field whose name starts
@@ -35200,7 +35231,8 @@ http-hardening <name> [from <source>]
         would be risky to block such requests, it is safe and even recommended
         to delete such headers from inbound internet requests. It is preferable
         not to do it on responses however when applications uses such header
-        fields to report information to HAProxy.
+        fields to report information to HAProxy. It is enabled by default in the
+        "basic-web" profile.
 
   - delete-unregistered-trailer-fields (inbound, request and response)
         Deletes from requests and responses any trailer field whose name starts
@@ -35209,7 +35241,7 @@ http-hardening <name> [from <source>]
         components. They may appear in untrusted requests in attacks trying to
         exploit some backend framework weaknesses however, so it is generally
         safe and even recommended to delete such trailers from inbound internet
-        requests.
+        requests. It is enabled by default in the "basic-web" profile.
 
   - reject-advanced-methods (inbound, request)
         Rejects requests whose method is not one of: HEAD, GET, POST, PUT,
@@ -35232,7 +35264,8 @@ http-hardening <name> [from <source>]
         communication, and for example for cache poisionning attacks. These may
         seldom be seen on legacy applications but not on standard components
         found on the internet, so it is generally safe to reject them on public
-        facing listeners. It is enabled by default on untrusted connections.
+        facing listeners. It is enabled by default on untrusted connections and
+        in the "basic-web" profile.
 
   - reject-content-length-with-te (inbound request and response)
         Rejects requests and responses having both a Content-Length header
@@ -35244,7 +35277,7 @@ http-hardening <name> [from <source>]
         client or server applications, sometimes in relation with compression
         and/or caching. While HAProxy properly normalizes them, it is generally
         safe to reject them on public facing listeners. It is enabled by
-        default on untrusted connections.
+        default on untrusted connections and in the "basic-web" profile.
 
   - reject-ctl-in-header-trailer (inbound request and response)
         Rejects requests and responses which contain control characters in
@@ -35257,7 +35290,8 @@ http-hardening <name> [from <source>]
         which can make certain backend applications trigger connection errors.
         As such, it is both safe and recommended to block them on public facing
         listeners. See also the has_ctl() converter used for detecting them.
-        It is enabled by default on untrusted connections.
+        It is enabled by default on untrusted connections and in the
+        "basic-web" profile.
 
   - reject-duplicate-content-length (inbound request and response)
         Rejects requests and responses having a duplicate Content-Length header
@@ -35268,7 +35302,7 @@ http-hardening <name> [from <source>]
         server applications, sometimes in relation with compression and/or
         caching. While HAProxy properly normalizes them, it is generally safe
         to reject them on public facing listeners. It is enabled by default on
-        untrusted connections.
+        untrusted connections and in the "basic-web" profile.
 
   - reject-duplicate-host-header (inbound request)
         Rejects requests containing more than one "Host" header field, even if
@@ -35282,7 +35316,7 @@ http-hardening <name> [from <source>]
         a value greater than zero or if a "transfer-encoding" header field is
         present. These may only be caused by bugs or by attempts by servers to
         inject contents (e.g. cache poisonning attacks). It is enabled by
-        default on untrusted connections.
+        default on untrusted connections and in the "basic-web" profile.
 
   - reject-header-trailer-folding (inbound request and response)
         Rejects requests and responses which contain folded header fields or
@@ -35294,7 +35328,8 @@ http-hardening <name> [from <source>]
         to inject headers into non-compliant components, and should be rejected
         as a sign of break-in attempt. Note that HAProxy does not have problems
         with them and systematically unfolds these messages before forwarding
-        them. It is enabled by default on untrusted connections.
+        them. It is enabled by default on untrusted connections and in the
+        "basic-web" profile.
 
   - reject-lowercase-method (inbound request)
         Rejects requests whose method contains a lower-case character. No
@@ -35302,7 +35337,7 @@ http-hardening <name> [from <source>]
         essentially used in desynchronization attack scenarios, by trying to
         exploit different case matching schemes along the chain. This is
         recommended on untrusted listeners. It is enabled by default on
-        untrusted connections.
+        untrusted connections and in the "basic-web" profile.
 
   - reject-out-of-range-status (inbound, response)
         Rejects responses containing a status code lower than 100 or higher
@@ -35310,7 +35345,7 @@ http-hardening <name> [from <source>]
         differently by multiple implementations. They are never used over the
         internet and usually only exist in local deployments. This is
         recommended on public-facing backends. It is enabled by default on
-        untrusted connections.
+        untrusted connections and in the "basic-web" profile.
 
   - reject-underscore-in-header-name (inbound, request and response)
         Rejects requests and responses in which one header field name contains
index 6b8d65542b1e027b043b5f96af60c1eade67c4eb..a3f9c40eaf17655ff0e8676a54408f7621fe5fab 100644 (file)
@@ -291,7 +291,24 @@ struct http_violation {
 /* default policy for a new profile: permissive */
 #define HTTP_HRD_DEFAULT  HTTP_HRD_NONE
 
-/* default contents of the implicit "untrusted" and "trusted" profiles */
+/* default contents of the implicit "basic-web", "untrusted" and "trusted" profiles */
+#define HTTP_HRD_BASIC_WEB_DEFAULT             (HTTP_HRD_REJ_LCASE_METHOD    | \
+                                                HTTP_HRD_REJ_HDR_FOLD        | \
+                                                HTTP_HRD_REJ_CTL_IN_HDR      | \
+                                                HTTP_HRD_DEL_USCORE_HDR_NAM  | \
+                                                HTTP_HRD_DEL_USCORE_TLR_NAM  | \
+                                                HTTP_HRD_DEL_UNREG_HDR       | \
+                                                HTTP_HRD_DEL_UNREG_TLR       | \
+                                                HTTP_HRD_DEL_ALL_TLR         | \
+                                                HTTP_HRD_REJ_CL_TE           | \
+                                                HTTP_HRD_REJ_CL_LEAD_ZERO    | \
+                                                HTTP_HRD_REJ_CL_DUP          | \
+                                                HTTP_HRD_REJ_FORB_PAYLOAD    | \
+                                                HTTP_HRD_REJ_OOR_STATUS      | \
+                                                HTTP_HRD_REJ_ADV_METH        | \
+                                                HTTP_HRD_REJ_UNEXP_REQ_PLD   | \
+                                                HTTP_HRD_REJ_UNEXP_REQ_UPG)
+
 #define HTTP_HRD_UNTRUSTED_DEFAULT             (HTTP_HRD_REJ_LCASE_METHOD    | \
                                                 HTTP_HRD_REJ_HDR_FOLD        | \
                                                 HTTP_HRD_REJ_CTL_IN_HDR      | \
index 1166273136e6b44ca92a3c8168afed1ae50c27e6..84df7f0ec1c32e76934528697592b16db8774d12 100644 (file)
@@ -181,9 +181,10 @@ client c_srv_auto -connect ${h1_srv_auto_sock} {
 #
 
 haproxy h1 -cli {
-       # both implicit profiles were declared, none is reported as implicit
+       # "untrusted" and "trusted" were declared, only "basic-web" is reported
+       # as implicit
        send "show http-hardening"
-       expect ~ "^base\nchild\ncli\nnodel\nnorej\nsrvp\ntrusted\nuntrusted\n"
+       expect ~ "^basic-web \\(implicit\\)\nbase\nchild\ncli\nnodel\nnorej\nsrvp\ntrusted\nuntrusted\n"
 
        send "show http-hardening child"
        expect ~ " 1 reject-duplicate-host-header +req +on\n 2 reject-lowercase-method +req +off\n 3 reject-underscore-in-header-name +- +off\n 4 reject-underscore-in-trailer-name +- +on\n 5 delete-underscore-in-header-name +- +on\n"
@@ -257,7 +258,7 @@ client c_srv_inherit2 -connect ${h1_srv_inherit_sock} {
        expect resp.http.x_a == "1"
 } -run
 
-# without declaration, the two implicit profiles are reported as such, with
+# without declaration, the three implicit profiles are reported as such, with
 # their default settings, which are inherited by "from".
 haproxy h2 -conf {
     global
@@ -281,7 +282,7 @@ haproxy h2 -conf {
 
 haproxy h2 -cli {
        send "show http-hardening"
-       expect ~ "^untrusted \\(implicit\\)\ntrusted \\(implicit\\)\nother\n"
+       expect ~ "^untrusted \\(implicit\\)\ntrusted \\(implicit\\)\nbasic-web \\(implicit\\)\nother\n"
 
        send "show http-hardening trusted"
        expect !~ " on\n"
index 2abfaa314d12cab5a7413d892294adb50555780d..03eeddd8b5a6d1eec68500c4b7fa531091dbeea7 100644 (file)
@@ -1833,6 +1833,7 @@ void dump_http_hardening_kws()
  * is parsed, in which case they are reset to their default values beforehand.
  */
 static struct ceb_root *http_hardening_by_name;
+struct http_hdng_prf http_hardening_basic_web  = { .name = "basic-web",  .mask = HTTP_HRD_BASIC_WEB_DEFAULT  };
 struct http_hdng_prf http_hardening_untrusted  = { .name = "untrusted",  .mask = HTTP_HRD_UNTRUSTED_DEFAULT  };
 struct http_hdng_prf http_hardening_trusted    = { .name = "trusted",    .mask = HTTP_HRD_TRUSTED_DEFAULT    };
 
@@ -1852,6 +1853,8 @@ struct http_hdng_prf *http_hardening_lookup(const char *name)
                        prf = &http_hardening_untrusted;
                else if (strcmp(name, http_hardening_trusted.name) == 0)
                        prf = &http_hardening_trusted;
+               else if (strcmp(name, http_hardening_basic_web.name) == 0)
+                       prf = &http_hardening_basic_web;
        }
        return prf;
 }
@@ -2005,6 +2008,8 @@ int cfg_parse_http_hardening(const char *file, int linenum, char **args, int kwm
                        prf->mask = HTTP_HRD_TRUSTED_DEFAULT;
                else if (prf == &http_hardening_untrusted)
                        prf->mask = HTTP_HRD_UNTRUSTED_DEFAULT;
+               else if (prf == &http_hardening_basic_web)
+                       prf->mask = HTTP_HRD_BASIC_WEB_DEFAULT;
 
                curr_http_hdng_prf = prf;
        }
@@ -2139,6 +2144,8 @@ static int cli_io_handler_show_http_hardening(struct appctx *appctx)
                        chunk_appendf(&trash, "%s (implicit)\n", http_hardening_untrusted.name);
                if (!cebuis_item_lookup(&http_hardening_by_name, name_node, name, http_hardening_trusted.name, struct http_hdng_prf))
                        chunk_appendf(&trash, "%s (implicit)\n", http_hardening_trusted.name);
+               if (!cebuis_item_lookup(&http_hardening_by_name, name_node, name, http_hardening_basic_web.name, struct http_hdng_prf))
+                       chunk_appendf(&trash, "%s (implicit)\n", http_hardening_basic_web.name);
                if (b_data(&trash) && applet_putchk(appctx, &trash) == -1)
                        return 0;
                ctx->stage = 1;
@@ -2392,6 +2399,15 @@ void http_dump_settings(const char *what)
                                if (!(kw->mask & (kw->mask - 1)))
                                        printf("\t%-*s %s\n", max, kw->name, (kw->mask & HTTP_HRD_UNTRUSTED_DEFAULT) ? "on" : "off");
                        }
+
+                       printf("\nhttp-hardening basic-web\n");
+                       if (!HTTP_HRD_BASIC_WEB_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_BASIC_WEB_DEFAULT) ? "on" : "off");
+                       }
                }
        }
 }