{"record":{"id":"33e8b9688d8660de","repo":"denoland/deno","slug":"err-tls-invalid-protocol-version","errorCode":"ERR_TLS_INVALID_PROTOCOL_VERSION","errorMessage":"${options.minVersion} is not a valid minVersion TLS protocol version","messagePattern":"(.+?) is not a valid minVersion TLS protocol version","errorType":"error_code","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"ext/node/polyfills/_tls_common.ts","lineNumber":329,"sourceCode":"      }\n      if (\n        options.secureProtocol === \"SSLv3_method\" ||\n        options.secureProtocol === \"SSLv3_client_method\" ||\n        options.secureProtocol === \"SSLv3_server_method\"\n      ) {\n        throw new ERR_TLS_INVALID_PROTOCOL_METHOD(\"SSLv3 methods disabled\");\n      }\n      throw new ERR_TLS_INVALID_PROTOCOL_METHOD(\n        `Unknown method: ${options.secureProtocol}`,\n      );\n    }\n\n    minVersion = range[0];\n    maxVersion = range[1];\n  } else {\n    if (options.minVersion) {\n      if (!SetPrototypeHas(kValidVersions, options.minVersion)) {\n        throw new ERR_TLS_INVALID_PROTOCOL_VERSION(\n          options.minVersion,\n          \"minVersion\",\n        );\n      }\n      minVersion = options.minVersion;\n    }\n    if (options.maxVersion) {\n      if (!SetPrototypeHas(kValidVersions, options.maxVersion)) {\n        throw new ERR_TLS_INVALID_PROTOCOL_VERSION(\n          options.maxVersion,\n          \"maxVersion\",\n        );\n      }\n      maxVersion = options.maxVersion;\n    }\n  }\n\n  return { minVersion, maxVersion };","sourceCodeStart":311,"sourceCodeEnd":347,"githubUrl":"https://github.com/denoland/deno/blob/9ad36f7a2cce60488e6ec52283efb32efddaf93a/ext/node/polyfills/_tls_common.ts#L311-L347","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before\nnew tls.TLSSocket(socket, { minVersion: 'tlsv1.2' }); // throws ERR_TLS_INVALID_PROTOCOL_VERSION\n\n// after\nnew tls.TLSSocket(socket, { minVersion: 'TLSv1.2' });","handlingStrategy":"validation","validationCode":"import * as tls from 'node:tls';\nconst VALID = new Set(['TLSv1', 'TLSv1.1', 'TLSv1.2', 'TLSv1.3']);\nfunction assertTlsVersion(value: unknown, opt: string): void {\n  if (value !== undefined && !VALID.has(value as string)) {\n    throw new RangeError(`${opt} must be one of: ${[...VALID].join(', ')}`);\n  }\n}\nassertTlsVersion(cfg.minVersion, 'minVersion');\nconst ctx = tls.createSecureContext(cfg);","typeGuard":"const VALID_TLS_VERSIONS = new Set(['TLSv1', 'TLSv1.1', 'TLSv1.2', 'TLSv1.3']);\ntype TlsVersion = 'TLSv1' | 'TLSv1.1' | 'TLSv1.2' | 'TLSv1.3';\nfunction isTlsVersion(v: unknown): v is TlsVersion {\n  return typeof v === 'string' && VALID_TLS_VERSIONS.has(v as TlsVersion);\n}","tryCatchPattern":"try {\n  ctx = tls.createSecureContext({ minVersion });\n} catch (err) {\n  if ((err as NodeJS.ErrnoException).code === 'ERR_TLS_INVALID_PROTOCOL_VERSION') {\n    ctx = tls.createSecureContext({}); // retry with runtime defaults\n  } else throw err;\n}","preventionTips":["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"],"tags":["tls","ssl","node-compat","secure-context","configuration"],"backgroundTag":"invalid-tls-protocol-version","analyzedSha":"9ad36f7a2cce60488e6ec52283efb32efddaf93a","analyzedAt":"2026-08-20T13:07:44.778Z","contentChangedAt":"2026-08-20T13:07:44.778Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}