@@ -361,6 +361,7 @@ ngx_http_v2_read_handler(ngx_event_t *rev)
361361 ngx_log_debug0 (NGX_LOG_DEBUG_HTTP , c -> log , 0 , "http2 read handler" );
362362
363363 h2c -> blocked = 1 ;
364+ h2c -> new_streams = 0 ;
364365
365366 if (c -> close ) {
366367 c -> close = 0 ;
@@ -1321,6 +1322,14 @@ ngx_http_v2_state_headers(ngx_http_v2_connection_t *h2c, u_char *pos,
13211322 goto rst_stream ;
13221323 }
13231324
1325+ if (h2c -> new_streams ++ >= 2 * h2scf -> concurrent_streams ) {
1326+ ngx_log_error (NGX_LOG_INFO , h2c -> connection -> log , 0 ,
1327+ "client sent too many streams at once" );
1328+
1329+ status = NGX_HTTP_V2_REFUSED_STREAM ;
1330+ goto rst_stream ;
1331+ }
1332+
13241333 if (!h2c -> settings_ack
13251334 && !(h2c -> state .flags & NGX_HTTP_V2_END_STREAM_FLAG )
13261335 && h2scf -> preread_size < NGX_HTTP_V2_DEFAULT_WINDOW )
@@ -1386,6 +1395,12 @@ ngx_http_v2_state_headers(ngx_http_v2_connection_t *h2c, u_char *pos,
13861395
13871396rst_stream :
13881397
1398+ if (h2c -> refused_streams ++ > ngx_max (h2scf -> concurrent_streams , 100 )) {
1399+ ngx_log_error (NGX_LOG_INFO , h2c -> connection -> log , 0 ,
1400+ "client sent too many refused streams" );
1401+ return ngx_http_v2_connection_error (h2c , NGX_HTTP_V2_NO_ERROR );
1402+ }
1403+
13891404 if (ngx_http_v2_send_rst_stream (h2c , h2c -> state .sid , status ) != NGX_OK ) {
13901405 return ngx_http_v2_connection_error (h2c , NGX_HTTP_V2_INTERNAL_ERROR );
13911406 }
0 commit comments