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
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
safe and even recommended to delete such trailers from inbound internet
requests.
+ - reject-advanced-methods (inbound, request)
+ Rejects requests whose method is not one of: HEAD, GET, POST, PUT,
+ DELETE, OPTIONS, PATCH, QUERY, or extended CONNECT (RFC8441). This
+ is amply sufficient for the vast majority of regular web sites and
+ applications accessed by browsers, but may not always be compatible
+ with API aimed at being joined directly by other applications. This can
+ block by default a significant number of backend vulnerabilities that
+ are not yet discovered and that are only triggered by less common
+ methods. Use only after verifying applications compatibility, though
+ this is safe for static web serving and simple internet-facing
+ applications. It is disabled by default.
+
- reject-content-length-leading-zero (inbound request and response)
Rejects requests and responses having a Content-Length header field
whose value contains a leading zero before a digit. Some client and
so it is safe to enable on untrusted listeners. See also the
"delete-underscore-in-trailer-name" variant.
+
/*
* Local variables:
* fill-column: 79
#define HTTP_HRD_REJ_CL_DUP 0x00002000
#define HTTP_HRD_REJ_FORB_PAYLOAD 0x00004000
#define HTTP_HRD_REJ_OOR_STATUS 0x00008000
+#define HTTP_HRD_REJ_ADV_METH 0x00010000
/* insert new masks above this line */
/* update this one with new rejects */
HTTP_HRD_REJ_CL_LEAD_ZERO | \
HTTP_HRD_REJ_CL_DUP | \
HTTP_HRD_REJ_FORB_PAYLOAD | \
- HTTP_HRD_REJ_OOR_STATUS)
+ HTTP_HRD_REJ_OOR_STATUS | \
+ HTTP_HRD_REJ_ADV_METH)
#define HTTP_HRD_ALL_DELETE (HTTP_HRD_DEL_USCORE_HDR_NAM | \
HTTP_HRD_DEL_USCORE_TLR_NAM | \
http-hardening untrusted
reject-duplicate-host-header on
- # everything but one check
+ # everything but one check (and the methods check, which would also
+ # reject "get")
http-hardening base
all on
reject-lowercase-method off
+ reject-advanced-methods off
# inherits everything from "base", and turns the underscore rejection
# into a deletion since the latter is still enabled.
}
}
+ /* reject-advanced-methods allows to reject methods that are not among:
+ * HEAD/GET/POST/PUT/OPTIONS/DELETE/PATCH/QUERY.
+ */
+ if (unlikely(h1sl->rq.meth == HTTP_METH_CONNECT ||
+ h1sl->rq.meth == HTTP_METH_TRACE ||
+ (h1sl->rq.meth == HTTP_METH_OTHER &&
+ (h1sl->rq.m.len != 5 || (memcmp(h1sl->rq.m.ptr, "PATCH", 5) != 0 && memcmp(h1sl->rq.m.ptr, "QUERY", 5) != 0)))) &&
+ http_harden(HTTP_HRD_REJ_ADV_METH)) {
+ h1m->err_code = 405; // method not allowed
+ 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;
flags |= HTX_SL_F_BODYLESS_RESP;
}
+ /* reject-advanced-methods allows to reject methods that are not among:
+ * HEAD/GET/POST/PUT/OPTIONS/DELETE/PATCH/QUERY. CONNECT is only
+ * accepted as extended CONNECT (e.g. WebSocket).
+ */
+ if (unlikely((meth == HTTP_METH_CONNECT && !(*msgf & H2_MSGF_EXT_CONNECT)) ||
+ meth == HTTP_METH_TRACE ||
+ (meth == HTTP_METH_OTHER &&
+ (meth_sl.len != 5 || (memcmp(meth_sl.ptr, "PATCH", 5) != 0 && memcmp(meth_sl.ptr, "QUERY", 5) != 0)))) &&
+ http_harden(HTTP_HRD_REJ_ADV_METH))
+ goto fail;
+
sl = htx_add_stline(htx, HTX_BLK_REQ_SL, flags, meth_sl, uri, ist("HTTP/2.0"));
if (!sl)
goto fail;
sl->info.req.meth = find_http_meth(meth.ptr, meth.len);
+ /* reject-advanced-methods allows to reject methods that are not among:
+ * HEAD/GET/POST/PUT/OPTIONS/DELETE/PATCH/QUERY.
+ */
+ if (unlikely(sl->info.req.meth == HTTP_METH_CONNECT ||
+ sl->info.req.meth == HTTP_METH_TRACE ||
+ (sl->info.req.meth == HTTP_METH_OTHER &&
+ (meth.len != 5 || (memcmp(meth.ptr, "PATCH", 5) != 0 && memcmp(meth.ptr, "QUERY", 5) != 0)))) &&
+ http_harden(HTTP_HRD_REJ_ADV_METH)) {
+ TRACE_ERROR("hardening rejected advanced 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-duplicate-content-length", HTTP_HRD_REJ_CL_DUP, HTTP_DIR_BOTH },
{ "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 },
/* 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 },