denoland/deno · error · TypeError
ERR_TLS_INVALID_PROTOCOL_VERSION
ERR_TLS_INVALID_PROTOCOL_VERSION
Error message
${options.minVersion} is not a valid minVersion TLS protocol version What it means
Deno's node:tls polyfill validates options.minVersion against a fixed allow-list (kValidVersions: 'TLSv1', 'TLSv1.1', 'TLSv1.2', 'TLSv1.3') while resolving the protocol version range for a secure context. Any value outside that set throws ERR_TLS_INVALID_PROTOCOL_VERSION before the TLS context is built, mirroring Node.js so misconfigured apps fail fast. Note this branch only runs when options.secureProtocol is not set.
Solutions
- Set minVersion to 'TLSv1.2' or 'TLSv1.3' — the versions modern Deno (rustls) negotiates
- Check exact case and spelling against the allow-list: 'TLSv1', 'TLSv1.1', 'TLSv1.2', 'TLSv1.3'
- Omit minVersion entirely to use the runtime default (TLSv1.2) instead of guessing
- If the value comes from config/env, validate it against the allow-list before passing it to node:tls
Example fix
// before
new tls.TLSSocket(socket, { minVersion: 'tlsv1.2' }); // throws ERR_TLS_INVALID_PROTOCOL_VERSION
// after
new tls.TLSSocket(socket, { minVersion: 'TLSv1.2' }); Defensive patterns
Strategy: validation
Validate before calling
import * as tls from 'node:tls';
const VALID = new Set(['TLSv1', 'TLSv1.1', 'TLSv1.2', 'TLSv1.3']);
function assertTlsVersion(value: unknown, opt: string): void {
if (value !== undefined && !VALID.has(value as string)) {
throw new RangeError(`${opt} must be one of: ${[...VALID].join(', ')}`);
}
}
assertTlsVersion(cfg.minVersion, 'minVersion');
const ctx = tls.createSecureContext(cfg); Type guard
const VALID_TLS_VERSIONS = new Set(['TLSv1', 'TLSv1.1', 'TLSv1.2', 'TLSv1.3']);
type TlsVersion = 'TLSv1' | 'TLSv1.1' | 'TLSv1.2' | 'TLSv1.3';
function isTlsVersion(v: unknown): v is TlsVersion {
return typeof v === 'string' && VALID_TLS_VERSIONS.has(v as TlsVersion);
} Try / catch
try {
ctx = tls.createSecureContext({ minVersion });
} catch (err) {
if ((err as NodeJS.ErrnoException).code === 'ERR_TLS_INVALID_PROTOCOL_VERSION') {
ctx = tls.createSecureContext({}); // retry with runtime defaults
} else throw err;
} Prevention
- Centralize TLS version strings as typed constants instead of free strings
- Type the config field as the union 'TLSv1' | 'TLSv1.1' | 'TLSv1.2' | 'TLSv1.3' so the compiler catches typos
- Validate env-sourced TLS settings once at startup rather than at every connection
When it happens
Trigger: Calling tls.createSecureContext(), tls.connect(), tls.createServer(), or new tls.TLSSocket() with options.minVersion that is not exactly 'TLSv1', 'TLSv1.1', 'TLSv1.2', or 'TLSv1.3' — e.g. 'TLSv1.4', lowercase 'tlsv1.2', 'SSLv3', '1.2', or the number 1.2.
Common situations: Typos or wrong casing in hand-written TLS config; copying OpenSSL-style names like 'TLSv1_2_method'; values sourced from env vars or JSON config that are misspelled or empty; config written for libraries that accept lowercase version strings.
Understand the failure class
- SSL/TLS and certificate errors — how TLS handshakes and certificate validation fail.
Related errors
- ERR_INVALID_ARG_TYPE
- ERR_TLS_ALPN_CALLBACK_WITH_PROTOCOLS
- ERR_TLS_INVALID_PROTOCOL_METHOD
- ERR_TLS_PROTOCOL_VERSION_CONFLICT
- Bad cluster.schedulingPolicy
AI-assisted analysis of denoland/deno@9ad36f7a2c (2026-08-20).
Data as JSON: /api/errors/33e8b9688d8660de.
Report an issue: GitHub.
Appendix: source
Thrown at ext/node/polyfills/_tls_common.ts:329
}
if (
options.secureProtocol === "SSLv3_method" ||
options.secureProtocol === "SSLv3_client_method" ||
options.secureProtocol === "SSLv3_server_method"
) {
throw new ERR_TLS_INVALID_PROTOCOL_METHOD("SSLv3 methods disabled");
}
throw new ERR_TLS_INVALID_PROTOCOL_METHOD(
`Unknown method: ${options.secureProtocol}`,
);
}
minVersion = range[0];
maxVersion = range[1];
} else {
if (options.minVersion) {
if (!SetPrototypeHas(kValidVersions, options.minVersion)) {
throw new ERR_TLS_INVALID_PROTOCOL_VERSION(
options.minVersion,
"minVersion",
);
}
minVersion = options.minVersion;
}
if (options.maxVersion) {
if (!SetPrototypeHas(kValidVersions, options.maxVersion)) {
throw new ERR_TLS_INVALID_PROTOCOL_VERSION(
options.maxVersion,
"maxVersion",
);
}
maxVersion = options.maxVersion;
}
}
return { minVersion, maxVersion };View on GitHub (pinned to 9ad36f7a2c)