Skip to content

Commit 92c9e6b

Browse files
committed
Add HTTP/3 Host header support for ModSecurity
ModSecurity cannot see the Host header in HTTP/3 requests because HTTP/3 uses the `:authority` pseudo-header, which nginx parses into `r->headers_in.server` but doesn't add to the headers list. This commit: - Adds `NGX_HTTP_VERSION_30` case to `http_version` switch - Manually extracts Host from `r->headers_in.server` for HTTP/3 requests - Adds Host header to ModSecurity transaction before processing other headers Fixes #305 false positives from OWASP CRS rule 920280 (Missing Host Header) on HTTP/3 connections. Tested with nginx 1.29.3 and ModSecurity 3.0.13.
1 parent fd28e6a commit 92c9e6b

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

src/ngx_http_modsecurity_rewrite.c

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,11 @@ ngx_http_modsecurity_rewrite_handler(ngx_http_request_t *r)
177177
case NGX_HTTP_VERSION_20 :
178178
http_version = "2.0";
179179
break;
180+
#endif
181+
#if defined(nginx_version) && nginx_version >= 1025000
182+
case NGX_HTTP_VERSION_30 :
183+
http_version = "3.0";
184+
break;
180185
#endif
181186
default :
182187
http_version = ngx_str_to_char(r->http_protocol, r->pool);
@@ -212,9 +217,22 @@ ngx_http_modsecurity_rewrite_handler(ngx_http_request_t *r)
212217
}
213218

214219
/**
215-
* Since incoming request headers are already in place, lets send it to ModSecurity
216-
*
220+
* HTTP/3 uses :authority pseudo-header instead of Host header and nginx
221+
* parses it into r->headers_in.server (see ngx_http_v3_request.c#L982)
222+
* but doesn't add it to the headers list, so ModSecurity never sees it.
223+
* We manually add Host header from r->headers_in.server for ModSecurity
224+
* before processing the remaining headers.
217225
*/
226+
if (strcmp(http_version, "3.0") == 0 && r->headers_in.server.len > 0) {
227+
dd("adding Host header from :authority: %.*s",
228+
(int)r->headers_in.server.len, r->headers_in.server.data);
229+
230+
msc_add_n_request_header(ctx->modsec_transaction,
231+
(const unsigned char *)"Host", 4,
232+
(const unsigned char *)r->headers_in.server.data,
233+
r->headers_in.server.len);
234+
}
235+
218236
ngx_list_part_t *part = &r->headers_in.headers.part;
219237
ngx_table_elt_t *data = part->elts;
220238
ngx_uint_t i = 0;

0 commit comments

Comments
 (0)