Skip to content

Commit

Permalink
test: http2 origin length ERR_HTTP2_ORIGIN_LENGTH
Browse files Browse the repository at this point in the history
  • Loading branch information
trivikr authored and Trott committed Feb 17, 2019
1 parent 5bb7764 commit 3bf4d66
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
6 changes: 4 additions & 2 deletions lib/internal/http2/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,8 @@ const kMaxFrameSize = (2 ** 24) - 1;
const kMaxInt = (2 ** 32) - 1;
const kMaxStreams = (2 ** 31) - 1;

const kMaxLengthOriginAltsvc = 16382;

// eslint-disable-next-line no-control-regex
const kQuotedString = /^[\x09\x20-\x5b\x5d-\x7e\x80-\xff]*$/;

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

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

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

if (len > 16382)
if (len > kMaxLengthOriginAltsvc)
throw new ERR_HTTP2_ORIGIN_LENGTH();

this[kHandle].origin(arr, count);
Expand Down
19 changes: 11 additions & 8 deletions test/parallel/test-http2-origin.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,17 @@ const ca = readKey('fake-startcom-root-cert.pem', 'binary');
}
);
});
const longInput = 'http://foo.bar' + 'a'.repeat(16383);
throws(
() => session.origin(longInput),
{
code: 'ERR_HTTP2_ORIGIN_LENGTH',
name: 'TypeError [ERR_HTTP2_ORIGIN_LENGTH]'
}
);

// Check that error is thrown if length is greater than 16382.
['http://foo.bar' + 'a'.repeat(16383)].forEach((input) => {
throws(
() => session.origin(input),
{
code: 'ERR_HTTP2_ORIGIN_LENGTH',
name: 'TypeError [ERR_HTTP2_ORIGIN_LENGTH]'
}
);
});
}));

server.listen(0, mustCall(() => {
Expand Down

0 comments on commit 3bf4d66

Please # to comment.