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
feat(ldap): add normalizeLdapUrl function and enhance error handling
Victor Hugo dos Santos77beffb69f18
diff --git a/backend/src/ee/services/secret-rotation-v2/ldap-password/ldap-password-rotation-fns.ts b/backend/src/ee/services/secret-rotation-v2/ldap-password/ldap-password-rotation-fns.tsindex 362ab3f422..bdae83c840 100644--- a/backend/src/ee/services/secret-rotation-v2/ldap-password/ldap-password-rotation-fns.ts+++ b/backend/src/ee/services/secret-rotation-v2/ldap-password/ldap-password-rotation-fns.ts@@ -19,6 +19,7 @@ import {isLdapReferralError,LdapProvider,LdapReferralError,+ normalizeLdapUrl,TLdapConnection} from "@app/services/app-connection/ldap";@@ -56,6 +57,9 @@ const getDN = async (dn: string, client: Client): Promise<string> => {if (!ldapErr.dn) {(ldapErr as { dn: string }).dn = base;}+ if (!Array.isArray((ldapErr as { referrals?: unknown }).referrals)) {+ (ldapErr as { referrals: string[] }).referrals = [];+ }(ldapErr as { referralSource: string }).referralSource = "search";logger.info({@@ -372,7 +376,7 @@ export const ldapPasswordRotationFactory: TRotationFactory<referredUrl = buildReferralUrl(credentials.url, referralTarget);- if (referredUrl === currentCredentials.url) {+ if (referredUrl === normalizeLdapUrl(currentCredentials.url)) {logger.error({ ...rotationContext, referredUrl, targetSource, referralSource },"LDAP password rotation — referral chase would loop to the same URL, aborting"diff --git a/backend/src/services/app-connection/ldap/ldap-connection-fns.ts b/backend/src/services/app-connection/ldap/ldap-connection-fns.tsindex dbcdb0bdcc..8a265e465d 100644--- a/backend/src/services/app-connection/ldap/ldap-connection-fns.ts+++ b/backend/src/services/app-connection/ldap/ldap-connection-fns.ts@@ -89,6 +89,15 @@ const constructLdapUrl = (protocol: string, host: string, port: number): stringreturn `${protocol}://${host}:${port}`;};+/**+ * Normalizes an LDAP URL to always include an explicit port.+ * e.g. "ldaps://dc1.test.com" → "ldaps://dc1.test.com:636"+ */+export const normalizeLdapUrl = (url: string): string => {+ const { protocol, host, port } = parseLdapUrl(url);+ return constructLdapUrl(protocol, host, port);+};+/*** Extracts the root domain (last two labels) from a hostname.* e.g. "dc1.test.com" → "test.com", "americas.infisical.local" → "infisical.local"