summaryrefslogtreecommitdiffhomepage
path: root/src/http/v3/ngx_http_v3.c
diff options
context:
space:
mode:
authorRoman Arutyunyan <arut@nginx.com>2021-10-07 13:22:42 +0300
committerRoman Arutyunyan <arut@nginx.com>2021-10-07 13:22:42 +0300
commit434f11bf3f4c9c8466a946c775441ecd6f768c13 (patch)
tree4b60637010e15bf84d539d2d027a31deddc1f297 /src/http/v3/ngx_http_v3.c
parent0c33e484a4333fe2a343baf3aeefae3212534db3 (diff)
downloadnginx-434f11bf3f4c9c8466a946c775441ecd6f768c13.tar.gz
nginx-434f11bf3f4c9c8466a946c775441ecd6f768c13.tar.bz2
HTTP/3: traffic-based flood detection.
With this patch, all traffic over HTTP/3 bidi and uni streams is counted in the h3c->total_bytes field, and payload traffic is counted in the h3c->payload_bytes field. As long as total traffic is many times larger than payload traffic, we consider this to be a flood. Request header traffic is counted as if all fields are literal. Response header traffic is counted as is.
Diffstat (limited to 'src/http/v3/ngx_http_v3.c')
-rw-r--r--src/http/v3/ngx_http_v3.c19
1 files changed, 19 insertions, 0 deletions
diff --git a/src/http/v3/ngx_http_v3.c b/src/http/v3/ngx_http_v3.c
index 2c838f4b5..500113509 100644
--- a/src/http/v3/ngx_http_v3.c
+++ b/src/http/v3/ngx_http_v3.c
@@ -86,3 +86,22 @@ ngx_http_v3_cleanup_session(void *data)
ngx_del_timer(&h3c->keepalive);
}
}
+
+
+ngx_int_t
+ngx_http_v3_check_flood(ngx_connection_t *c)
+{
+ ngx_http_v3_session_t *h3c;
+
+ h3c = ngx_http_v3_get_session(c);
+
+ if (h3c->total_bytes / 8 > h3c->payload_bytes + 1048576) {
+ ngx_log_error(NGX_LOG_INFO, c->log, 0, "http3 flood detected");
+
+ ngx_http_v3_finalize_connection(c, NGX_HTTP_V3_ERR_NO_ERROR,
+ "HTTP/3 flood detected");
+ return NGX_ERROR;
+ }
+
+ return NGX_OK;
+}