Skip to content

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

fix veria comment

Thiago Araujo da Silva5e6718b0b65c
diff --git a/backend/src/ee/services/secret-rotation-v2/fireworks-api-key/fireworks-api-key-rotation-fns.ts b/backend/src/ee/services/secret-rotation-v2/fireworks-api-key/fireworks-api-key-rotation-fns.ts
index 97f49e1500..d0ee0167a9 100644
--- a/backend/src/ee/services/secret-rotation-v2/fireworks-api-key/fireworks-api-key-rotation-fns.ts
+++ b/backend/src/ee/services/secret-rotation-v2/fireworks-api-key/fireworks-api-key-rotation-fns.ts
@@ -123,7 +123,7 @@ export const fireworksApiKeyRotationFactory: TRotationFactory<
generatedCredentials.map((credential) => $deleteApiKey(apiKey, accountId, serviceAccountUserId, credential.keyId))
);
- results.forEach((result, index) => {
+ results.forEach((result) => {
if (result.status === "rejected") {
logger.error(
result.reason,
diff --git a/backend/src/server/routes/mfa-step-up-fns.ts b/backend/src/server/routes/mfa-step-up-fns.ts
index 19a5602177..4d06a1542d 100644
--- a/backend/src/server/routes/mfa-step-up-fns.ts
+++ b/backend/src/server/routes/mfa-step-up-fns.ts
@@ -26,7 +26,7 @@ export type TMfaStepUpResource = (typeof MfaStepUpResource)[keyof typeof MfaStep
*
* - With a valid, verified session for this user + resource: returns immediately.
* - Otherwise (no session id, or one that is missing/expired/unverified/foreign):
- * mints a fresh pending session (emailing the code when the user's method is
+ * mints a fresh pending session (emailing the code when the required method is
* email) and throws `SESSION_MFA_REQUIRED` carrying the new session id + method
* so the client can drive the challenge and retry.
*/
@@ -34,11 +34,13 @@ export const ensureStepUpMfa = async (
server: FastifyZodProvider,
{
userId,
+ orgId,
resourceId,
mfaSessionId,
message
}: {
userId: string;
+ orgId: string;
resourceId: TMfaStepUpResource;
mfaSessionId?: string;
message: string;
@@ -56,7 +58,8 @@ export const ensureStepUpMfa = async (
}
const user = await server.services.user.getMe(userId);
- const mfaMethod = (user.selectedMfaMethod as MfaMethod | null) ?? MfaMethod.EMAIL;
+
+ const mfaMethod = await server.services.user.getStepUpMfaMethod(userId, orgId);
const newMfaSessionId = await server.services.mfaSession.createMfaSession(userId, resourceId, mfaMethod);
diff --git a/backend/src/server/routes/v1/user-router.ts b/backend/src/server/routes/v1/user-router.ts
index 6f5f003bf4..6260494e28 100644
--- a/backend/src/server/routes/v1/user-router.ts
+++ b/backend/src/server/routes/v1/user-router.ts
@@ -310,6 +310,7 @@ export const registerUserRouter = async (server: FastifyZodProvider) => {
handler: async (req) => {
await ensureStepUpMfa(server, {
userId: req.permission.id,
+ orgId: req.permission.orgId,
resourceId: MfaStepUpResource.MfaManagement,
mfaSessionId: req.query.mfaSessionId,
message: "MFA verification is required to access recovery codes"
@@ -344,6 +345,7 @@ export const registerUserRouter = async (server: FastifyZodProvider) => {
handler: async (req) => {
await ensureStepUpMfa(server, {
userId: req.permission.id,
+ orgId: req.permission.orgId,
resourceId: MfaStepUpResource.MfaManagement,
mfaSessionId: req.body?.mfaSessionId,
message: "MFA verification is required to access recovery codes"
diff --git a/backend/src/server/routes/v2/user-router.ts b/backend/src/server/routes/v2/user-router.ts
index 007840d8a2..4a5e48913a 100644
--- a/backend/src/server/routes/v2/user-router.ts
+++ b/backend/src/server/routes/v2/user-router.ts
@@ -139,6 +139,12 @@ export const registerUserRouter = async (server: FastifyZodProvider) => {
// selectOrganization), so reaching this handler already proves the org-required
// method. The transient post-password no-org token used during login/onboarding
// is rejected here and cannot obtain recovery codes.
+ //
+ // This is enable-only: the org-scoped token proves the org method was completed at
+ // login but NOT a fresh step-up challenge, so re-running it on an already-enabled
+ // account would mint fresh recovery codes without the step-up gate the recovery-code
+ // endpoints enforce. The service rejects already-enabled accounts; rotating codes on
+ // an enabled account goes through the step-up-gated POST /me/mfa/recovery-codes route.
server.route({
method: "POST",
url: "/me/mfa/activate",
@@ -194,6 +200,7 @@ export const registerUserRouter = async (server: FastifyZodProvider) => {
handler: async (req) => {
await ensureStepUpMfa(server, {
userId: req.permission.id,
+ orgId: req.permission.orgId,
resourceId: MfaStepUpResource.MfaManagement,
mfaSessionId: req.body?.mfaSessionId,
message: "MFA verification is required to disable two-factor authentication"
diff --git a/backend/src/services/user/user-service.ts b/backend/src/services/user/user-service.ts
index 5fc74b33f9..3ce2117092 100644
--- a/backend/src/services/user/user-service.ts
+++ b/backend/src/services/user/user-service.ts
@@ -14,6 +14,7 @@ import { TokenType } from "@app/services/auth-token/auth-token-types";
import { TOrgDALFactory } from "@app/services/org/org-dal";
import { SmtpTemplates, TSmtpService } from "@app/services/smtp/smtp-service";
+import { getRequiredMfaMethod } from "../auth/auth-fns";
import { ActorType, AuthMethod, AuthModeSignUpTokenPayload, AuthTokenType, MfaMethod } from "../auth/auth-type";
import { TGroupProjectDALFactory } from "../group-project/group-project-dal";
import { TMembershipUserDALFactory } from "../membership-user/membership-user-dal";
@@ -137,7 +138,7 @@ export const userServiceFactory = ({
// first-time setup; other methods must already be configured (asserted below).
const activateMfa = async ({ userId, selectedMfaMethod }: TActivateUserMfaDTO) => {
const user = await userDAL.findById(userId);
- if (!user || !user.email) throw new BadRequestError({ name: "Failed to enable MFA" });
+ if (!user || !user.email || user.isMfaEnabled) throw new BadRequestError({ name: "Failed to enable MFA" });
const method = selectedMfaMethod ?? (user.selectedMfaMethod as MfaMethod | null) ?? MfaMethod.EMAIL;
await assertMfaMethodConfigured(userId, method);
@@ -479,6 +480,19 @@ export const userServiceFactory = ({
};
};
+ // Resolves the MFA method a step-up challenge must use, from the current org
+ // context. Recovery codes bypass the org-required method at login, so the step-up
+ // that gates them must challenge that same method rather than the user's personal
+ // preference (which could be weaker, e.g. email while the org enforces passkeys).
+ // Mirrors login via the shared getRequiredMfaMethod: an org enforcing MFA dictates
+ // the method, otherwise the user's own preference applies. Reaching a step-up-gated
+ // route already proves membership of this org, so no permission check is needed.
+ const getStepUpMfaMethod = async (userId: string, orgId: string): Promise<MfaMethod> => {
+ const [user, org] = await Promise.all([userDAL.findById(userId), orgDAL.findById(orgId)]);
+ const { requiredMfaMethod } = getRequiredMfaMethod(org ?? {}, user ?? {});
+ return requiredMfaMethod;
+ };
+
const deleteUser = async (userId: string) => {
// If the deleting user is the only remaining server admin, block self-deletion.
// The super_admin table's `initialized` flag is not reset on user delete, so
@@ -642,6 +656,7 @@ export const userServiceFactory = ({
updateUserEmail,
deleteUser,
getMe,
+ getStepUpMfaMethod,
createUserAction,
listUserGroups,
getUserAction,