[PATCH 03 of 10] gRPC: improved window update checking

Maxim Dounin mdounin at mdounin.ru
Tue Nov 24 00:27:06 UTC 2026


# HG changeset patch
# User Maxim Dounin <mdounin at mdounin.ru>
# Date 1795479768 -10800
#      Tue Nov 24 03:22:48 2026 +0300
# Node ID f0af3674e99a92f62b3526ed4bf3df762f422323
# Parent  a793fa576435e45acbbfc92fb3294836120bf2af
gRPC: improved window update checking.

Following changes in HTTP/2, window updates are now rejected as long as
the current send window is larger than NGX_HTTP_V2_MAX_WINDOW minus the
window update sent by the client, so no overflows or underflows are
possible.  Additionally, the check on the window update itself ensures
it is no larger than the maximum (which is not possible per protocol, so
the check is provided for clarity).

This ensures that window updates are properly rejected even if the
current send window happens to be larger than NGX_HTTP_V2_MAX_WINDOW for
some reason.

diff --git a/src/http/modules/ngx_http_grpc_module.c b/src/http/modules/ngx_http_grpc_module.c
--- a/src/http/modules/ngx_http_grpc_module.c
+++ b/src/http/modules/ngx_http_grpc_module.c
@@ -3842,8 +3842,9 @@ ngx_http_grpc_parse_window_update(ngx_ht
 
     if (ctx->stream_id) {
 
-        if (ctx->window_update > (size_t) NGX_HTTP_V2_MAX_WINDOW
-                                 - ctx->send_window)
+        if (ctx->window_update > NGX_HTTP_V2_MAX_WINDOW
+            || ctx->send_window > (ssize_t) (NGX_HTTP_V2_MAX_WINDOW
+                                  - ctx->window_update))
         {
             ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
                           "upstream sent too large window update");
@@ -3855,7 +3856,8 @@ ngx_http_grpc_parse_window_update(ngx_ht
     } else {
 
         if (ctx->window_update > NGX_HTTP_V2_MAX_WINDOW
-                                 - ctx->connection->send_window)
+            || ctx->connection->send_window > NGX_HTTP_V2_MAX_WINDOW
+                                              - ctx->window_update)
         {
             ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
                           "upstream sent too large window update");



More information about the nginx-devel mailing list