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
fix(ldap): check the LDAP URL on test connection
Vlad Ligai6276d0cb0fce
diff --git a/backend/src/ee/services/ldap-config/ldap-config-service.test.ts b/backend/src/ee/services/ldap-config/ldap-config-service.test.tsnew file mode 100644index 0000000000..87a944fb9b--- /dev/null+++ b/backend/src/ee/services/ldap-config/ldap-config-service.test.ts@@ -0,0 +1,54 @@+import { createMongoAbility } from "@casl/ability";+import { beforeEach, describe, expect, test, vi } from "vitest";++import { ActorType } from "@app/services/auth/auth-type";++import { OrgPermissionActions, OrgPermissionSubjects } from "../permission/org-permission";+import { ldapConfigServiceFactory } from "./ldap-config-service";+import { testLDAPConfig } from "./ldap-fns";++vi.mock("@app/lib/config/env", () => ({+ getConfig: () => ({ isDevelopmentMode: false, ALLOW_INTERNAL_IP_CONNECTIONS: false })+}));++vi.mock("./ldap-fns", () => ({+ testLDAPConfig: vi.fn().mockResolvedValue(true)+}));++const createService = () =>+ ldapConfigServiceFactory({+ permissionService: {+ getOrgPermission: vi.fn().mockResolvedValue({+ permission: createMongoAbility([{ action: OrgPermissionActions.Create, subject: OrgPermissionSubjects.Ldap }])+ })+ },+ licenseService: { getPlan: vi.fn().mockResolvedValue({ ldap: true }) }+ } as unknown as Parameters<typeof ldapConfigServiceFactory>[0]);++// literal IPs keep the suite hermetic: blockLocalAndPrivateIpAddresses skips the DNS lookup+const testConnection = (url: string) =>+ createService().testLDAPConnection({+ actor: ActorType.USER,+ actorId: "user-id",+ actorOrgId: "org-id",+ actorAuthMethod: null,+ orgId: "org-id",+ url,+ bindDN: "cn=admin",+ bindPass: "pw",+ caCert: ""+ });++describe("testLDAPConnection", () => {+ beforeEach(() => vi.clearAllMocks());++ test("refuses a private address without connecting", async () => {+ await expect(testConnection("ldap://127.0.0.1:389")).rejects.toThrow("Local IPs not allowed as URL");+ expect(testLDAPConfig).not.toHaveBeenCalled();+ });++ test("connects to a public address", async () => {+ await expect(testConnection("ldap://8.8.8.8:389")).resolves.toBe(true);+ expect(testLDAPConfig).toHaveBeenCalledWith(expect.objectContaining({ url: "ldap://8.8.8.8:389" }));+ });+});diff --git a/backend/src/ee/services/ldap-config/ldap-config-service.ts b/backend/src/ee/services/ldap-config/ldap-config-service.tsindex cf9ca8f3ca..7c0e3e9bf0 100644--- a/backend/src/ee/services/ldap-config/ldap-config-service.ts+++ b/backend/src/ee/services/ldap-config/ldap-config-service.ts@@ -1043,6 +1043,8 @@ export const ldapConfigServiceFactory = ({message: "Failed to test LDAP connection due to plan restriction. Upgrade plan to test the LDAP connection."});+ await blockLocalAndPrivateIpAddresses(url);+if (Boolean(clientCertificate) !== Boolean(clientKeyCertificate)) {throw new BadRequestError({message: "clientCertificate and clientKeyCertificate must be provided together for mTLS."