Skip to content

Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.

fix(ldap-auth): trim whitespace for LDAP URL and bind DN fields, enhance validation logic

Victor Hugo dos Santos73ee07861ad3
diff --git a/backend/src/ee/services/identity-auth-template/identity-auth-template-schemas.ts b/backend/src/ee/services/identity-auth-template/identity-auth-template-schemas.ts
index 5b59e5a214..e48ea9908a 100644
--- a/backend/src/ee/services/identity-auth-template/identity-auth-template-schemas.ts
+++ b/backend/src/ee/services/identity-auth-template/identity-auth-template-schemas.ts
@@ -10,10 +10,10 @@ import { formatOidcAudiences } from "@app/services/identity-oidc-auth/identity-o
import { TEMPLATE_VALIDATION_MESSAGES } from "./identity-auth-template-enums";
export const ldapTemplateFieldsSchema = z.object({
- url: z.string().min(1, TEMPLATE_VALIDATION_MESSAGES.LDAP.URL_REQUIRED),
- bindDN: z.string().min(1, TEMPLATE_VALIDATION_MESSAGES.LDAP.BIND_DN_REQUIRED),
+ url: z.string().trim().min(1, TEMPLATE_VALIDATION_MESSAGES.LDAP.URL_REQUIRED),
+ bindDN: z.string().trim().min(1, TEMPLATE_VALIDATION_MESSAGES.LDAP.BIND_DN_REQUIRED),
bindPass: z.string().min(1, TEMPLATE_VALIDATION_MESSAGES.LDAP.BIND_PASSWORD_REQUIRED),
- searchBase: z.string().min(1, TEMPLATE_VALIDATION_MESSAGES.LDAP.SEARCH_BASE_REQUIRED),
+ searchBase: z.string().trim().min(1, TEMPLATE_VALIDATION_MESSAGES.LDAP.SEARCH_BASE_REQUIRED),
ldapCaCertificate: z.string().trim().optional()
});
diff --git a/backend/src/services/identity-ldap-auth/identity-ldap-auth-service.ts b/backend/src/services/identity-ldap-auth/identity-ldap-auth-service.ts
index ea85ff3a48..a2f875b005 100644
--- a/backend/src/services/identity-ldap-auth/identity-ldap-auth-service.ts
+++ b/backend/src/services/identity-ldap-auth/identity-ldap-auth-service.ts
@@ -692,7 +692,8 @@ export const identityLdapAuthServiceFactory = ({
};
}
- if (config.url && config.url !== identityLdapAuth.url && !config.bindPass) {
+ const nextUrl = config.url?.trim();
+ if (nextUrl && nextUrl !== identityLdapAuth.url.trim() && !config.bindPass) {
throw new BadRequestError({
message: template
? `LDAP auth template '${template.name}' has no bind password stored, so it cannot move this identity to a different LDAP URL. Add a bind password to the template first.`
diff --git a/frontend/src/pages/organization/AccessManagementPage/components/OrgIdentityTab/components/IdentitySection/IdentityLdapAuthForm.tsx b/frontend/src/pages/organization/AccessManagementPage/components/OrgIdentityTab/components/IdentitySection/IdentityLdapAuthForm.tsx
index 6c0ac68d60..2e78a4a208 100644
--- a/frontend/src/pages/organization/AccessManagementPage/components/OrgIdentityTab/components/IdentitySection/IdentityLdapAuthForm.tsx
+++ b/frontend/src/pages/organization/AccessManagementPage/components/OrgIdentityTab/components/IdentitySection/IdentityLdapAuthForm.tsx
@@ -72,6 +72,8 @@ import { AccessTokenTtlFields } from "./shared/AccessTokenTtlFields";
import { TrustedIpsField } from "./shared/TrustedIpsField";
import { IDENTITY_AUTH_FORM_ID, IdentityFormTab } from "./types";
+const normalizeUrl = (value?: string) => value?.trim() ?? "";
+
const buildSchema = (maxAccessTokenTTL: number, isUpdate: boolean, currentUrl?: string) =>
z
.object({
@@ -177,7 +179,7 @@ const buildSchema = (maxAccessTokenTTL: number, isUpdate: boolean, currentUrl?:
path: ["bindDN"]
});
}
- if (!data.bindPass && (!isUpdate || data.url !== currentUrl)) {
+ if (!data.bindPass && (!isUpdate || normalizeUrl(data.url) !== normalizeUrl(currentUrl))) {
ctx.addIssue({
code: z.ZodIssueCode.custom,
message: isUpdate
@@ -292,7 +294,10 @@ export const IdentityLdapAuthForm = ({
const templateId = watch("templateId");
const urlValue = watch("url");
const hasUrlChanged = Boolean(
- isUpdate && scope !== "template" && data?.url && urlValue !== data.url
+ isUpdate &&
+ scope !== "template" &&
+ data?.url &&
+ normalizeUrl(urlValue) !== normalizeUrl(data.url)
);
const configurationOptions = useMemo<ConfigurationOption[]>(