reject-duplicate-content-length on
reject-forbidden-payload on
reject-advanced-methods off
+ reject-unexpected-request-payload off
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
so it is safe to enable on untrusted listeners. See also the
"delete-underscore-in-trailer-name" variant.
+ - reject-unexpected-request-payload (inbound, request)
+ Rejects requests which contain a payload on methods which have no
+ defined semantics with it (HEAD, GET, DELETE, OPTIONS, CONNECT, TRACE),
+ as well as any HTTP/1.1 request using the chunked Transfer-Encoding.
+ This protects backend servers having imperfect implementation against a
+ wide list of attacks that try to abuse their limited parsing to bypass
+ their inspection or desynchronize them with haproxy. The vast majority
+ of applications aimed at browsers will not experience any issue with
+ this setting, but some in-house or proprietary components might rely on
+ passing a payload to some of these methods, or uploading streamed data
+ using Transfer-Encoding. Note that other methods are assumed to support
+ payloads, and unknown methods might be handled similarly to GET by some
+ servers. As such, when using this to protect an application, it is wise
+ to also use 'reject-advanced-methods'. This is generally safe for
+ static web serving and simple internet-facing applications. It is
+ disabled by default.
+
/*
* Local variables:
#define HTTP_HRD_REJ_FORB_PAYLOAD 0x00004000
#define HTTP_HRD_REJ_OOR_STATUS 0x00008000
#define HTTP_HRD_REJ_ADV_METH 0x00010000
+#define HTTP_HRD_REJ_UNEXP_REQ_PLD 0x00020000
/* insert new masks above this line */
/* update this one with new rejects */
HTTP_HRD_REJ_CL_DUP | \
HTTP_HRD_REJ_FORB_PAYLOAD | \
HTTP_HRD_REJ_OOR_STATUS | \
- HTTP_HRD_REJ_ADV_METH)
+ HTTP_HRD_REJ_ADV_METH | \
+ HTTP_HRD_REJ_UNEXP_REQ_PLD)
#define HTTP_HRD_ALL_DELETE (HTTP_HRD_DEL_USCORE_HDR_NAM | \
HTTP_HRD_DEL_USCORE_TLR_NAM | \
# 0x040 delete-unregistered-header-fields (only looked up when enabled)
# 0x100 delete-all-trailer-fields (any trailer)
# 0x400 reject-ctl-in-header-trailer
+# 0x20000 reject-unexpected-request-payload (the chunked requests)
# The masks are logged in hex after htonl. The H2 frontend has no
# backend, so "bs" is not available there.
syslog Strusted -level info {
recv
- expect ~ "fe_trusted .* fs=00000514/00000000/- bs=00000514/00000000/-$"
+ expect ~ "fe_trusted .* fs=00020514/00000000/- bs=00000514/00000000/-$"
} -start
syslog Sreq -level info {
recv
- expect ~ "fe_req .* fs=00000454/00000450/reject-ctl-in-header-trailer bs=-/-/-$"
+ expect ~ "fe_req .* fs=00020454/00000450/reject-ctl-in-header-trailer bs=-/-/-$"
} -start
syslog Sres -level info {
goto error;
}
+ /* reject-unexpected-request-payload: reject payload on methods which
+ * don't have defined semantics for this, as well as chunked encoding
+ * in requests for any method.
+ */
+ if (((h1m->flags & H1_MF_CHNK) ||
+ ((h1sl->rq.meth == HTTP_METH_GET || h1sl->rq.meth == HTTP_METH_HEAD || h1sl->rq.meth == HTTP_METH_DELETE ||
+ h1sl->rq.meth == HTTP_METH_OPTIONS || h1sl->rq.meth == HTTP_METH_CONNECT || h1sl->rq.meth == HTTP_METH_TRACE) &&
+ (h1m->flags & H1_MF_CLEN) && h1m->body_len != 0)) &&
+ http_harden(HTTP_HRD_REJ_UNEXP_REQ_PLD)) {
+ h1m->err_code = 400;
+ goto error;
+ }
+
/* Remove Upgrade header if no 'connection: upgrade' found */
if ((h1m->flags & (H1_MF_CONN_UPG|H1_MF_UPG_HDR)) == H1_MF_UPG_HDR) {
int i;
http_harden(HTTP_HRD_REJ_ADV_METH))
goto fail;
+ /* reject-unexpected-request-payload: reject payload on methods which
+ * don't have defined semantics for this.
+ */
+ if ((*msgf & H2_MSGF_BODY) &&
+ (meth == HTTP_METH_GET || meth == HTTP_METH_HEAD || meth == HTTP_METH_DELETE ||
+ meth == HTTP_METH_OPTIONS || meth == HTTP_METH_CONNECT || meth == HTTP_METH_TRACE) &&
+ http_harden(HTTP_HRD_REJ_UNEXP_REQ_PLD))
+ goto fail;
+
sl = htx_add_stline(htx, HTX_BLK_REQ_SL, flags, meth_sl, uri, ist("HTTP/2.0"));
if (!sl)
goto fail;
goto out;
}
+ /* reject-unexpected-request-payload: reject payload on methods which
+ * don't have defined semantics for this.
+ */
+ if (!fin &&
+ (sl->info.req.meth == HTTP_METH_GET || sl->info.req.meth == HTTP_METH_HEAD ||
+ sl->info.req.meth == HTTP_METH_DELETE || sl->info.req.meth == HTTP_METH_OPTIONS ||
+ sl->info.req.meth == HTTP_METH_CONNECT || sl->info.req.meth == HTTP_METH_TRACE) &&
+ http_harden(HTTP_HRD_REJ_UNEXP_REQ_PLD)) {
+ TRACE_ERROR("hardening rejected unexpected payload for method", H3_EV_RX_FRAME|H3_EV_RX_HDR, qcs->qcc->conn, qcs);
+ h3s->err = H3_ERR_REQUEST_REJECTED;
+ qcc_report_glitch(h3c->qcc, 1);
+ len = -1;
+ goto out;
+ }
+
if (isttest(authority)) {
if (!htx_add_header(htx, ist("host"), authority)) {
len = -1;
{ "reject-forbidden-payload", HTTP_HRD_REJ_FORB_PAYLOAD, HTTP_DIR_RES },
{ "reject-out-of-range-status", HTTP_HRD_REJ_OOR_STATUS, HTTP_DIR_RES },
{ "reject-advanced-methods", HTTP_HRD_REJ_ADV_METH, HTTP_DIR_REQ },
+ { "reject-unexpected-request-payload", HTTP_HRD_REJ_UNEXP_REQ_PLD, HTTP_DIR_REQ },
/* insert new hardening options above this line */
{ "all-reject", HTTP_HRD_ALL_REJECT, HTTP_DIR_BOTH },
{ "all-delete", HTTP_HRD_ALL_DELETE, HTTP_DIR_BOTH },