Skip to content

Commit 3bf4d66

Browse files
trivikrTrott
authored andcommitted
test: http2 origin length ERR_HTTP2_ORIGIN_LENGTH
1 parent 5bb7764 commit 3bf4d66

File tree

2 files changed

+15
-10
lines changed

2 files changed

+15
-10
lines changed

lib/internal/http2/core.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,8 @@ const kMaxFrameSize = (2 ** 24) - 1;
138138
const kMaxInt = (2 ** 32) - 1;
139139
const kMaxStreams = (2 ** 31) - 1;
140140

141+
const kMaxLengthOriginAltsvc = 16382;
142+
141143
// eslint-disable-next-line no-control-regex
142144
const kQuotedString = /^[\x09\x20-\x5b\x5d-\x7e\x80-\xff]*$/;
143145

@@ -1377,7 +1379,7 @@ class ServerHttp2Session extends Http2Session {
13771379
throw new ERR_INVALID_CHAR('alt');
13781380

13791381
// Max length permitted for ALTSVC
1380-
if ((alt.length + (origin !== undefined ? origin.length : 0)) > 16382)
1382+
if (alt.length + (origin ? origin.length : 0) > kMaxLengthOriginAltsvc)
13811383
throw new ERR_HTTP2_ALTSVC_LENGTH();
13821384

13831385
this[kHandle].altsvc(stream, origin || '', alt);
@@ -1409,7 +1411,7 @@ class ServerHttp2Session extends Http2Session {
14091411
len += origin.length;
14101412
}
14111413

1412-
if (len > 16382)
1414+
if (len > kMaxLengthOriginAltsvc)
14131415
throw new ERR_HTTP2_ORIGIN_LENGTH();
14141416

14151417
this[kHandle].origin(arr, count);

test/parallel/test-http2-origin.js

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -70,14 +70,17 @@ const ca = readKey('fake-startcom-root-cert.pem', 'binary');
7070
}
7171
);
7272
});
73-
const longInput = 'http://foo.bar' + 'a'.repeat(16383);
74-
throws(
75-
() => session.origin(longInput),
76-
{
77-
code: 'ERR_HTTP2_ORIGIN_LENGTH',
78-
name: 'TypeError [ERR_HTTP2_ORIGIN_LENGTH]'
79-
}
80-
);
73+
74+
// Check that error is thrown if length is greater than 16382.
75+
['http://foo.bar' + 'a'.repeat(16383)].forEach((input) => {
76+
throws(
77+
() => session.origin(input),
78+
{
79+
code: 'ERR_HTTP2_ORIGIN_LENGTH',
80+
name: 'TypeError [ERR_HTTP2_ORIGIN_LENGTH]'
81+
}
82+
);
83+
});
8184
}));
8285

8386
server.listen(0, mustCall(() => {

0 commit comments

Comments
 (0)