From: Willy Tarreau Date: Mon, 23 Nov 2026 08:56:17 +0000 (+0100) Subject: MEDIUM: http/hardening: delete untrusted headers/trailers with underscore X-Git-Url: https://git.kaiwu.me/http/%7B@url%7D?a=commitdiff_plain;h=8e581c25e830f75e250d1dd512017d04b696b2e4;p=haproxy.git MEDIUM: http/hardening: delete untrusted headers/trailers with underscore No standard header/trailer name exists with underscores, and these are sometimes converted to the same variable name as the ones with a dash by some application frameworks or CGI/FCGI, causing confusion. Let's just drop them by default from untrusted peers (we don't deny these requests nor responses though). --- diff --git a/include/haproxy/http-t.h b/include/haproxy/http-t.h index 15f7d4186..49ef142f5 100644 --- a/include/haproxy/http-t.h +++ b/include/haproxy/http-t.h @@ -278,10 +278,12 @@ struct http_violation { #define HTTP_HRD_DEFAULT HTTP_HRD_NONE /* default contents of the implicit "untrusted" and "trusted" profiles */ -#define HTTP_HRD_UNTRUSTED_DEFAULT (HTTP_HRD_REJ_LCASE_METHOD | \ - HTTP_HRD_REJ_HDR_FOLD | \ - HTTP_HRD_REJ_CTL_IN_HDR | \ - HTTP_HRD_REJ_CL_TE | \ +#define HTTP_HRD_UNTRUSTED_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_REJ_CL_TE | \ HTTP_HRD_REJ_CL_LEAD_ZERO) #define HTTP_HRD_TRUSTED_DEFAULT HTTP_HRD_DEFAULT diff --git a/reg-tests/http-messaging/http_hardening_profiles.vtc b/reg-tests/http-messaging/http_hardening_profiles.vtc index 6298af943..e9354dcbb 100644 --- a/reg-tests/http-messaging/http_hardening_profiles.vtc +++ b/reg-tests/http-messaging/http_hardening_profiles.vtc @@ -285,7 +285,7 @@ haproxy h2 -cli { expect !~ " on\n" send "show http-hardening untrusted" - expect ~ " 1 reject-duplicate-host-header +req +off\n 2 reject-lowercase-method +req +on\n 3 reject-underscore-in-header-name +- +off\n 4 reject-underscore-in-trailer-name +- +off\n 5 delete-underscore-in-header-name +- +off\n 6 delete-underscore-in-trailer-name +- +off\n 7 delete-unregistered-header-fields +- +off\n 8 delete-unregistered-trailer-fields +- +off\n 9 delete-all-trailer-fields +- +off\n10 reject-header-trailer-folding +- +on\n11 reject-ctl-in-header-trailer +- +on\n12 reject-content-length-with-te +- +on\n13 reject-content-length-leading-zero +- +on\n" + expect ~ " 1 reject-duplicate-host-header +req +off\n 2 reject-lowercase-method +req +on\n 3 reject-underscore-in-header-name +- +off\n 4 reject-underscore-in-trailer-name +- +off\n 5 delete-underscore-in-header-name +- +on\n 6 delete-underscore-in-trailer-name +- +on\n 7 delete-unregistered-header-fields +- +off\n 8 delete-unregistered-trailer-fields +- +off\n 9 delete-all-trailer-fields +- +off\n10 reject-header-trailer-folding +- +on\n11 reject-ctl-in-header-trailer +- +on\n12 reject-content-length-with-te +- +on\n13 reject-content-length-leading-zero +- +on\n" send "show http-hardening other" expect ~ " 2 reject-lowercase-method +req +off\n(.*\n)*10 reject-header-trailer-folding +- +on\n"