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: validate PEM certificates and keys in LDAP configuration
Victor Hugo dos Santos77b94dda9182
diff --git a/backend/src/ee/services/ldap-config/ldap-fns.ts b/backend/src/ee/services/ldap-config/ldap-fns.tsindex dbf87b1741..c1798c18bd 100644--- a/backend/src/ee/services/ldap-config/ldap-fns.ts+++ b/backend/src/ee/services/ldap-config/ldap-fns.ts@@ -1,5 +1,8 @@+import { createPrivateKey, X509Certificate } from "node:crypto";+import ldapjs from "@infisical/ldapjs";+import { BadRequestError } from "@app/lib/errors";import { logger } from "@app/lib/logger";import { TLDAPConfig, TTestLDAPConfigDTO } from "./ldap-config-types";@@ -18,9 +21,39 @@ type TLdapTlsConfigInput = Pick<TLDAPConfig, "url" | "caCert" | "clientCertificaexport const buildLdapTlsOptions = (cfg: TLdapTlsConfigInput) => {const tlsOptions: { ca?: string[]; cert?: string; key?: string; servername?: string } = {};- if (cfg.caCert) tlsOptions.ca = [cfg.caCert];- if (cfg.clientCertificate) tlsOptions.cert = cfg.clientCertificate;- if (cfg.clientKeyCertificate) tlsOptions.key = cfg.clientKeyCertificate;++ if (cfg.caCert) {+ try {+ // eslint-disable-next-line no-new+ new X509Certificate(cfg.caCert);+ } catch {+ throw new BadRequestError({+ message: "Invalid CA Certificate. Expected a PEM-encoded X.509 certificate."+ });+ }+ tlsOptions.ca = [cfg.caCert];+ }+ if (cfg.clientCertificate) {+ try {+ // eslint-disable-next-line no-new+ new X509Certificate(cfg.clientCertificate);+ } catch {+ throw new BadRequestError({+ message: "Invalid Client Certificate. Expected a PEM-encoded X.509 certificate."+ });+ }+ tlsOptions.cert = cfg.clientCertificate;+ }+ if (cfg.clientKeyCertificate) {+ try {+ createPrivateKey(cfg.clientKeyCertificate);+ } catch {+ throw new BadRequestError({+ message: "Invalid Client Private Key. Expected a PEM-encoded private key."+ });+ }+ tlsOptions.key = cfg.clientKeyCertificate;+ }if (Object.keys(tlsOptions).length === 0) return undefined;diff --git a/docs/documentation/platform/ldap/google-workspace.mdx b/docs/documentation/platform/ldap/google-workspace.mdxindex 2796d6feed..984c6d62af 100644--- a/docs/documentation/platform/ldap/google-workspace.mdx+++ b/docs/documentation/platform/ldap/google-workspace.mdx@@ -60,8 +60,8 @@ Prerequisites:- Group Search Base / Group DN (optional): LDAP search base to use for group membership search (`dc=yourdomain,dc=com`).- Group Filter (optional): Template used when constructing the group membership query (`(&(objectClass=groupOfNames)(member=uid={{.Username}},ou=Users,dc=yourdomain,dc=com))`).- CA Certificate (optional): Leave empty, Google's LDAP server uses a publicly trusted certificate.- - Client Certificate: Paste the contents of the `.crt` file downloaded from Google.- - Client Private Key: Paste the contents of the `.key` file downloaded from Google.+ - Client Certificate (optional) : Paste the contents of the `.crt` file downloaded from Google.+ - Client Private Key (optional) : Paste the contents of the `.key` file downloaded from Google.<Tip>The Client Certificate and Client Private Key must be provided together — providing only one will fail validation. These are the credentials presented during the TLS handshake; without them, the connection fails before LDAP-layer bind is attempted.diff --git a/frontend/src/pages/organization/SettingsPage/components/OrgSsoTab/LDAPModal.tsx b/frontend/src/pages/organization/SettingsPage/components/OrgSsoTab/LDAPModal.tsxindex 4d3e2219d8..3df73c40ee 100644--- a/frontend/src/pages/organization/SettingsPage/components/OrgSsoTab/LDAPModal.tsx+++ b/frontend/src/pages/organization/SettingsPage/components/OrgSsoTab/LDAPModal.tsx@@ -89,7 +89,7 @@ export const LDAPModal = ({ popUp, handlePopUpClose, handlePopUpToggle, hideDeleconst { mutateAsync: testLDAPConnection } = useTestLDAPConnection();const { data } = useGetLDAPConfig(currentOrg?.id ?? "");- const { control, handleSubmit, reset, watch, setValue } = useForm<TLDAPFormData>({+ const { control, handleSubmit, reset, watch } = useForm<TLDAPFormData>({resolver: zodResolver(LDAPFormSchema)});@@ -227,7 +227,7 @@ export const LDAPModal = ({ popUp, handlePopUpClose, handlePopUpToggle, hideDeleif (watchEnableMtls) {if (watchHasStoredClientKey && !watchClientKeyCertificate?.trim()) {createNotification({- text: "Paste the Client Private Key to test the connection — stored keys are not sent to the browser.",+ text: "Paste the Client Private Key to test the connection. Stored keys are not sent to the browser.",type: "warning"});return;@@ -466,13 +466,7 @@ export const LDAPModal = ({ popUp, handlePopUpClose, handlePopUpToggle, hideDeleid="ldap-enable-mtls"variant="org"checked={field.value}- onCheckedChange={(checked) => {- field.onChange(checked);- if (!checked) {- setValue("clientCertificate", "", { shouldValidate: true });- setValue("clientKeyCertificate", "", { shouldValidate: true });- }- }}+ onCheckedChange={field.onChange}/></Field>)}