Skip to content

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

feat(user-alias): enhance resolveAssertedProfileName to handle multi-valued attributes

Victor Hugo dos Santos6388ece6c557
diff --git a/backend/src/services/user-alias/user-alias-fns.test.ts b/backend/src/services/user-alias/user-alias-fns.test.ts
index a537535bcd..4fc24f556b 100644
--- a/backend/src/services/user-alias/user-alias-fns.test.ts
+++ b/backend/src/services/user-alias/user-alias-fns.test.ts
@@ -99,10 +99,40 @@ describe("resolveAssertedProfileName", () => {
});
});
+ // Every one of these attributes is multi-valued in the LDAP schema, so ldapjs returns a string[]
+ // for any entry that carries a second value, and an IdP can assert a JSON array just as well.
+ test("takes the first value when an assertion is multi-valued", () => {
+ expect(
+ resolveAssertedProfileName({
+ givenName: ["Jane", "Janet"],
+ familyName: ["Doe", "Smith"],
+ displayName: "Jane Doe"
+ })
+ ).toEqual({ firstName: "Jane", lastName: "Doe" });
+ });
+
+ test("removes the surname from a multi-valued composite name", () => {
+ expect(resolveAssertedProfileName({ familyName: "Doe", displayName: ["Jane Doe", "jdoe"] })).toEqual({
+ firstName: "Jane",
+ lastName: "Doe"
+ });
+ });
+
+ // ldapjs renders an attribute with no values as an empty array rather than omitting it.
+ test("ignores empty and whitespace-only values inside an assertion", () => {
+ expect(resolveAssertedProfileName({ givenName: [], familyName: [" ", "Doe"], displayName: ["Jane Doe"] })).toEqual(
+ {
+ firstName: "Jane",
+ lastName: "Doe"
+ }
+ );
+ });
+
test("returns null when nothing usable is asserted", () => {
expect(resolveAssertedProfileName({})).toBeNull();
expect(resolveAssertedProfileName({ familyName: "Doe" })).toBeNull();
expect(resolveAssertedProfileName({ givenName: null, familyName: null, displayName: null })).toBeNull();
+ expect(resolveAssertedProfileName({ givenName: [], familyName: [], displayName: [] })).toBeNull();
});
});
diff --git a/backend/src/services/user-alias/user-alias-fns.ts b/backend/src/services/user-alias/user-alias-fns.ts
index ce4ea15b8d..bb336b8753 100644
--- a/backend/src/services/user-alias/user-alias-fns.ts
+++ b/backend/src/services/user-alias/user-alias-fns.ts
@@ -34,13 +34,17 @@ type TIsStaleSsoAliasDTO = {
assertedEmail: string;
};
+// Every one of these is multi-valued in the LDAP schema, so ldapjs hands back a string[] whenever
+// the entry carries more than one value, and an IdP can assert a JSON array just as well.
+type TAssertedName = string | string[] | null;
+
type TResolveAssertedProfileNameDTO = {
// OIDC `given_name` / LDAP `givenName`.
- givenName?: string | null;
+ givenName?: TAssertedName;
// OIDC `family_name` / LDAP `sn`.
- familyName?: string | null;
+ familyName?: TAssertedName;
// The composite display name: OIDC `name` / LDAP `cn`.
- displayName?: string | null;
+ displayName?: TAssertedName;
};
/**
@@ -70,9 +74,12 @@ export const resolveAssertedProfileName = ({
familyName,
displayName
}: TResolveAssertedProfileNameDTO): { firstName: string; lastName: string } | null => {
- const given = givenName?.trim();
- const family = familyName?.trim();
- const display = displayName?.trim();
+ const firstValue = (value?: TAssertedName) =>
+ (Array.isArray(value) ? value.find((entry) => entry?.trim()) : value)?.trim();
+
+ const given = firstValue(givenName);
+ const family = firstValue(familyName);
+ const display = firstValue(displayName);
if (given) return { firstName: given, lastName: family || "" };
if (!display) return null;