Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.
TypeScript acmeagentsai-agentscertificate-managementdevsecopsenvironment-variableskubernetesopen-sourcepampkipostgresprivate-caprivileged-access-managementsecret-managementsecret-managersecretssecrets-managementsecuritysecurity-toolsvault
strip for ipv6
Thiago Araujo da Silva058c075c143e
diff --git a/backend/src/ee/services/ldap-config/ldap-fns.ts b/backend/src/ee/services/ldap-config/ldap-fns.tsindex 802bfb2c18..74b4e1b295 100644--- a/backend/src/ee/services/ldap-config/ldap-fns.ts+++ b/backend/src/ee/services/ldap-config/ldap-fns.ts@@ -5,6 +5,7 @@ import ldapjs from "@infisical/ldapjs";import { BadRequestError } from "@app/lib/errors";import { logger } from "@app/lib/logger";+import { stripIpv6Brackets } from "@app/lib/tls";import { TLDAPConfig, TTestLDAPConfigDTO } from "./ldap-config-types";@@ -64,7 +65,7 @@ export const buildLdapTlsOptions = (cfg: TLdapTlsConfigInput) => {if (cfg.clientCertificate || cfg.clientKeyCertificate) {try {const { hostname } = new URL(cfg.url);- if (!isIP(hostname)) tlsOptions.servername = hostname;+ if (!isIP(stripIpv6Brackets(hostname))) tlsOptions.servername = hostname;} catch {// Malformed URL — connection itself will surface the error.}diff --git a/backend/src/lib/tls/index.ts b/backend/src/lib/tls/index.tsindex 612ed054b0..c006396553 100644--- a/backend/src/lib/tls/index.ts+++ b/backend/src/lib/tls/index.ts@@ -1,6 +1,10 @@import { isIP } from "node:net";import tls from "node:tls";+// URL.hostname keeps the brackets around an IPv6 literal, which isIP and checkServerIdentity do not accept.+export const stripIpv6Brackets = (host: string) =>+ host.startsWith("[") && host.endsWith("]") ? host.slice(1, -1) : host;+// Node 26 throws when servername is an IP (SNI cannot carry one, RFC 6066). Earlier versions still sent the// IP as SNI, so omitting it changes what the server sees (no SNI, or "localhost" from an https.Agent with no// Host header). Keep the certificate check against the IP: many callers dial a local gateway proxy, where@@ -8,6 +12,8 @@ import tls from "node:tls";export const getTlsServerNameOptions = (host?: string): Pick<tls.ConnectionOptions, "servername" | "checkServerIdentity"> => {- if (!host || !isIP(host)) return { servername: host };- return { checkServerIdentity: (_hostname, cert) => tls.checkServerIdentity(host, cert) };+ if (!host) return { servername: host };+ const ip = stripIpv6Brackets(host);+ if (!isIP(ip)) return { servername: host };+ return { checkServerIdentity: (_hostname, cert) => tls.checkServerIdentity(ip, cert) };};