Skip to content

Commit

Permalink
http2: explicitly disallow nested push streams
Browse files Browse the repository at this point in the history
Fixes: #19095

Backport-PR-URL: #22850
PR-URL: #22245
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
  • Loading branch information
jasnell authored and BethGriggs committed Oct 16, 2018
1 parent b66cba0 commit cc561cc
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 0 deletions.
6 changes: 6 additions & 0 deletions doc/api/errors.md
Original file line number Diff line number Diff line change
Expand Up @@ -775,6 +775,12 @@ required to send an acknowledgment that it has received and applied the new
be sent at any given time. This error code is used when that limit has been
reached.

<a id="ERR_HTTP2_NESTED_PUSH"></a>
### ERR_HTTP2_NESTED_PUSH

An attempt was made to initiate a new push stream from within a push stream.
Nested push streams are not permitted.

<a id="ERR_HTTP2_NO_SOCKET_MANIPULATION"></a>
### ERR_HTTP2_NO_SOCKET_MANIPULATION

Expand Down
3 changes: 3 additions & 0 deletions doc/api/http2.md
Original file line number Diff line number Diff line change
Expand Up @@ -1261,6 +1261,9 @@ Setting the weight of a push stream is not allowed in the `HEADERS` frame. Pass
a `weight` value to `http2stream.priority` with the `silent` option set to
`true` to enable server-side bandwidth balancing between concurrent streams.

Calling `http2stream.pushStream()` from within a pushed stream is not permitted
and will throw an error.

#### http2stream.respond([headers[, options]])
<!-- YAML
added: v8.4.0
Expand Down
2 changes: 2 additions & 0 deletions lib/internal/errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,8 @@ E('ERR_HTTP2_INVALID_SETTING_VALUE',
E('ERR_HTTP2_INVALID_STREAM', 'The stream has been destroyed');
E('ERR_HTTP2_MAX_PENDING_SETTINGS_ACK',
(max) => `Maximum number of pending settings acknowledgements (${max})`);
E('ERR_HTTP2_NESTED_PUSH',
'A push stream cannot initiate another push stream.', Error);
E('ERR_HTTP2_NO_SOCKET_MANIPULATION',
'HTTP/2 sockets should not be directly manipulated (e.g. read and written)');
E('ERR_HTTP2_OUT_OF_STREAMS',
Expand Down
2 changes: 2 additions & 0 deletions lib/internal/http2/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -2116,6 +2116,8 @@ class ServerHttp2Stream extends Http2Stream {
pushStream(headers, options, callback) {
if (!this.pushAllowed)
throw new errors.Error('ERR_HTTP2_PUSH_DISABLED');
if (this[kID] % 2 === 0)
throw new errors.Error('ERR_HTTP2_NESTED_PUSH');

const session = this[kSession];

Expand Down
8 changes: 8 additions & 0 deletions test/parallel/test-http2-server-push-stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,14 @@ server.on('stream', common.mustCall((stream, headers) => {
'x-push-data': 'pushed by server',
});
push.end('pushed by server data');

common.expectsError(() => {
push.pushStream({}, common.mustNotCall());
}, {
code: 'ERR_HTTP2_NESTED_PUSH',
type: Error
});

stream.end('test');
}));
}
Expand Down

0 comments on commit cc561cc

Please sign in to comment.