denoland/deno · error · Error
Session ticket keys must be a 48-byte buffer
Error message
Session ticket keys must be a 48-byte buffer
What it means
After its type check, Server.prototype.setTicketKeys validates length: TLS session-ticket key material is a fixed 48-byte structure in Node's format. A Buffer/TypedArray/DataView of any other length throws a plain Error('Session ticket keys must be a 48-byte buffer') — unlike the sibling constructor-option error this one has no error code, so match on the message when catching.
Solutions
- Provide exactly 48 bytes: crypto.randomBytes(48) or Buffer.from(hex, 'hex') where hex is 96 characters
- Check keys.length === 48 before calling setTicketKeys
- When catching, match on the message text since this Error carries no code property
Example fix
// before server.setTicketKeys(Buffer.from(process.env.TICKET_KEYS!)); // utf8 decode → wrong length // after server.setTicketKeys(Buffer.from(process.env.TICKET_KEYS!, 'hex')); // 48 bytes
Defensive patterns
Strategy: validation
Validate before calling
const decoded = Buffer.from(process.env.TICKET_KEYS!, 'hex');
if (decoded.length !== 48) {
throw new RangeError(`Session ticket keys must be 48 bytes, got ${decoded.length}`);
}
server.setTicketKeys(decoded); Type guard
function is48ByteView(v: unknown): v is Buffer | Uint8Array | DataView {
return ArrayBuffer.isView(v) && (v as ArrayBufferView).byteLength === 48;
} Try / catch
try {
server.setTicketKeys(keys);
} catch (err) {
if (err instanceof Error && err.message.includes('48-byte')) {
server.setTicketKeys(randomBytes(48)); // regenerate correctly-sized keys
} else throw err;
} Prevention
- Always pass an explicit encoding ('hex'/'base64') to Buffer.from for key material
- Check length before calling since this Error has no code property
- Validate rotated keys in staging before applying to a live server
When it happens
Trigger: server.setTicketKeys(randomBytes(32)); setTicketKeys(Buffer.from('96-char hex')) decoded as utf8 yielding 96 bytes; any correctly-typed view with byteLength !== 48.
Common situations: Using a 32-byte AES key as ticket keys; hex/base64 secrets passed through Buffer.from(str) without the encoding argument; partially truncated key material after copy-paste.
Related errors
- ERR_INVALID_ARG_VALUE
- ERR_TLS_REQUIRED_SERVER_NAME
- ERR_INVALID_ARG_TYPE
- ERR_INVALID_ARG_TYPE
- ERR_TLS_ALPN_CALLBACK_WITH_PROTOCOLS
AI-assisted analysis of denoland/deno@f7822238ca (2026-08-20).
Data as JSON: /api/errors/073b29217aedd865.
Report an issue: GitHub.
Appendix: source
Thrown at ext/node/polyfills/_tls_wrap.js:1534
throw new ERR_TLS_REQUIRED_SERVER_NAME();
}
ArrayPrototypePush(this._contexts, [servername, context]);
};
Server.prototype.getTicketKeys = function getTicketKeys() {
return Buffer.from(this._ticketKeys);
};
Server.prototype.setTicketKeys = function setTicketKeys(keys) {
if (!isArrayBufferView(keys)) {
throw new ERR_INVALID_ARG_TYPE(
"keys",
["Buffer", "TypedArray", "DataView"],
keys,
);
}
if (getViewByteLength(keys) !== 48) {
throw new Error("Session ticket keys must be a 48-byte buffer");
}
this._ticketKeys = Buffer.from(
getViewBuffer(keys),
getViewByteOffset(keys),
getViewByteLength(keys),
);
};
// ---------------------------------------------------------------------------
// connect
// ---------------------------------------------------------------------------
function onConnectEnd() {
if (!this._hadError) {
const options = this[kConnectOptions];
this._hadError = true;
const error = connResetException(
"Client network socket disconnected " +View on GitHub (pinned to f7822238ca)