Skip to content

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

feat(user-alias): implement resolveAssertedProfileName function and integrate it into LDAP and OIDC login flows

Victor Hugo dos Santos3e0855d491b7
diff --git a/backend/src/ee/routes/v1/ldap-router.ts b/backend/src/ee/routes/v1/ldap-router.ts
index 34edcad7f1..df3470fd5e 100644
--- a/backend/src/ee/routes/v1/ldap-router.ts
+++ b/backend/src/ee/routes/v1/ldap-router.ts
@@ -26,6 +26,7 @@ import { verifyAuth } from "@app/server/plugins/auth/verify-auth";
import { SanitizedLdapConfigSchema } from "@app/server/routes/sanitizedSchema/directory-config";
import { AuthMode, ProviderAuthResult } from "@app/services/auth/auth-type";
import { PostHogEventTypes } from "@app/services/telemetry/telemetry-types";
+import { resolveAssertedProfileName } from "@app/services/user-alias/user-alias-fns";
export const registerLdapRouter = async (server: FastifyZodProvider) => {
const appCfg = getConfig();
@@ -82,12 +83,18 @@ export const registerLdapRouter = async (server: FastifyZodProvider) => {
? (fastifyReq.body as { callbackPort?: number })?.callbackPort
: undefined;
+ const assertedName = resolveAssertedProfileName({
+ givenName: user.givenName,
+ familyName: user.sn,
+ displayName: user.cn
+ });
+
const loginResult = await server.services.ldap.ldapLogin({
externalId,
username,
ldapConfigId: ldapConfig.id,
- firstName: user.givenName ?? user.cn ?? "",
- lastName: user.sn ?? "",
+ firstName: assertedName?.firstName ?? "",
+ lastName: assertedName?.lastName ?? "",
email: user.mail,
groups,
ip: requestContext.get("ip") || "",
diff --git a/backend/src/ee/services/oidc/oidc-config-service.ts b/backend/src/ee/services/oidc/oidc-config-service.ts
index db81715fb2..fb6c5a2c5a 100644
--- a/backend/src/ee/services/oidc/oidc-config-service.ts
+++ b/backend/src/ee/services/oidc/oidc-config-service.ts
@@ -62,6 +62,7 @@ import {
adoptProvisionedShadowUser,
ensureSsoAccountVerified,
isStaleSsoAlias,
+ resolveAssertedProfileName,
syncSsoUserProfile
} from "@app/services/user-alias/user-alias-fns";
import { UserAliasType } from "@app/services/user-alias/user-alias-types";
@@ -897,8 +898,12 @@ export const oidcConfigServiceFactory = ({
});
}
- const name = claims?.given_name || claims?.name;
- if (!name) {
+ const assertedName = resolveAssertedProfileName({
+ givenName: claims?.given_name,
+ familyName: claims?.family_name,
+ displayName: claims?.name
+ });
+ if (!assertedName) {
throw new BadRequestError({
message: "Invalid request. Missing name claim."
});
@@ -909,8 +914,8 @@ export const oidcConfigServiceFactory = ({
oidcLogin({
email: claims.email.toLowerCase(),
externalId: claims.sub,
- firstName: name,
- lastName: claims.family_name ?? "",
+ firstName: assertedName.firstName,
+ lastName: assertedName.lastName,
orgId: org.id,
ip: requestContext.get("ip") || "",
userAgent: requestContext.get("userAgent") || "",
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 f7027dcfdb..a537535bcd 100644
--- a/backend/src/services/user-alias/user-alias-fns.test.ts
+++ b/backend/src/services/user-alias/user-alias-fns.test.ts
@@ -5,7 +5,12 @@ import { TUserAliases, TUsers } from "@app/db/schemas";
import { DatabaseErrorCode } from "@app/lib/error-codes";
import { DatabaseError, ForbiddenRequestError } from "@app/lib/errors";
-import { adoptProvisionedShadowUser, resolveAliasUserIds, syncSsoUserProfile } from "./user-alias-fns";
+import {
+ adoptProvisionedShadowUser,
+ resolveAliasUserIds,
+ resolveAssertedProfileName,
+ syncSsoUserProfile
+} from "./user-alias-fns";
import { UserAliasType } from "./user-alias-types";
vi.mock("@app/lib/logger", () => ({
@@ -14,6 +19,93 @@ vi.mock("@app/lib/logger", () => ({
const alias = (externalId: string, userId: string) => ({ externalId, userId });
+describe("resolveAssertedProfileName", () => {
+ test("uses the structured claims when the given name is asserted", () => {
+ expect(resolveAssertedProfileName({ givenName: "Jane", familyName: "Doe", displayName: "Jane Doe" })).toEqual({
+ firstName: "Jane",
+ lastName: "Doe"
+ });
+ });
+
+ test("keeps the given name even when no surname is asserted", () => {
+ expect(resolveAssertedProfileName({ givenName: "Jane" })).toEqual({ firstName: "Jane", lastName: "" });
+ });
+
+ // The regression this function exists for: the composite name carries the surname already, so
+ // taking the surname from family_name as well rendered it twice ("Jane Doe Doe").
+ test("removes the surname from the composite name when the given name is missing", () => {
+ expect(resolveAssertedProfileName({ familyName: "Doe", displayName: "Jane Doe" })).toEqual({
+ firstName: "Jane",
+ lastName: "Doe"
+ });
+ });
+
+ test("removes a multi-part surname from the composite name", () => {
+ expect(resolveAssertedProfileName({ familyName: "García López", displayName: "Juan García López" })).toEqual({
+ firstName: "Juan",
+ lastName: "García López"
+ });
+ });
+
+ // A family-name-first locale puts the surname at the start, so the suffix match must not fire and
+ // the whole name is kept as-is rather than being split on a guess.
+ test("keeps the whole composite name when the surname is not a trailing part of it", () => {
+ expect(resolveAssertedProfileName({ familyName: "Nagy", displayName: "Nagy János" })).toEqual({
+ firstName: "Nagy János",
+ lastName: ""
+ });
+ });
+
+ test("keeps the whole composite name when a suffix follows the surname", () => {
+ expect(resolveAssertedProfileName({ familyName: "Doe", displayName: "Jane Doe Jr." })).toEqual({
+ firstName: "Jane Doe Jr.",
+ lastName: ""
+ });
+ });
+
+ test("keeps the whole composite name when only part of the surname trails it", () => {
+ expect(resolveAssertedProfileName({ familyName: "García López", displayName: "Juan López" })).toEqual({
+ firstName: "Juan López",
+ lastName: ""
+ });
+ });
+
+ test("keeps the composite name when no surname is asserted", () => {
+ expect(resolveAssertedProfileName({ displayName: "Jane Doe" })).toEqual({
+ firstName: "Jane Doe",
+ lastName: ""
+ });
+ });
+
+ // Stripping here would leave an empty first name, so the composite is kept whole instead.
+ test("keeps the composite name when it consists only of the surname", () => {
+ expect(resolveAssertedProfileName({ familyName: "Doe", displayName: "Doe" })).toEqual({
+ firstName: "Doe",
+ lastName: ""
+ });
+ });
+
+ test("still resolves when the given name repeats the surname", () => {
+ expect(resolveAssertedProfileName({ familyName: "Doe", displayName: "Doe Doe" })).toEqual({
+ firstName: "Doe",
+ lastName: "Doe"
+ });
+ });
+
+ test("ignores whitespace-only assertions", () => {
+ expect(resolveAssertedProfileName({ givenName: " ", familyName: " ", displayName: " Jane Doe " })).toEqual({
+ firstName: "Jane Doe",
+ lastName: ""
+ });
+ });
+
+ 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();
+ });
+});
+
describe("resolveAliasUserIds", () => {
test("resolves an identifier to the user its alias points at", () => {
const { userIdByIdentifier, ambiguousIdentifiers } = resolveAliasUserIds({
diff --git a/backend/src/services/user-alias/user-alias-fns.ts b/backend/src/services/user-alias/user-alias-fns.ts
index b31cd4b5a6..ce4ea15b8d 100644
--- a/backend/src/services/user-alias/user-alias-fns.ts
+++ b/backend/src/services/user-alias/user-alias-fns.ts
@@ -34,6 +34,15 @@ type TIsStaleSsoAliasDTO = {
assertedEmail: string;
};
+type TResolveAssertedProfileNameDTO = {
+ // OIDC `given_name` / LDAP `givenName`.
+ givenName?: string | null;
+ // OIDC `family_name` / LDAP `sn`.
+ familyName?: string | null;
+ // The composite display name: OIDC `name` / LDAP `cn`.
+ displayName?: string | null;
+};
+
/**
* The legacy SSO flow persisted aliases before email verification completed, so an as-yet-unverified
* alias may point at a different user's account. Such an alias is "stale" when the email asserted by
@@ -56,6 +65,26 @@ export const isStaleSsoAlias = ({ user, userAlias, assertedEmail }: TIsStaleSsoA
return !normalizedAssertedEmail || !accountEmails.has(normalizedAssertedEmail);
};
+export const resolveAssertedProfileName = ({
+ givenName,
+ familyName,
+ displayName
+}: TResolveAssertedProfileNameDTO): { firstName: string; lastName: string } | null => {
+ const given = givenName?.trim();
+ const family = familyName?.trim();
+ const display = displayName?.trim();
+
+ if (given) return { firstName: given, lastName: family || "" };
+ if (!display) return null;
+
+ if (family && display.endsWith(` ${family}`)) {
+ const remainder = display.slice(0, -(family.length + 1)).trim();
+ if (remainder) return { firstName: remainder, lastName: family };
+ }
+
+ return { firstName: display, lastName: "" };
+};
+
/**
* When an org enforces SSO, the verified domain + IdP are authoritative, so we skip the separate
* email-verification step. This marks the user + alias as verified/accepted before a session is
diff --git a/docs/documentation/platform/sso/auth0-oidc.mdx b/docs/documentation/platform/sso/auth0-oidc.mdx
index 3a271200b7..44dd92d1cf 100644
--- a/docs/documentation/platform/sso/auth0-oidc.mdx
+++ b/docs/documentation/platform/sso/auth0-oidc.mdx
@@ -32,6 +32,10 @@ description: "Learn how to configure Auth0 OIDC for Infisical SSO."
1.3. Proceed to the Connections Tab and enable desired connections.
![OIDC auth0 application connections](../../../images/sso/auth0-oidc/application-connections.png)
+ <Note>
+ Infisical takes a user's name from the `given_name` and `family_name` claims, so make sure both are set on your Auth0 users. If `given_name` is missing, Infisical falls back to the `name` claim. See [General OIDC](/documentation/platform/sso/general-oidc/overview) for how that fallback resolves.
+ </Note>
+
</Step>
<Step title="Retrieve Identity Provider (IdP) Information from Auth0">
2.1. From the application settings page, retrieve the **Client ID** and **Client Secret**
diff --git a/docs/documentation/platform/sso/auth0-saml.mdx b/docs/documentation/platform/sso/auth0-saml.mdx
index c92f3e5f04..ea5b9d7e39 100644
--- a/docs/documentation/platform/sso/auth0-saml.mdx
+++ b/docs/documentation/platform/sso/auth0-saml.mdx
@@ -69,7 +69,7 @@ description: "Learn how to configure Auth0 SAML for Infisical SSO."
Click **Save**.
<Warning>
- Make sure the `firstName` claim is mapped to a valid field of your Auth0 users. If your users don't have a `"given_name"` field available, you can replace it with `"name"` or another field that exists in your user profile on the left side of the mapping.
+ Make sure the `firstName` claim is mapped to a valid field of your Auth0 users. If your users don't have a `"given_name"` field available, you can replace it with `"name"` or another field that exists in your user profile on the left side of the mapping. Because `"name"` holds a user's full name, remove the `family_name` mapping when you do, otherwise the surname shows up twice in Infisical.
</Warning>
</Step>
<Step title="Enable SAML SSO in Infisical">
diff --git a/docs/documentation/platform/sso/general-oidc/overview.mdx b/docs/documentation/platform/sso/general-oidc/overview.mdx
index f6bc151c82..2d89a9eb4f 100644
--- a/docs/documentation/platform/sso/general-oidc/overview.mdx
+++ b/docs/documentation/platform/sso/general-oidc/overview.mdx
@@ -21,7 +21,7 @@ You can configure your organization in Infisical to have members authenticate wi
Prerequisites:
- The identity provider (Okta, Google, Entra ID, etc.) should support OIDC.
-- Users in the IdP should have a configured `email` and `given_name`.
+- Users in the IdP should have a configured `email`, `given_name`, and `family_name`.
<Steps>
<Step title="Setup Identity Provider">
@@ -31,6 +31,10 @@ Prerequisites:
1.3. Configure the scopes needed by Infisical (email, profile, openid) and ensure that they are mapped to the ID token claims.
+ <Note>
+ Infisical takes a user's first name from the `given_name` claim and their last name from `family_name`. If your IdP doesn't send `given_name`, Infisical falls back to the `name` claim and removes `family_name` from the end of it. When `family_name` isn't at the end of `name`, Infisical keeps the whole `name` as the first name.
+ </Note>
+
1.4. Access the IdP’s OIDC discovery document (usually located at `https://<idp-domain>/.well-known/openid-configuration`). This document contains important endpoints such as authorization, token, userinfo, and keys.
</Step>
<Step title="Finish configuring OIDC in Infisical">
diff --git a/docs/documentation/platform/sso/okta-oidc.mdx b/docs/documentation/platform/sso/okta-oidc.mdx
index 036b64371d..4fbcdb7a76 100644
--- a/docs/documentation/platform/sso/okta-oidc.mdx
+++ b/docs/documentation/platform/sso/okta-oidc.mdx
@@ -48,6 +48,10 @@ description: "Learn how to configure Okta OIDC for Infisical SSO."
Infisical does not currently support DPoP for OIDC authentication.
</Warning>
+ <Note>
+ Infisical takes a user's name from the `given_name` and `family_name` claims, so make sure both are set on your Okta users. If `given_name` is missing, Infisical falls back to the `name` claim. See [General OIDC](/documentation/platform/sso/general-oidc/overview) for how that fallback resolves.
+ </Note>
+
</Step>
<Step title="Retrieve Identity Provider (IdP) Information from Okta">
After creating the application, you'll be taken to the application's settings page. From the **General** tab, copy the **Client ID** and **Client Secret** values.
diff --git a/docs/documentation/platform/sso/pingone-oidc.mdx b/docs/documentation/platform/sso/pingone-oidc.mdx
index 3de4777795..6e2cc8429f 100644
--- a/docs/documentation/platform/sso/pingone-oidc.mdx
+++ b/docs/documentation/platform/sso/pingone-oidc.mdx
@@ -42,11 +42,16 @@ description: "Learn how to configure PingOne OIDC for Infisical SSO."
1.6 Map the following attributes:
- `email` -> `Email Address`
- - `name` -> `Username`
+ - `given_name` -> `Given Name`
+ - `family_name` -> `Family Name`
![OIDC PingOne Edit Attribute Mappings](../../../images/sso/pingone-oidc/pingone-edit-application-attribute-mappings-2.png)
Once done, press the "Save" button.
+ <Note>
+ Infisical takes a user's name from the `given_name` and `family_name` claims. If you map `name` instead, Infisical falls back to it and stores the whole name as the user's first name. See [General OIDC](/documentation/platform/sso/general-oidc/overview) for how that fallback resolves.
+ </Note>
+
</Step>
<Step title="Retrieve Identity Provider (IdP) Information from PingOne">
2.1. Open the "Overview" tab and copy the **Client ID** and **Client Secret**.