Skip to content

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

improvement: prevent empty/invalid values when disable lockout

Scott Wilsona134ed995a64
diff --git a/frontend/src/pages/organization/AccessManagementPage/components/OrgIdentityTab/components/IdentitySection/IdentityLdapAuthForm.tsx b/frontend/src/pages/organization/AccessManagementPage/components/OrgIdentityTab/components/IdentitySection/IdentityLdapAuthForm.tsx
index b545192e29..8f80a96b31 100644
--- a/frontend/src/pages/organization/AccessManagementPage/components/OrgIdentityTab/components/IdentitySection/IdentityLdapAuthForm.tsx
+++ b/frontend/src/pages/organization/AccessManagementPage/components/OrgIdentityTab/components/IdentitySection/IdentityLdapAuthForm.tsx
@@ -52,6 +52,7 @@ import {
import { useGetAvailableTemplates } from "@app/hooks/api/identityAuthTemplates/queries";
import { UsePopUpState } from "@app/hooks/usePopUp";
+import { LOCKOUT_DEFAULT_VALUES } from "./lockout/constants";
import { LockoutTab } from "./lockout/LockoutTab";
import { superRefineLockout } from "./lockout/super-refine";
import { AccessTokenNumUsesLimitField } from "./shared/AccessTokenNumUsesLimitField";
@@ -209,6 +210,7 @@ export const IdentityLdapAuthForm = ({
reset,
watch,
setValue,
+ trigger,
formState: { isSubmitting }
} = useForm<FormData>({
resolver,
@@ -224,12 +226,7 @@ export const IdentityLdapAuthForm = ({
accessTokenMaxTTL: "2592000",
accessTokenNumUsesLimit: "",
accessTokenTrustedIps: DEFAULT_TRUSTED_IPS,
- lockoutEnabled: true,
- lockoutThreshold: "3",
- lockoutDurationValue: "5",
- lockoutDurationUnit: "m",
- lockoutCounterResetValue: "30",
- lockoutCounterResetUnit: "s"
+ ...LOCKOUT_DEFAULT_VALUES
}
});
@@ -305,12 +302,7 @@ export const IdentityLdapAuthForm = ({
accessTokenMaxTTL: "2592000",
accessTokenNumUsesLimit: "",
accessTokenTrustedIps: DEFAULT_TRUSTED_IPS,
- lockoutEnabled: true,
- lockoutThreshold: "3",
- lockoutDurationValue: "5",
- lockoutDurationUnit: "m",
- lockoutCounterResetValue: "30",
- lockoutCounterResetUnit: "s"
+ ...LOCKOUT_DEFAULT_VALUES
});
}, [data, reset]);
@@ -767,6 +759,7 @@ export const IdentityLdapAuthForm = ({
</TabsContent>
<LockoutTab
control={control}
+ trigger={trigger}
lockoutEnabled={lockoutEnabledWatch}
lockoutThreshold={lockoutThresholdWatch}
lockoutDurationValue={lockoutDurationValueWatch}
diff --git a/frontend/src/pages/organization/AccessManagementPage/components/OrgIdentityTab/components/IdentitySection/IdentityUniversalAuthForm.tsx b/frontend/src/pages/organization/AccessManagementPage/components/OrgIdentityTab/components/IdentitySection/IdentityUniversalAuthForm.tsx
index 865f0af038..5e3dc0a62a 100644
--- a/frontend/src/pages/organization/AccessManagementPage/components/OrgIdentityTab/components/IdentitySection/IdentityUniversalAuthForm.tsx
+++ b/frontend/src/pages/organization/AccessManagementPage/components/OrgIdentityTab/components/IdentitySection/IdentityUniversalAuthForm.tsx
@@ -35,6 +35,7 @@ import {
} from "@app/hooks/api";
import { UsePopUpState } from "@app/hooks/usePopUp";
+import { LOCKOUT_DEFAULT_VALUES } from "./lockout/constants";
import { LockoutTab } from "./lockout/LockoutTab";
import { superRefineLockout } from "./lockout/super-refine";
import { AccessTokenNumUsesLimitField } from "./shared/AccessTokenNumUsesLimitField";
@@ -118,7 +119,8 @@ export const IdentityUniversalAuthForm = ({
handleSubmit,
reset,
formState: { isSubmitting },
- watch
+ watch,
+ trigger
} = useForm<FormData>({
resolver,
defaultValues: {
@@ -128,12 +130,7 @@ export const IdentityUniversalAuthForm = ({
clientSecretTrustedIps: DEFAULT_TRUSTED_IPS,
accessTokenTrustedIps: DEFAULT_TRUSTED_IPS,
accessTokenPeriod: "0",
- lockoutEnabled: true,
- lockoutThreshold: "3",
- lockoutDurationValue: "5",
- lockoutDurationUnit: "m",
- lockoutCounterResetValue: "30",
- lockoutCounterResetUnit: "s"
+ ...LOCKOUT_DEFAULT_VALUES
}
});
@@ -175,12 +172,7 @@ export const IdentityUniversalAuthForm = ({
accessTokenPeriod: "0",
clientSecretTrustedIps: DEFAULT_TRUSTED_IPS,
accessTokenTrustedIps: DEFAULT_TRUSTED_IPS,
- lockoutEnabled: true,
- lockoutThreshold: "3",
- lockoutDurationValue: "5",
- lockoutDurationUnit: "m",
- lockoutCounterResetValue: "30",
- lockoutCounterResetUnit: "s"
+ ...LOCKOUT_DEFAULT_VALUES
});
}
}, [data]);
@@ -322,6 +314,7 @@ export const IdentityUniversalAuthForm = ({
</TabsContent>
<LockoutTab
control={control}
+ trigger={trigger}
lockoutEnabled={lockoutEnabledWatch}
lockoutThreshold={lockoutThresholdWatch}
lockoutDurationValue={lockoutDurationValueWatch}
diff --git a/frontend/src/pages/organization/AccessManagementPage/components/OrgIdentityTab/components/IdentitySection/lockout/LockoutTab.tsx b/frontend/src/pages/organization/AccessManagementPage/components/OrgIdentityTab/components/IdentitySection/lockout/LockoutTab.tsx
index 5e836e339b..14f3d4d105 100644
--- a/frontend/src/pages/organization/AccessManagementPage/components/OrgIdentityTab/components/IdentitySection/lockout/LockoutTab.tsx
+++ b/frontend/src/pages/organization/AccessManagementPage/components/OrgIdentityTab/components/IdentitySection/lockout/LockoutTab.tsx
@@ -1,4 +1,5 @@
-import { Control, Controller } from "react-hook-form";
+import { type FocusEvent } from "react";
+import { Control, Controller, UseFormTrigger } from "react-hook-form";
import { InfoIcon } from "lucide-react";
import {
@@ -24,9 +25,22 @@ import {
import { useScopeVariant } from "@app/hooks";
import { IdentityFormTab } from "../types";
+import { LOCKOUT_DEFAULT_VALUES } from "./constants";
+
+// Numeric lockout fields must never be left empty, otherwise the description label renders
+// values like "m" instead of "5m". On blur, an empty field reverts to its default.
+const handleRevertOnBlur =
+ (field: { onChange: (value: string) => void; onBlur: () => void }, fallback: string) =>
+ (e: FocusEvent<HTMLInputElement>) => {
+ field.onBlur();
+ if (e.target.value.trim() === "") {
+ field.onChange(fallback);
+ }
+ };
export const LockoutTab = ({
control,
+ trigger,
lockoutEnabled,
lockoutThreshold,
lockoutDurationValue,
@@ -35,6 +49,7 @@ export const LockoutTab = ({
lockoutCounterResetUnit
}: {
control: Control<any>;
+ trigger: UseFormTrigger<any>;
lockoutEnabled: boolean;
lockoutThreshold: string;
lockoutDurationValue: string;
@@ -44,6 +59,13 @@ export const LockoutTab = ({
}) => {
const scopeVariant = useScopeVariant();
+ // Fall back to defaults so the description never collapses to "m"/"s"
+ // while a value field is momentarily empty during editing.
+ const thresholdLabel = lockoutThreshold || LOCKOUT_DEFAULT_VALUES.lockoutThreshold;
+ const durationLabel = lockoutDurationValue || LOCKOUT_DEFAULT_VALUES.lockoutDurationValue;
+ const counterResetLabel =
+ lockoutCounterResetValue || LOCKOUT_DEFAULT_VALUES.lockoutCounterResetValue;
+
return (
<TabsContent value={IdentityFormTab.Lockout}>
<FieldGroup>
@@ -56,7 +78,7 @@ export const LockoutTab = ({
<FieldContent>
<FieldTitle>Lockout</FieldTitle>
<FieldDescription>
- {`The lockout feature will prevent login attempts for ${lockoutDurationValue}${lockoutDurationUnit} after ${lockoutThreshold} consecutive login failures. If ${lockoutCounterResetValue}${lockoutCounterResetUnit} pass after the most recent failure, the lockout counter resets.`}
+ {`The lockout feature will prevent login attempts for ${durationLabel}${lockoutDurationUnit} after ${thresholdLabel} consecutive login failures. If ${counterResetLabel}${lockoutCounterResetUnit} pass after the most recent failure, the lockout counter resets.`}
</FieldDescription>
<FieldError>{error?.message}</FieldError>
</FieldContent>
@@ -64,7 +86,19 @@ export const LockoutTab = ({
id="lockout-enabled"
variant={scopeVariant}
checked={value}
- onCheckedChange={onChange}
+ onCheckedChange={async (checked) => {
+ // Lockout values are always submitted, so block disabling while any are
+ // invalid; otherwise invalid values would silently reach the backend.
+ if (!checked) {
+ const isValid = await trigger([
+ "lockoutThreshold",
+ "lockoutDurationValue",
+ "lockoutCounterResetValue"
+ ]);
+ if (!isValid) return;
+ }
+ onChange(checked);
+ }}
/>
</Field>
);
@@ -94,6 +128,7 @@ export const LockoutTab = ({
placeholder="Threshold..."
disabled={!lockoutEnabled}
isError={Boolean(error)}
+ onBlur={handleRevertOnBlur(field, LOCKOUT_DEFAULT_VALUES.lockoutThreshold)}
/>
<FieldError>{error?.message}</FieldError>
</Field>
@@ -128,6 +163,7 @@ export const LockoutTab = ({
placeholder="Duration..."
disabled={!lockoutEnabled}
isError={Boolean(error)}
+ onBlur={handleRevertOnBlur(field, LOCKOUT_DEFAULT_VALUES.lockoutDurationValue)}
/>
<FieldError>{error?.message}</FieldError>
</Field>
@@ -191,6 +227,10 @@ export const LockoutTab = ({
type="number"
disabled={!lockoutEnabled}
isError={Boolean(error)}
+ onBlur={handleRevertOnBlur(
+ field,
+ LOCKOUT_DEFAULT_VALUES.lockoutCounterResetValue
+ )}
/>
<FieldError>{error?.message}</FieldError>
</Field>
diff --git a/frontend/src/pages/organization/AccessManagementPage/components/OrgIdentityTab/components/IdentitySection/lockout/constants.ts b/frontend/src/pages/organization/AccessManagementPage/components/OrgIdentityTab/components/IdentitySection/lockout/constants.ts
new file mode 100644
index 0000000000..e362e8cc99
--- /dev/null
+++ b/frontend/src/pages/organization/AccessManagementPage/components/OrgIdentityTab/components/IdentitySection/lockout/constants.ts
@@ -0,0 +1,8 @@
+export const LOCKOUT_DEFAULT_VALUES = {
+ lockoutEnabled: true,
+ lockoutThreshold: "3",
+ lockoutDurationValue: "5",
+ lockoutDurationUnit: "m",
+ lockoutCounterResetValue: "30",
+ lockoutCounterResetUnit: "s"
+} as const;