Skip to content

Commit e324e9b

Browse files
authored
Merge pull request #1874 from lianglli/fix-CVE-2023-44487
HTTP/2: per-iteration stream handling limit.
2 parents 311ec04 + 9330174 commit e324e9b

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

src/http/v2/ngx_http_v2.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

13871396
rst_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
}

src/http/v2/ngx_http_v2.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,8 @@ struct ngx_http_v2_connection_s {
124124
ngx_uint_t processing;
125125
ngx_uint_t frames;
126126
ngx_uint_t idle;
127+
ngx_uint_t new_streams;
128+
ngx_uint_t refused_streams;
127129
ngx_uint_t priority_limit;
128130

129131
ngx_uint_t pushing;

0 commit comments

Comments
 (0)