Skip to content

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

feat: resolved review feedbacks, doc issue

=cff2ff698366
diff --git a/backend/src/db/migrations/20260404140728_username-merge.ts b/backend/src/db/migrations/20260404140728_username-merge.ts
index b0fd28ace1..ec46b52d7e 100644
--- a/backend/src/db/migrations/20260404140728_username-merge.ts
+++ b/backend/src/db/migrations/20260404140728_username-merge.ts
@@ -116,10 +116,13 @@ export async function up(knex: Knex): Promise<void> {
// that would conflict (unique constraint), the update will fail for that row.
// So we do it in two steps: update what we can, leave the rest for CASCADE delete.
try {
+ await knex.raw("SAVEPOINT fk_reassign");
await knex(ref.table_name)
.whereIn(ref.column_name, loserIds)
.update({ [ref.column_name]: winner.id });
+ await knex.raw("RELEASE SAVEPOINT fk_reassign");
} catch (err: unknown) {
+ await knex.raw("ROLLBACK TO SAVEPOINT fk_reassign");
// Unique constraint violation (23505) — some rows couldn't be reassigned.
// That's fine — they'll be cleaned up by CASCADE when the loser user is deleted.
if ((err as { code?: string })?.code !== "23505") {
diff --git a/backend/src/ee/services/oidc/oidc-config-service.ts b/backend/src/ee/services/oidc/oidc-config-service.ts
index 1234bcd394..2cd375f2b7 100644
--- a/backend/src/ee/services/oidc/oidc-config-service.ts
+++ b/backend/src/ee/services/oidc/oidc-config-service.ts
@@ -267,7 +267,7 @@ export const oidcConfigServiceFactory = ({
if (!newUser) {
newUser = await userDAL.create(
{
- email,
+ email: sanitizedEmail,
firstName,
username: sanitizedEmail,
lastName,
diff --git a/frontend/src/config/request.ts b/frontend/src/config/request.ts
index 53815c7d09..51ff948bb6 100644
--- a/frontend/src/config/request.ts
+++ b/frontend/src/config/request.ts
@@ -20,6 +20,9 @@ export const apiRequest = axios.create({
});
apiRequest.interceptors.request.use((config) => {
+ // Skip auto-injection if the caller already set an Authorization header
+ if (config.headers?.Authorization) return config;
+
const signupTempToken = getSignupTempToken();
const mfaTempToken = getMfaTempToken();
const token = getAuthToken();
diff --git a/frontend/src/hooks/api/organization/queries.tsx b/frontend/src/hooks/api/organization/queries.tsx
index ce7ebea338..a8f78ac01e 100644
--- a/frontend/src/hooks/api/organization/queries.tsx
+++ b/frontend/src/hooks/api/organization/queries.tsx
@@ -4,6 +4,7 @@ import { apiRequest } from "@app/config/request";
import { OrderByDirection } from "@app/hooks/api/generic/types";
import { TGroupOrgMembership } from "../groups/types";
+import { getAuthToken } from "../reactQuery";
import { TOrgRole } from "../roles/types";
import { IntegrationAuth } from "../types";
import {
@@ -71,10 +72,16 @@ export const useGetOrganizations = () => {
};
export const fetchOrganizationsWithSubOrgs = async () => {
+ // prioritize auth token
+ const authToken = getAuthToken();
+
const {
data: { organizations }
} = await apiRequest.get<{ organizations: TOrgWithSubOrgs[] }>(
- "/api/v1/organization/accessible-with-sub-orgs"
+ "/api/v1/organization/accessible-with-sub-orgs",
+ {
+ headers: authToken ? { Authorization: `Bearer ${authToken}` } : undefined
+ }
);
return organizations;
};
diff --git a/frontend/src/hooks/api/users/queries.tsx b/frontend/src/hooks/api/users/queries.tsx
index 6660f9c311..3a1bedc484 100644
--- a/frontend/src/hooks/api/users/queries.tsx
+++ b/frontend/src/hooks/api/users/queries.tsx
@@ -3,7 +3,7 @@ import { AxiosError } from "axios";
import { apiRequest } from "@app/config/request";
import { SessionStorageKeys } from "@app/const";
-import { queryClient as qc } from "@app/hooks/api/reactQuery";
+import { getAuthToken, queryClient as qc } from "@app/hooks/api/reactQuery";
import { APIKeyDataV2 } from "../apiKeys/types";
import { authKeys } from "../auth/queries";
@@ -29,7 +29,12 @@ import {
} from "./types";
export const fetchUserDetails = async () => {
- const { data } = await apiRequest.get<{ user: User & UserEnc }>("/api/v1/user");
+ // prioritize auth token
+ const authToken = getAuthToken();
+
+ const { data } = await apiRequest.get<{ user: User & UserEnc }>("/api/v1/user", {
+ headers: authToken ? { Authorization: `Bearer ${authToken}` } : undefined
+ });
return data.user;
};
diff --git a/frontend/src/pages/auth/CliRedirectPage/CliRedirectPage.tsx b/frontend/src/pages/auth/CliRedirectPage/CliRedirectPage.tsx
index 9df3f03fb2..263ecb2bbd 100644
--- a/frontend/src/pages/auth/CliRedirectPage/CliRedirectPage.tsx
+++ b/frontend/src/pages/auth/CliRedirectPage/CliRedirectPage.tsx
@@ -57,7 +57,7 @@ export const CliRedirectPage = () => {
<p className="bg-linear-to-b from-white to-bunker-200 bg-clip-text text-center text-3xl font-medium text-transparent">
Unable to reach CLI
</p>
- <p className="text-light mb-1 text-center text-lg text-mineshaft-400">
+ <p className="text-light mt-2 mb-1 text-center text-lg text-mineshaft-400">
Your login was successful but, Infisical couldn&apos;t automatically push your login
token to the CLI.
</p>
diff --git a/frontend/src/pages/auth/CliRedirectPage/route.tsx b/frontend/src/pages/auth/CliRedirectPage/route.tsx
index 098c81a588..7577ffbe2b 100644
--- a/frontend/src/pages/auth/CliRedirectPage/route.tsx
+++ b/frontend/src/pages/auth/CliRedirectPage/route.tsx
@@ -1,7 +1,33 @@
import { createFileRoute } from "@tanstack/react-router";
+import axios from "axios";
+
+import { SessionStorageKeys } from "@app/const";
import { CliRedirectPage } from "./CliRedirectPage";
export const Route = createFileRoute("/cli-redirect")({
- component: CliRedirectPage
+ component: CliRedirectPage,
+ beforeLoad: async () => {
+ const cliTerminalTokenInfo = sessionStorage.getItem(SessionStorageKeys.CLI_TERMINAL_TOKEN);
+ if (!cliTerminalTokenInfo) return;
+
+ try {
+ const { expiry, data, callbackPort } = JSON.parse(cliTerminalTokenInfo);
+ if (new Date() > new Date(expiry)) {
+ sessionStorage.removeItem(SessionStorageKeys.CLI_TERMINAL_TOKEN);
+ return;
+ }
+
+ if (!callbackPort) return;
+
+ const payload = JSON.parse(window.atob(data));
+ const instance = axios.create();
+ await instance.post(`http://127.0.0.1:${callbackPort}/`, payload);
+
+ // POST succeeded — clear the token so the page shows the success message
+ sessionStorage.removeItem(SessionStorageKeys.CLI_TERMINAL_TOKEN);
+ } catch {
+ // POST failed — token stays in session storage so the page shows the fallback UI
+ }
+ }
});
diff --git a/frontend/src/pages/auth/SelectOrgPage/SelectOrgPage.tsx b/frontend/src/pages/auth/SelectOrgPage/SelectOrgPage.tsx
index e182dfc29b..e010668ee7 100644
--- a/frontend/src/pages/auth/SelectOrgPage/SelectOrgPage.tsx
+++ b/frontend/src/pages/auth/SelectOrgPage/SelectOrgPage.tsx
@@ -1,15 +1,13 @@
-import { useCallback, useEffect, useMemo, useState } from "react";
+import { useCallback, useEffect, useMemo, useRef, useState } from "react";
import { Helmet } from "react-helmet";
import { useTranslation } from "react-i18next";
import { Link, useNavigate, useRouter, useSearch } from "@tanstack/react-router";
-import axios from "axios";
import { addSeconds, format, formatISO } from "date-fns";
import { jwtDecode } from "jwt-decode";
import { ChevronRight, LogIn, Search } from "lucide-react";
import { Mfa } from "@app/components/auth/Mfa";
import { createNotification } from "@app/components/notifications";
-import { IsCliLoginSuccessful } from "@app/components/utilities/attemptCliLogin";
import SecurityClient from "@app/components/utilities/SecurityClient";
import { Button, ContentLoader, Input, Spinner } from "@app/components/v2";
import { SessionStorageKeys } from "@app/const";
@@ -78,7 +76,7 @@ export const SelectOrgPage = () => {
org_id: orgId,
callback_port: callbackPort,
is_admin_login: isBreakglassRoute,
- mfa_pending: mfaPending
+ mfa_method: mfaMethodFromSearch
} = search;
const { data: orgs, isPending: orgsLoading } = useGetOrganizationsWithSubOrgs();
@@ -87,10 +85,12 @@ export const SelectOrgPage = () => {
const logout = useLogoutUser();
const [shouldShowMfa, toggleShowMfa] = useToggle(false);
- const [requiredMfaMethod, setRequiredMfaMethod] = useState(MfaMethod.EMAIL);
+ const [requiredMfaMethod, setRequiredMfaMethod] = useState(
+ mfaMethodFromSearch ?? MfaMethod.EMAIL
+ );
const [selectedRootOrg, setSelectedRootOrg] = useState<TOrgWithSubOrgs | null>(null);
const [searchTerm, setSearchTerm] = useState("");
- const [mfaSuccessCallback, setMfaSuccessCallback] = useState<() => void>(() => {});
+ const mfaSuccessCallback = useRef<() => void>(() => {});
const handleLogout = useCallback(async () => {
try {
@@ -204,7 +204,7 @@ export const SelectOrgPage = () => {
setRequiredMfaMethod(mfaMethod);
}
toggleShowMfa.on();
- setMfaSuccessCallback(() => () => handleSelectOrganization(org, subOrgId));
+ mfaSuccessCallback.current = () => handleSelectOrganization(org, subOrgId);
return;
}
@@ -223,18 +223,16 @@ export const SelectOrgPage = () => {
JTWToken: token,
email: user?.email,
privateKey: ""
- } as IsCliLoginSuccessful["loginResponse"];
-
- const instance = axios.create();
- await instance.post(`http://127.0.0.1:${callbackPort}/`, payload).catch(() => {
- sessionStorage.setItem(
- SessionStorageKeys.CLI_TERMINAL_TOKEN,
- JSON.stringify({
- expiry: formatISO(addSeconds(new Date(), 30)),
- data: window.btoa(JSON.stringify(payload))
- })
- );
- });
+ };
+
+ sessionStorage.setItem(
+ SessionStorageKeys.CLI_TERMINAL_TOKEN,
+ JSON.stringify({
+ expiry: formatISO(addSeconds(new Date(), 30)),
+ data: window.btoa(JSON.stringify(payload)),
+ callbackPort
+ })
+ );
navigate({ to: "/cli-redirect" });
} else {
setAuthToken(token);
@@ -248,16 +246,14 @@ export const SelectOrgPage = () => {
// eslint-disable-next-line react-hooks/exhaustive-deps
useEffect(() => {
const defaultOrg = orgs?.find((o) => o.id === orgId);
- if (mfaPending && defaultOrg) {
- const storedMfaToken = sessionStorage.getItem(SessionStorageKeys.MFA_TEMP_TOKEN);
- if (storedMfaToken) {
- sessionStorage.removeItem(SessionStorageKeys.MFA_TEMP_TOKEN);
- SecurityClient.setMfaToken(storedMfaToken);
- toggleShowMfa.on();
- setMfaSuccessCallback(() => () => handleSelectOrganization(defaultOrg));
- }
+ const storedMfaToken = sessionStorage.getItem(SessionStorageKeys.MFA_TEMP_TOKEN);
+ if (mfaMethodFromSearch && storedMfaToken && defaultOrg) {
+ sessionStorage.removeItem(SessionStorageKeys.MFA_TEMP_TOKEN);
+ SecurityClient.setMfaToken(storedMfaToken);
+ toggleShowMfa.on();
+ mfaSuccessCallback.current = () => handleSelectOrganization(defaultOrg);
}
- }, [mfaPending, orgs?.length, orgId]);
+ }, [mfaMethodFromSearch, orgs?.length, orgId]);
const renderListContent = () => {
if (orgsLoading) {
@@ -390,8 +386,8 @@ export const SelectOrgPage = () => {
{shouldShowMfa ? (
<Mfa
email={user.email as string}
- successCallback={mfaSuccessCallback}
- method={requiredMfaMethod}
+ successCallback={mfaSuccessCallback.current}
+ method={requiredMfaMethod as MfaMethod}
/>
) : (
<div className="mx-auto mt-20 w-full max-w-md pb-28">
diff --git a/frontend/src/pages/auth/SelectOrgPage/route.tsx b/frontend/src/pages/auth/SelectOrgPage/route.tsx
index 0fe405fb90..617bc67449 100644
--- a/frontend/src/pages/auth/SelectOrgPage/route.tsx
+++ b/frontend/src/pages/auth/SelectOrgPage/route.tsx
@@ -1,13 +1,17 @@
import { createFileRoute, redirect, stripSearchParams } from "@tanstack/react-router";
import { zodValidator } from "@tanstack/zod-adapter";
+import { addSeconds, formatISO } from "date-fns";
import { z } from "zod";
+import { SessionStorageKeys } from "@app/const";
import { selectOrganization } from "@app/hooks/api/auth/queries";
+import { UserAgentType } from "@app/hooks/api/auth/types";
import {
fetchOrganizationsWithSubOrgs,
organizationKeys
} from "@app/hooks/api/organization/queries";
import { setAuthToken } from "@app/hooks/api/reactQuery";
+import { fetchUserDetails } from "@app/hooks/api/users/queries";
import { SelectOrgPage } from "./SelectOrgPage";
@@ -16,9 +20,7 @@ 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_pending: z.boolean().optional().catch(false),
- mfaToken: z.string().optional().catch(undefined),
- mfaMethod: z.string().optional().catch(undefined)
+ mfa_method: z.string().optional().catch(undefined)
});
export const Route = createFileRoute("/_restrict-login-signup/login/select-organization")({
@@ -30,15 +32,13 @@ export const Route = createFileRoute("/_restrict-login-signup/login/select-organ
org_id: "",
callback_port: undefined,
is_admin_login: false,
- mfa_pending: false,
- mfaToken: undefined,
- mfaMethod: undefined
+ mfa_method: undefined
})
]
},
beforeLoad: async ({ context, search }) => {
- // Skip auto-select for CLI flows, MFA pending, or force flag
- if (search.callback_port || search.mfa_pending || search.mfaToken || search.force) return;
+ // Skip auto-select for MFA pending or force flag
+ if (search.mfa_method || search.force) return;
try {
const orgsWithSubOrgs = await context.queryClient.ensureQueryData({
@@ -60,20 +60,43 @@ export const Route = createFileRoute("/_restrict-login-signup/login/select-organ
// If org_id is specified and doesn't match the only org, let the page handle it
if (search.org_id && search.org_id !== orgId) return;
- const result = await selectOrganization({ organizationId: orgId });
+ const result = await selectOrganization({
+ organizationId: orgId,
+ userAgent: search.callback_port ? UserAgentType.CLI : undefined
+ });
if (result.isMfaEnabled) {
// MFA required — redirect back to this page with MFA params so the component renders MFA immediately
+ sessionStorage.setItem(SessionStorageKeys.MFA_TEMP_TOKEN, result.token);
throw redirect({
to: "/login/select-organization",
search: {
- mfaToken: result.token,
- mfaMethod: result.mfaMethod,
- org_id: orgId
+ mfa_method: result.mfaMethod,
+ org_id: orgId,
+ callback_port: search.callback_port
}
});
}
+ if (search.callback_port) {
+ const user = await fetchUserDetails();
+ const payload = {
+ JTWToken: result.token,
+ email: user.email,
+ privateKey: ""
+ };
+
+ sessionStorage.setItem(
+ SessionStorageKeys.CLI_TERMINAL_TOKEN,
+ JSON.stringify({
+ expiry: formatISO(addSeconds(new Date(), 30)),
+ data: window.btoa(JSON.stringify(payload)),
+ callbackPort: search.callback_port
+ })
+ );
+ throw redirect({ to: "/cli-redirect" });
+ }
+
setAuthToken(result.token);
throw redirect({
to: "/organizations/$orgId/projects",
diff --git a/frontend/src/pages/middlewares/authenticate.tsx b/frontend/src/pages/middlewares/authenticate.tsx
index 92c8c98f38..114789c33d 100644
--- a/frontend/src/pages/middlewares/authenticate.tsx
+++ b/frontend/src/pages/middlewares/authenticate.tsx
@@ -15,6 +15,7 @@ export const Route = createFileRoute("/_authenticate")({
throw redirect({ to: "/admin/signup" });
}
+ console.log("trigger authenticate");
const data = await context.queryClient
.fetchQuery({
queryKey: authKeys.getAuthToken,
diff --git a/frontend/src/pages/middlewares/inject-org-details.tsx b/frontend/src/pages/middlewares/inject-org-details.tsx
index 6987181847..e84189d552 100644
--- a/frontend/src/pages/middlewares/inject-org-details.tsx
+++ b/frontend/src/pages/middlewares/inject-org-details.tsx
@@ -26,13 +26,15 @@ export const Route = createFileRoute("/_authenticate/_inject-org-details")({
if (urlOrgId !== currentTokenOrgId) {
try {
- const { token, isMfaEnabled } = await selectOrganization({ organizationId: urlOrgId });
+ const { token, isMfaEnabled, mfaMethod } = await selectOrganization({
+ organizationId: urlOrgId
+ });
if (isMfaEnabled) {
sessionStorage.setItem(SessionStorageKeys.MFA_TEMP_TOKEN, token);
throw redirect({
to: "/login/select-organization",
- search: { org_id: urlOrgId, mfa_pending: true }
+ search: { org_id: urlOrgId, mfa_method: mfaMethod }
});
}
diff --git a/frontend/src/pages/middlewares/restrict-login-signup.tsx b/frontend/src/pages/middlewares/restrict-login-signup.tsx
index 7f877ad01f..69fa9ff809 100644
--- a/frontend/src/pages/middlewares/restrict-login-signup.tsx
+++ b/frontend/src/pages/middlewares/restrict-login-signup.tsx
@@ -94,34 +94,30 @@ export const Route = createFileRoute("/_restrict-login-signup")({
if (location.pathname === "/signupinvite") return;
- // Avoid redirect if on select-organization page with force=true
- if (location.pathname.endsWith("select-organization") && search?.force === true) return;
+ const isOnSelectOrg = location.pathname.endsWith("select-organization");
+ const needsOrgSelection =
+ search?.callback_port || search?.force || search?.org_id || !data.organizationId;
- // to do cli login
- if (search?.callback_port) {
- if (location.pathname.endsWith("select-organization") || location.pathname.endsWith("login"))
+ if (needsOrgSelection) {
+ if (isOnSelectOrg || (!data.organizationId && location.pathname.endsWith("verify-email")))
return;
- }
-
- if (search.org_id) {
- if (location.pathname.endsWith("select-organization")) return;
- throw redirect({ to: "/login/select-organization", search: { org_id: search.org_id } });
+ throw redirect({
+ to: "/login/select-organization",
+ search: {
+ org_id: search?.org_id || data.organizationId,
+ callback_port: search?.callback_port
+ }
+ });
}
- if (!data.organizationId) {
- if (
- location.pathname.endsWith("select-organization") ||
- location.pathname.endsWith("verify-email")
- )
- return;
- throw redirect({ to: "/login/select-organization" });
- }
const orgId = data.subOrganizationId || data.organizationId;
- throw redirect({
- to: "/organizations/$orgId/projects",
- params: { orgId }
- });
+ if (orgId) {
+ throw redirect({
+ to: "/organizations/$orgId/projects",
+ params: { orgId }
+ });
+ }
},
component: AuthConsentWrapper
});
diff --git a/frontend/src/pages/organization/SettingsPage/components/OrgSsoTab/OrgEmailDomainsSection/OrgEmailDomainsSection.tsx b/frontend/src/pages/organization/SettingsPage/components/OrgSsoTab/OrgEmailDomainsSection/OrgEmailDomainsSection.tsx
index 66d35af223..5969aed349 100644
--- a/frontend/src/pages/organization/SettingsPage/components/OrgSsoTab/OrgEmailDomainsSection/OrgEmailDomainsSection.tsx
+++ b/frontend/src/pages/organization/SettingsPage/components/OrgSsoTab/OrgEmailDomainsSection/OrgEmailDomainsSection.tsx
@@ -3,6 +3,7 @@ import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import { OrgPermissionCan, PermissionDeniedBanner } from "@app/components/permissions";
import { Button } from "@app/components/v2";
+import { DocumentationLinkBadge } from "@app/components/v3";
import {
OrgPermissionEmailDomainActions,
OrgPermissionSubjects,
@@ -28,9 +29,15 @@ export const OrgEmailDomainsSection = () => {
<div className="mb-4 space-y-6 rounded-lg border border-mineshaft-600 bg-mineshaft-900 p-6">
<div className="mb-4 flex items-center justify-between">
<div>
- <p className="text-xl font-medium text-gray-200">Email Domains</p>
+ <div className="text-xl font-medium text-gray-200">
+ Email Domains
+ <DocumentationLinkBadge
+ className="ml-2"
+ href="https://infisical.com/docs/documentation/platform/email-domain"
+ />
+ </div>
<p className="mt-1 mb-2 text-gray-400">
- Verify ownership of your email domains to use with SSO and identity providers.
+ Verify ownership of your email domains to use with SSO and identity providers. For mo
</p>
</div>
{hasEmailDomainVerification && (