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 alias bypass and analytics
Scott Wilsona639605b6e0d
diff --git a/backend/e2e-test/routes/v3/auth-signup-oauth.spec.ts b/backend/e2e-test/routes/v3/auth-signup-oauth.spec.tsindex 6a3aa60cd1..0cebd8b1e2 100644--- a/backend/e2e-test/routes/v3/auth-signup-oauth.spec.ts+++ b/backend/e2e-test/routes/v3/auth-signup-oauth.spec.ts@@ -134,6 +134,48 @@ describe("Auth OAuth Signup V3 (provider-attested email verification)", () => {expect(second.result).toBe(ProviderAuthResult.SESSION);expect(second.didCompleteSignup).toBe(false);});++ test("a brand-new alias must not inherit a user-level provider flag for a provider-unverified email", async () => {+ // The victim previously completed a verified GitHub login, so their per-account GitHub flag is+ // set. authMethods already includes GitHub, so this login takes the email-fallback backfill+ // path (a new alias for a different externalId) rather than the link path.+ const email = `oauth-flag-inherit-${crypto.randomUUID()}@localhost.local`;+ const [victim] = await getDb()(TableName.Users)+ .insert({+ username: email,+ email,+ isAccepted: true,+ isEmailVerified: true,+ isGhost: false,+ isGitHubVerified: true,+ authMethods: [AuthMethod.GITHUB]+ })+ .returning("*");+ createdUserIds.push(victim.id);++ // A different GitHub account lists the victim's email as UNVERIFIED.+ const attackerExternalId = `github-attacker-${crypto.randomUUID()}`;+ const result = await oauthLogin({+ email,+ isEmailVerifiedByProvider: false,+ authMethod: AuthMethod.GITHUB,+ providerUserId: attackerExternalId+ });++ // No session off the inherited flag: our own verification is still required.+ expect(result.result).toBe(ProviderAuthResult.SIGNUP_REQUIRED);+ expect(result.signupToken).toBeDefined();+ expect(result.didCompleteSignup).toBe(false);++ // The verification code goes to the real inbox owner, who alone can complete it.+ expect(findEmailTo(email)).toBeDefined();++ // The backfilled alias for the new identity stays unverified.+ const attackerAlias = await getDb()(TableName.UserAliases)+ .where({ userId: victim.id, externalId: attackerExternalId })+ .first();+ expect(attackerAlias?.isEmailVerified).toBe(false);+ });});describe("provider verified the email -> a session is issued directly, no completion step", () => {diff --git a/backend/src/server/routes/v1/sso-router.ts b/backend/src/server/routes/v1/sso-router.tsindex da3a6e4c5e..f65842c9ef 100644--- a/backend/src/server/routes/v1/sso-router.ts+++ b/backend/src/server/routes/v1/sso-router.ts@@ -462,11 +462,14 @@ export const registerSsoRouter = async (server: FastifyZodProvider) => {// through complete-account; fire the signup telemetry that route would have sent.if (passportResult.didCompleteSignup) {const { user } = passportResult;+ // An invited user completing signup via a provider-verified email is tagged as an invite for+ // parity with the complete-account route that this provider-verified flow bypasses.+ const signupMethod = passportResult.wasInvited ? "invite" : passportResult.authMethod;if (user.email) {void server.services.telemetry.sendLoopsEvent(user.email, user.firstName || "", user.lastName || "");void server.services.telemetry.sendHubSpotSignupEvent(user.email,- passportResult.authMethod,+ signupMethod,user.firstName || "",user.lastName || "",typeof req.cookies?.hubspotutk === "string" ? req.cookies.hubspotutk.slice(0, 512) : undefined@@ -479,7 +482,8 @@ export const registerSsoRouter = async (server: FastifyZodProvider) => {properties: {username: user.username,email: user.email ?? "",- signupMethod: passportResult.authMethod+ ...(passportResult.wasInvited ? { attributionSource: "Team Invite" } : {}),+ signupMethod}});}@@ -494,6 +498,9 @@ export const registerSsoRouter = async (server: FastifyZodProvider) => {const sessionUrl = new URL("/login/select-organization", appCfg.SITE_URL);if (isAdminLogin) sessionUrl.searchParams.set("isAdminLogin", isAdminLogin);if (cbPort) sessionUrl.searchParams.set("callback_port", String(cbPort));+ // Provider-verified signups never render the signup page that pushes the GTM conversion event,+ // so flag the org-selection page to fire it on arrival.+ if (passportResult.didCompleteSignup) sessionUrl.searchParams.set("signup_completed", "true");return res.redirect(sessionUrl.toString());}diff --git a/backend/src/services/auth/auth-login-service.ts b/backend/src/services/auth/auth-login-service.tsindex 940a3d20f1..dc03472886 100644--- a/backend/src/services/auth/auth-login-service.ts+++ b/backend/src/services/auth/auth-login-service.ts@@ -867,6 +867,14 @@ export const authLoginServiceFactory = ({// user's signup (used by the caller to fire signup telemetry exactly once per account).const wasUserAcceptedBeforeLogin = Boolean(user?.isAccepted);+ // Mirror complete-account's invite detection: a not-yet-accepted user who already has an org+ // membership was invited (the inviter created it), versus an organic signup that has none yet.+ // Only meaningful when this login completes the signup, so skip the read for accepted users.+ const wasInvited =+ !wasUserAcceptedBeforeLogin && user+ ? (await orgDAL.findMembership({ actorUserId: user.id, scope: AccessScope.Organization })).length > 0+ : false;+const serverCfg = await getServerCfg();if (serverCfg.enabledLoginMethods && user) {@@ -1083,14 +1091,18 @@ export const authLoginServiceFactory = ({}// Skip our own email verification when the provider already verified the email, or when the- // user previously verified it through this provider (persisted user-level flag).+ // user previously verified it through this provider (persisted user-level flag). The user-level+ // flag is per account, not per provider-identity, so it is only trusted for an existing alias: a+ // brand-new alias (email-fallback backfill) for a different externalId must prove the email via+ // the provider. Otherwise a new provider account asserting an existing user's provider-unverified+ // email would inherit the flag and mint a session as that user.let isAliasVerified = false;if (authMethod === AuthMethod.GOOGLE) {- isAliasVerified = isEmailVerifiedByProvider || Boolean(user.isGoogleVerified);+ isAliasVerified = isEmailVerifiedByProvider || (!isNewAlias && Boolean(user.isGoogleVerified));} else if (authMethod === AuthMethod.GITHUB) {- isAliasVerified = isEmailVerifiedByProvider || Boolean(user.isGitHubVerified);+ isAliasVerified = isEmailVerifiedByProvider || (!isNewAlias && Boolean(user.isGitHubVerified));} else if (authMethod === AuthMethod.GITLAB) {- isAliasVerified = isEmailVerifiedByProvider || Boolean(user.isGitLabVerified);+ isAliasVerified = isEmailVerifiedByProvider || (!isNewAlias && Boolean(user.isGitLabVerified));}// Self-healing backfill: create alias for existing users found by email fallbackif (isNewAlias) {@@ -1168,6 +1180,8 @@ export const authLoginServiceFactory = ({...callbackResult,user: { ...user, hashedPassword: null },didCompleteSignup,+ // meaningful only alongside didCompleteSignup: tags the completed signup as an invite+ wasInvited,authMethod,orgId,orgNamediff --git a/frontend/src/pages/auth/SelectOrgPage/route.tsx b/frontend/src/pages/auth/SelectOrgPage/route.tsxindex ab4efa5105..d18dfdaaf7 100644--- a/frontend/src/pages/auth/SelectOrgPage/route.tsx+++ b/frontend/src/pages/auth/SelectOrgPage/route.tsx@@ -5,6 +5,7 @@ import { z } from "zod";import { createNotification } from "@app/components/notifications";import { SessionStorageKeys } from "@app/const";+import { isInfisicalCloud } from "@app/helpers/platform";import { authKeys, selectOrganization } from "@app/hooks/api/auth/queries";import { UserAgentType } from "@app/hooks/api/auth/types";import {@@ -21,7 +22,10 @@ export const SelectOrganizationPageQueryParams = z.object({callback_port: z.coerce.number().optional().catch(undefined),is_admin_login: z.boolean().optional().catch(false),force: z.boolean().optional(),- mfa_method: z.string().optional().catch(undefined)+ mfa_method: z.string().optional().catch(undefined),+ // set by the provider-verified OAuth signup redirect so this page can fire the GTM conversion+ // event that the bypassed signup page would have pushed+ signup_completed: z.boolean().optional().catch(false)});export const Route = createFileRoute("/_restrict-login-signup/login/select-organization")({@@ -38,6 +42,14 @@ export const Route = createFileRoute("/_restrict-login-signup/login/select-organ]},beforeLoad: async ({ context, search }) => {+ // Provider-verified OAuth signups complete server-side and land here directly, bypassing the+ // signup page that normally pushes this conversion event. Fire it before any auto-select+ // redirect so the common single-org case is still counted (cloud only).+ if (search.signup_completed && isInfisicalCloud()) {+ window.dataLayer = window.dataLayer || [];+ window.dataLayer.push({ event: "signup_completed" });+ }+// Skip auto-select for MFA pending or force flagif (search.mfa_method || search.force) return;