Skip to content

Commit f6e4dbb

Browse files
aduh95targos
authored andcommitted
tls: validate ticket keys buffer
Fixes: #38305 PR-URL: #38308 Reviewed-By: Darshan Sen <raisinten@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent 6b58f28 commit f6e4dbb

3 files changed

Lines changed: 29 additions & 1 deletion

File tree

‎doc/api/tls.md‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -697,7 +697,8 @@ existing server. Existing connections to the server are not interrupted.
697697
added: v3.0.0
698698
-->
699699

700-
*`keys` {Buffer} A 48-byte buffer containing the session ticket keys.
700+
*`keys` {Buffer|TypedArray|DataView} A 48-byte buffer containing the session
701+
ticket keys.
701702

702703
Sets the session ticket keys.
703704

‎lib/_tls_wrap.js‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1371,6 +1371,9 @@ Server.prototype.getTicketKeys = function getTicketKeys() {
13711371

13721372

13731373
Server.prototype.setTicketKeys=functionsetTicketKeys(keys){
1374+
validateBuffer(keys);
1375+
assert(keys.byteLength===48,
1376+
'Session ticket keys must be a 48-byte buffer');
13741377
this._sharedCreds.context.setTicketKeys(keys);
13751378
};
13761379

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
'use strict';
2+
constcommon=require('../common');
3+
if(!common.hasCrypto){
4+
common.skip('missing crypto');
5+
}
6+
7+
constassert=require('assert');
8+
consttls=require('tls');
9+
10+
constserver=newtls.Server();
11+
12+
[null,undefined,0,1,1n,Symbol(),{},[],true,false,'',()=>{}]
13+
.forEach((arg)=>
14+
assert.throws(
15+
()=>server.setTicketKeys(arg),
16+
{code: 'ERR_INVALID_ARG_TYPE'}
17+
));
18+
19+
[newUint8Array(1),Buffer.from([1]),newDataView(newArrayBuffer(2))].forEach(
20+
(arg)=>
21+
assert.throws(()=>{
22+
server.setTicketKeys(arg);
23+
},/Sessionticketkeysmustbea48-bytebuffer/)
24+
);

0 commit comments

Comments
 (0)