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
Enhance LDAP error logging and referral handling
Victor Hugo dos Santos35285c40d546
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 56ce56769d..aa45e9a069 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@@ -68,7 +68,7 @@ const getDN = async (dn: string, client: Client): Promise<string> => {referralDn: ldapErr.dn,referralUrls: (ldapErr as { referrals?: string[] }).referrals ?? []},- "LDAP DN resolution received referral — propagating for upstream chase"+ `LDAP DN resolution received referral — propagating for upstream chase [searchBase=${base}] [upn=${dn}] [referralDn=${ldapErr.dn}]`);reject(error);return;@@ -227,7 +227,7 @@ export const ldapPasswordRotationFactory: TRotationFactory<targetDn: dn,url: modifyUrl},- "LDAP search referral — captured before gateway proxy"+ `LDAP search referral — captured before gateway proxy [targetDn=${dn}] [url=${modifyUrl}] [errorDn=${getDnErr.dn}]`);capturedReferralError = getDnErr;}@@ -258,13 +258,13 @@ export const ldapPasswordRotationFactory: TRotationFactory<targetDn: userDn,url: modifyUrl},- "LDAP modify referral — captured before gateway proxy"+ `LDAP modify referral — captured before gateway proxy [targetDn=${userDn}] [url=${modifyUrl}] [errorDn=${ldapErr.dn}]`);capturedReferralError = ldapErr as LdapReferralError;} else {logger.debug({ errorMessage: err.message, errorName: err.name, targetDn: userDn, url: modifyUrl },- "LDAP modify error (non-referral)"+ `LDAP modify error (non-referral) [targetDn=${userDn}] [url=${modifyUrl}] [errorName=${err.name}]`);}reject(err);@@ -288,8 +288,10 @@ export const ldapPasswordRotationFactory: TRotationFactory<const MAX_REFERRAL_HOPS = 10;let referredUrl: string | undefined;let currentCredentials = connectionCredentials;+ const visitedUrls = new Set<string>();for (let hop = 0; hop <= MAX_REFERRAL_HOPS; hop += 1) {+ visitedUrls.add(normalizeLdapUrl(currentCredentials.url));try {// eslint-disable-next-line no-await-in-loopawait performModify(currentCredentials);@@ -373,7 +375,7 @@ export const ldapPasswordRotationFactory: TRotationFactory<targetSource,currentUrl: currentCredentials.url},- `LDAP referral received during ${referralSource} — resolving chase target`+ `LDAP referral received during ${referralSource} — resolving chase target [referralDn=${referralDn}] [referralTarget=${referralTarget}] [targetSource=${targetSource}] [currentUrl=${currentCredentials.url}]`);if (!referralTarget) {@@ -384,13 +386,13 @@ export const ldapPasswordRotationFactory: TRotationFactory<referredUrl = buildReferralUrl(credentials.url, referralTarget);- if (referredUrl === normalizeLdapUrl(currentCredentials.url)) {+ if (visitedUrls.has(referredUrl)) {logger.error(- { ...rotationContext, referredUrl, targetSource, referralSource },- "LDAP password rotation — referral chase would loop to the same URL, aborting"+ { ...rotationContext, referredUrl, visitedUrls: [...visitedUrls], targetSource, referralSource },+ `LDAP password rotation — referral chase would loop to an already-visited URL, aborting [referredUrl=${referredUrl}] [referralSource=${referralSource}]`);throw new Error(- `Provider Modify Error: Referral chase loop detected — referred URL ${referredUrl} is the same as the current URL`+ `Provider Modify Error: Referral chase loop detected — referred URL ${referredUrl} was already visited`);}diff --git a/backend/src/services/app-connection/ldap/ldap-connection-fns.ts b/backend/src/services/app-connection/ldap/ldap-connection-fns.tsindex 0937ae96ab..68de9c8fca 100644--- a/backend/src/services/app-connection/ldap/ldap-connection-fns.ts+++ b/backend/src/services/app-connection/ldap/ldap-connection-fns.ts@@ -131,9 +131,8 @@ export const buildReferralUrl = (originalUrl: string, targetDomain: string): strconst targetRoot = getRootDomain(targetDomain);if (!originalRoot) {- logger.warn(- { originalHost: host, targetDomain },- "Cannot validate referral domain boundary — original LDAP URL is not a FQDN"+ throw new Error(+ `Cannot validate referral domain boundary — original LDAP URL '${host}' is not a FQDN. Refusing to forward credentials to '${targetDomain}'`);} else if (!targetRoot || originalRoot !== targetRoot) {throw new Error(