Skip to content

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

only remove webauthn if there is no other left

Thiago Araujo da Silvacdf012fde97e
diff --git a/backend/src/server/routes/v1/user-router.ts b/backend/src/server/routes/v1/user-router.ts
index 183de52088..81ec8f2aa6 100644
--- a/backend/src/server/routes/v1/user-router.ts
+++ b/backend/src/server/routes/v1/user-router.ts
@@ -586,6 +586,13 @@ export const registerUserRouter = async (server: FastifyZodProvider) => {
},
onRequest: verifyAuth([AuthMode.JWT]),
handler: async (req) => {
+ // Other passkeys can still answer the challenge, so only removing the last one
+ // needs to fall back to a different factor.
+ const { credentials } = await server.services.webAuthn.getUserWebAuthnCredentials({
+ userId: req.permission.id
+ });
+ const isRemovingLastPasskey = credentials.every((credential) => credential.id === req.params.id);
+
await ensureStepUpMfa(server, {
userId: req.permission.id,
orgId: req.permission.orgId,
@@ -593,7 +600,7 @@ export const registerUserRouter = async (server: FastifyZodProvider) => {
resourceId: MfaStepUpResource.MfaManagement,
mfaSessionId: req.query.mfaSessionId,
message: "MFA verification is required to remove a passkey",
- excludeMfaMethod: MfaMethod.WEBAUTHN
+ excludeMfaMethod: isRemovingLastPasskey ? MfaMethod.WEBAUTHN : undefined
});
await server.services.webAuthn.deleteWebAuthnCredential({
userId: req.permission.id,