safe and even recommended to delete such trailers from inbound internet
requests.
+ - reject-ctl-in-header-trailer (inbound request and response)
+ Rejects requests and responses which contain control characters in
+ their header or trailer field values (codes 0-8,10-31,127). These ones
+ are forbidden but have long experienced a certain tolerance among
+ implementations, which has encouraged some rare applications to use
+ them as record delimiters for example. No standard component produces
+ them on the public internet, except attacks. By default, HAProxy only
+ blocks the strictly required ones (0,10,13) and lets other ones pass,
+ 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.
+
- reject-duplicate-host-header (inbound request)
Rejects requests containing more than one "Host" header field, even if
valid and identical. This is recommended on untrusted listeners. Note that
#define HTTP_HRD_DEL_UNREG_TLR 0x00000080
#define HTTP_HRD_DEL_ALL_TLR 0x00000100
#define HTTP_HRD_REJ_HDR_FOLD 0x00000200
+#define HTTP_HRD_REJ_CTL_IN_HDR 0x00000400
/* insert new masks above this line */
#define HTTP_HRD_ALL 0xFFFFFFFF
* remains is HT (rare), CTL, CR/LF (forbidden), or obs-text.
*/
for (; start < istend(ist); start++) {
- if ((uint8_t)*start <= 0x0d &&
+ /* speed-up: SP, VCHAR, obs-text are always OK,
+ * i.e. anything not CTL nor DEL.
+ */
+ if ((uint8_t)*start >= 0x20 && *start != 0x7f)
+ continue;
+
+ /* CR/LF/NUL are always forbidden */
+ if ((uint8_t)*start < 0x20 &&
(1U << (uint8_t)*start) & ((1<<13) | (1<<10) | (1<<0)))
return 1;
+
+ /* the rest (CTL, DEL) is OK in default mode */
+ if (!(http_hdng_chk.rules & HTTP_HRD_REJ_CTL_IN_HDR))
+ continue;
+
+ /* strict mode: DEL and all CTL but HT are forbidden */
+ if (*start != 0x9 && http_harden(HTTP_HRD_REJ_CTL_IN_HDR))
+ return 1;
}
return 0;
}
EAT_AND_JUMP_OR_RETURN(ptr, end, http_msg_hdr_l2_lf, http_msg_ood, state, H1_MSG_HDR_L2_LF);
goto http_msg_hdr_l2_lf;
}
+
+ /* CR/LF/NUL have already been deal with, only remain
+ * CTL/HT/DEL, OK in default mode, but only HT is
+ * allowed in strict mode.
+ */
+ if (*ptr != 9 && http_harden(HTTP_HRD_REJ_CTL_IN_HDR)) {
+ state = H1_MSG_HDR_VAL;
+ goto http_msg_invalid;
+ }
}
/* OK, not < 0x20 or a valid one (e.g. tab) */
{ "delete-unregistered-trailer-fields",HTTP_HRD_DEL_UNREG_TLR, HTTP_DIR_BOTH },
{ "delete-all-trailer-fields", HTTP_HRD_DEL_ALL_TLR, HTTP_DIR_BOTH },
{ "reject-header-trailer-folding", HTTP_HRD_REJ_HDR_FOLD, HTTP_DIR_BOTH },
+ { "reject-ctl-in-header-trailer", HTTP_HRD_REJ_CTL_IN_HDR, HTTP_DIR_BOTH },
/* insert new hardening options above this line */
{ "all", HTTP_HRD_ALL, HTTP_DIR_BOTH },
{ NULL, 0 }