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: resolved the logout race condition
=20916ca7f3c4
diff --git a/backend/src/server/routes/v3/signup-router.ts b/backend/src/server/routes/v3/signup-router.tsindex d88dd52a81..22f21870c7 100644--- a/backend/src/server/routes/v3/signup-router.ts+++ b/backend/src/server/routes/v3/signup-router.ts@@ -166,7 +166,7 @@ export const registerSignupRouter = async (server: FastifyZodProvider) => {void res.setCookie("jid", refreshToken, {httpOnly: true,- path: "/",+ path: "/api",sameSite: "strict",secure: appCfg.HTTPS_ENABLED});diff --git a/backend/src/services/auth/auth-login-service.ts b/backend/src/services/auth/auth-login-service.tsindex 07b069cc75..88c2079032 100644--- a/backend/src/services/auth/auth-login-service.ts+++ b/backend/src/services/auth/auth-login-service.ts@@ -404,8 +404,7 @@ export const authLoginServiceFactory = ({const appCfg = getConfig();try {- const users = await userDAL.findUserByUsername(email);- const user = users?.[0];+ const user = await userDAL.findOne({ username: email });if (!user) {logger.error(`Failed to find user for email ${email}`);throw new BadRequestError({ message: "Invalid credentials" });diff --git a/backend/src/services/auth/auth-signup-service.ts b/backend/src/services/auth/auth-signup-service.tsindex 64aa2611a1..eef6e94668 100644--- a/backend/src/services/auth/auth-signup-service.ts+++ b/backend/src/services/auth/auth-signup-service.ts@@ -150,7 +150,7 @@ export const authSignupServiceFactory = ({const dummyUserId = "00000000-0000-0000-0000-000000000000";validateSignUpAuthorization(authorization, user?.id ?? dummyUserId);- if (!user || (user && (user.isAccepted || !user.isEmailVerified))) {+ if (!user || (user && user.isAccepted)) {throw new BadRequestError({ message: "Failed to complete account for complete user" });}@@ -173,19 +173,8 @@ export const authSignupServiceFactory = ({const hashedPassword = await crypto.hashing().createHash(password, appCfg.SALT_ROUNDS);const updatedUser = await authDAL.transaction(async (tx) => {- const us = await userDAL.updateById(user.id, { firstName, lastName, isAccepted: true }, tx);- if (!us) throw new Error("User not found");-- const userEncKey = await userDAL.upsertUserEncryptionKey(- us.id,- {- encryptionVersion: UserEncryption.V2,- hashedPassword- },- tx- );-- return { info: us, key: userEncKey };+ const us = await userDAL.updateById(user.id, { firstName, lastName, isAccepted: true, hashedPassword }, tx);+ return { ...us, hashedPassword: null };});// If self-signup, create a default organization@@ -204,7 +193,7 @@ export const authSignupServiceFactory = ({const tokenSession = await tokenService.getUserTokenSession({userAgent,ip,- userId: updatedUser.info.id+ userId: updatedUser.id});if (!tokenSession) throw new Error("Failed to create token");@@ -212,7 +201,7 @@ export const authSignupServiceFactory = ({{authMethod: AuthMethod.EMAIL,authTokenType: AuthTokenType.ACCESS_TOKEN,- userId: updatedUser.info.id,+ userId: updatedUser.id,tokenVersionId: tokenSession.id,accessVersion: tokenSession.accessVersion},@@ -223,7 +212,7 @@ export const authSignupServiceFactory = ({const refreshToken = crypto.jwt().sign({authTokenType: AuthTokenType.REFRESH_TOKEN,- userId: updatedUser.info.id,+ userId: updatedUser.id,tokenVersionId: tokenSession.id,refreshVersion: tokenSession.refreshVersion},@@ -232,7 +221,8 @@ export const authSignupServiceFactory = ({);return {- user: updatedUser.info,+ user: updatedUser,+ isInvitedUser,accessToken,refreshToken,authMethod: AuthMethod.EMAILdiff --git a/backend/src/services/user/user-service.ts b/backend/src/services/user/user-service.tsindex 3c01d2a5d6..c0ce2c6e4f 100644--- a/backend/src/services/user/user-service.ts+++ b/backend/src/services/user/user-service.ts@@ -340,12 +340,13 @@ export const userServiceFactory = ({};const getMe = async (userId: string) => {- const user = await userDAL.findUserEncKeyByUserId(userId);+ const user = await userDAL.findById(userId);if (!user) throw new NotFoundError({ message: `User with ID '${userId}' not found`, name: "GetMe" });return {...user,- encryptionVersion: user.encryptionVersion!+ hashedPassword: null,+ encryptionVersion: 2};};diff --git a/frontend/src/components/auth/Mfa.tsx b/frontend/src/components/auth/Mfa.tsxindex 7fe4989c6d..b6da43dce7 100644--- a/frontend/src/components/auth/Mfa.tsx+++ b/frontend/src/components/auth/Mfa.tsx@@ -84,7 +84,7 @@ export const Mfa = ({ successCallback, closeMfa, hideLogo, email, method }: Propconst [shouldShowWebAuthnRegistration, setShouldShowWebAuthnRegistration] = useState(false);const [credentialName, setCredentialName] = useState("");const [isRegisteringPasskey, setIsRegisteringPasskey] = useState(false);- const logout = useLogoutUser(true);+ const logout = useLogoutUser();const { mutateAsync: generateWebAuthnAuthenticationOptions } = useGenerateAuthenticationOptions();const { mutateAsync: verifyWebAuthnAuthentication } = useVerifyAuthentication();diff --git a/frontend/src/hooks/api/users/queries.tsx b/frontend/src/hooks/api/users/queries.tsxindex 7f553b5720..ce9d5cd802 100644--- a/frontend/src/hooks/api/users/queries.tsx+++ b/frontend/src/hooks/api/users/queries.tsx@@ -325,7 +325,7 @@ export const logoutUser = async () => {};// Utility function to clear session storage and query cache-export const clearSession = (keepQueryClient?: boolean) => {+export const clearSession = () => {setAuthToken(""); // Clear authentication tokenlocalStorage.removeItem("protectedKey");localStorage.removeItem("protectedKeyIV");@@ -338,21 +338,29 @@ export const clearSession = (keepQueryClient?: boolean) => {localStorage.removeItem("orgData.id");sessionStorage.removeItem(SessionStorageKeys.CLI_TERMINAL_TOKEN);- if (!keepQueryClient) {- qc.clear();- }+ qc.clear();};-export const useLogoutUser = (keepQueryClient?: boolean) => {+let logoutTimer: ReturnType<typeof setTimeout> | null = null;++export const useLogoutUser = () => {return useMutation({mutationFn: async () => {- // Cancel all in-flight queries and clear token before the logout call- // to prevent 401 interceptor from triggering refresh attempts- qc.cancelQueries();+ if (logoutTimer) {+ clearTimeout(logoutTimer);+ logoutTimer = null;+ }setAuthToken("");await logoutUser();},- onSuccess: () => clearSession(keepQueryClient)+ onSuccess: () => {+ // Delay cache clear so the route transition completes first and+ // useSuspenseQuery components unmount before their cache is removed.+ logoutTimer = setTimeout(() => {+ clearSession();+ logoutTimer = null;+ }, 500);+ }});};diff --git a/frontend/src/layouts/OrganizationLayout/components/NavBar/Navbar.tsx b/frontend/src/layouts/OrganizationLayout/components/NavBar/Navbar.tsxindex c7274415ff..74c75c2f31 100644--- a/frontend/src/layouts/OrganizationLayout/components/NavBar/Navbar.tsx+++ b/frontend/src/layouts/OrganizationLayout/components/NavBar/Navbar.tsx@@ -269,7 +269,6 @@ export const Navbar = () => {const logout = useLogoutUser();const logOutUser = async () => {try {- console.log("Logging out...");await logout.mutateAsync();navigate({ to: "/login" });} catch (error) {diff --git a/frontend/src/pages/auth/SelectOrgPage/EmailDuplicationConfirmation.tsx b/frontend/src/pages/auth/SelectOrgPage/EmailDuplicationConfirmation.tsxindex 5fa158f937..8fba090a4c 100644--- a/frontend/src/pages/auth/SelectOrgPage/EmailDuplicationConfirmation.tsx+++ b/frontend/src/pages/auth/SelectOrgPage/EmailDuplicationConfirmation.tsx@@ -24,7 +24,7 @@ export const EmailDuplicationConfirmation = ({ onRemoveDuplicateLater }: Props)const removeDuplicateEmails = useRemoveMyDuplicateAccounts();const { t } = useTranslation();const navigate = useNavigate();- const logout = useLogoutUser(true);+ const logout = useLogoutUser();const { popUp, handlePopUpToggle } = usePopUp(["removeDuplicateConfirm"] as const);const handleLogout = useCallback(async () => {try {diff --git a/frontend/src/pages/auth/SelectOrgPage/SelectOrgSection.tsx b/frontend/src/pages/auth/SelectOrgPage/SelectOrgSection.tsxindex 967b59e1de..79d250c6cc 100644--- a/frontend/src/pages/auth/SelectOrgPage/SelectOrgSection.tsx+++ b/frontend/src/pages/auth/SelectOrgPage/SelectOrgSection.tsx@@ -62,7 +62,7 @@ export const SelectOrganizationSection = () => {const isLoadingSubOrgCheck =Boolean(defaultSelectedOrg) && !callbackPort && orgsWithSubOrgs.isPending;- const logout = useLogoutUser(true);+ const logout = useLogoutUser();const handleLogout = useCallback(async () => {try {await logout.mutateAsync();