Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tls: validate ticket keys buffer #38308

Merged
merged 1 commit into from
Apr 23, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion doc/api/tls.md
Original file line number Diff line number Diff line change
Expand Up @@ -730,7 +730,8 @@ existing server. Existing connections to the server are not interrupted.
added: v3.0.0
-->

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

Sets the session ticket keys.

Expand Down
3 changes: 3 additions & 0 deletions lib/_tls_wrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -1396,6 +1396,9 @@ Server.prototype.getTicketKeys = function getTicketKeys() {


Server.prototype.setTicketKeys = function setTicketKeys(keys) {
validateBuffer(keys);
assert(keys.byteLength === 48,
'Session ticket keys must be a 48-byte buffer');
this._sharedCreds.context.setTicketKeys(keys);
};

Expand Down
24 changes: 24 additions & 0 deletions test/parallel/test-tls-ticket-invalid-arg.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
'use strict';
const common = require('../common');
if (!common.hasCrypto) {
common.skip('missing crypto');
}

const assert = require('assert');
const tls = require('tls');

const server = new tls.Server();

[null, undefined, 0, 1, 1n, Symbol(), {}, [], true, false, '', () => {}]
.forEach((arg) =>
assert.throws(
() => server.setTicketKeys(arg),
{ code: 'ERR_INVALID_ARG_TYPE' }
));

[new Uint8Array(1), Buffer.from([1]), new DataView(new ArrayBuffer(2))].forEach(
(arg) =>
assert.throws(() => {
server.setTicketKeys(arg);
}, /Session ticket keys must be a 48-byte buffer/)
);