In 3.5-dev11, the ability to remove unregistered headers and trailers
(X-*) was added with commits
4b9b6044b2 ("MINOR: http/hardening: add
"delete-unregistered-header-fields"") and
b5fd464f0a ("MINOR:
http/hardening: add "delete-unregistered-trailer-fields""). There is
a small mistake there, which is the the http_harden() call is made
before checking if the situation was met, resulting in the flags being
set for each header/trailer. For now this doesn't have any impact but
it will when reporting is implemented. Let's fix that by only calling
http_harden() after the header syntax was checked. No backport is
needed.
break;
}
+
/* we may have to delete unregistered header names (X-) */
- if (unlikely((h1m->state != H1_MSG_TRAILERS && http_harden(HTTP_HRD_DEL_UNREG_HDR)) ||
- (h1m->state == H1_MSG_TRAILERS && http_harden(HTTP_HRD_DEL_UNREG_TLR)))) {
- if (n.len > 1 && n.ptr[1] == '-' &&
- (n.ptr[0] == 'x' || n.ptr[0] == 'X'))
- break;
+ if (h1m->state != H1_MSG_TRAILERS &&
+ unlikely((http_hdng_chk.rules & HTTP_HRD_DEL_UNREG_HDR) &&
+ (n.len > 1 && n.ptr[1] == '-' &&
+ (n.ptr[0] == 'x' || n.ptr[0] == 'X'))) &&
+ http_harden(HTTP_HRD_DEL_UNREG_HDR)) {
+ /* skip it, so it won't be added */
+ break;
+ }
+ else if (h1m->state == H1_MSG_TRAILERS &&
+ unlikely((http_hdng_chk.rules & HTTP_HRD_DEL_UNREG_TLR) &&
+ (n.len > 1 && n.ptr[1] == '-' &&
+ (n.ptr[0] == 'x' || n.ptr[0] == 'X'))) &&
+ http_harden(HTTP_HRD_DEL_UNREG_TLR)) {
+ /* skip it, so it won't be added */
+ break;
}
if (isteqi(n, ist("transfer-encoding"))) {
}
/* we may have to delete unregistered header names (X-) */
- if (unlikely(http_harden(HTTP_HRD_DEL_UNREG_HDR))) {
- if (list[idx].n.len > 1 && list[idx].n.ptr[1] == '-' &&
- (list[idx].n.ptr[0] == 'x' || list[idx].n.ptr[0] == 'X'))
- /* skip it, so it won't be added */
- continue;
+ if (unlikely((http_hdng_chk.rules & HTTP_HRD_DEL_UNREG_HDR) &&
+ (list[idx].n.len > 1 && list[idx].n.ptr[1] == '-' &&
+ (list[idx].n.ptr[0] == 'x' || list[idx].n.ptr[0] == 'X'))) &&
+ http_harden(HTTP_HRD_DEL_UNREG_HDR)) {
+ /* skip it, so it won't be added */
+ continue;
}
if (unlikely(!(fields & H2_PHDR_FND_NONE))) {
}
/* we may have to delete unregistered header names (X-) */
- if (unlikely(http_harden(HTTP_HRD_DEL_UNREG_HDR))) {
- if (list[idx].n.len > 1 && list[idx].n.ptr[1] == '-' &&
- (list[idx].n.ptr[0] == 'x' || list[idx].n.ptr[0] == 'X'))
- /* skip it, so it won't be added */
- continue;
+ if (unlikely((http_hdng_chk.rules & HTTP_HRD_DEL_UNREG_HDR) &&
+ (list[idx].n.len > 1 && list[idx].n.ptr[1] == '-' &&
+ (list[idx].n.ptr[0] == 'x' || list[idx].n.ptr[0] == 'X'))) &&
+ http_harden(HTTP_HRD_DEL_UNREG_HDR)) {
+ /* skip it, so it won't be added */
+ continue;
}
if (!(fields & H2_PHDR_FND_NONE)) {
}
/* we may have to delete unregistered header names (X-) */
- if (unlikely(http_harden(HTTP_HRD_DEL_UNREG_HDR))) {
- if (list[hdr_idx].n.len > 1 && list[hdr_idx].n.ptr[1] == '-' &&
- (list[hdr_idx].n.ptr[0] == 'x' || list[hdr_idx].n.ptr[0] == 'X')) {
- /* skip it, so it won't be added */
- ++hdr_idx;
- continue;
- }
+ if (unlikely((http_hdng_chk.rules & HTTP_HRD_DEL_UNREG_HDR) &&
+ (list[hdr_idx].n.len > 1 && list[hdr_idx].n.ptr[1] == '-' &&
+ (list[hdr_idx].n.ptr[0] == 'x' || list[hdr_idx].n.ptr[0] == 'X'))) &&
+ http_harden(HTTP_HRD_DEL_UNREG_HDR)) {
+ /* skip it, so it won't be added */
+ ++hdr_idx;
+ continue;
}
if (isteq(list[hdr_idx].n, ist("host"))) {
}
/* we may have to delete unregistered header names (X-) */
- if (unlikely(http_harden(HTTP_HRD_DEL_UNREG_TLR))) {
- if (list[idx].n.len > 1 && list[idx].n.ptr[1] == '-' &&
- (list[idx].n.ptr[0] == 'x' || list[idx].n.ptr[0] == 'X'))
- /* skip it, so it won't be added */
- continue;
+ if (unlikely(http_hdng_chk.rules & HTTP_HRD_DEL_UNREG_TLR) &&
+ (list[idx].n.len > 1 && list[idx].n.ptr[1] == '-' &&
+ (list[idx].n.ptr[0] == 'x' || list[idx].n.ptr[0] == 'X')) &&
+ http_harden(HTTP_HRD_DEL_UNREG_TLR)) {
+ /* skip it, so it won't be added */
+ continue;
}
/* trim leading/trailing LWS as per RC9113#8.2.1 */