strapi-plugin-magic-sessionmanager 4.16.1 → 4.17.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (31) hide show
  1. package/CHANGELOG.md +41 -0
  2. package/README.md +49 -15
  3. package/dist/admin/{Analytics-FcRt0X62.mjs → Analytics-B-p2Q7th.mjs} +1 -1
  4. package/dist/admin/{Analytics-CMR62DiD.js → Analytics-BTIByTUY.js} +1 -1
  5. package/dist/admin/{App-CmytGbze.js → App-CH6635JB.js} +33 -170
  6. package/dist/admin/{App-DBieSWB0.mjs → App-DmesuM2g.mjs} +3 -140
  7. package/dist/admin/{OnlineUsersWidget-zP9Hl_it.mjs → OnlineUsersWidget-CuqeQ0tb.mjs} +1 -1
  8. package/dist/admin/{OnlineUsersWidget-Lzx9XB74.js → OnlineUsersWidget-TlOp8nie.js} +1 -1
  9. package/dist/admin/{Settings-CZOPusQK.mjs → Settings-C4IgGBjQ.mjs} +1163 -56
  10. package/dist/admin/{Settings-1v--SXC0.js → Settings-DtP_H4JS.js} +1167 -60
  11. package/dist/admin/dashboardModel-0ROcWcB1.mjs +189 -0
  12. package/dist/admin/dashboardModel-BSJhZdXI.js +188 -0
  13. package/dist/admin/{de-D3TSA066.mjs → de-BoahnYIP.mjs} +110 -9
  14. package/dist/admin/{de-y_9mdVT7.js → de-C_ooq6EF.js} +110 -9
  15. package/dist/admin/{en-CIQB8nfI.js → en-CuUVE2K0.js} +110 -9
  16. package/dist/admin/{en-B60I97bK.mjs → en-DHme92L-.mjs} +110 -9
  17. package/dist/admin/{es-CJEL_iGC.mjs → es-CjcTgS9Z.mjs} +110 -9
  18. package/dist/admin/{es-DHhHzlRY.js → es-lbDNXcQi.js} +110 -9
  19. package/dist/admin/{fr-BfBK_iuV.mjs → fr-BPwnrSaC.mjs} +110 -9
  20. package/dist/admin/{fr-D86FTt1w.js → fr-RtypjgGp.js} +110 -9
  21. package/dist/admin/{index-tt61o2VH.mjs → index-B102RF2H.mjs} +40 -38
  22. package/dist/admin/{index-CSJJn4qy.js → index-w0OuPYFm.js} +12 -10
  23. package/dist/admin/index.js +1 -1
  24. package/dist/admin/index.mjs +1 -1
  25. package/dist/admin/{pt-BE-FT-L8.js → pt-BMCAKRQ4.js} +110 -9
  26. package/dist/admin/{pt-C3PSvC7z.mjs → pt-D5FHSP2y.mjs} +110 -9
  27. package/dist/server/index.js +1519 -78
  28. package/dist/server/index.mjs +1519 -78
  29. package/package.json +1 -1
  30. package/dist/admin/riskData-BVs9GpgD.js +0 -26
  31. package/dist/admin/riskData-CI1gm2yI.mjs +0 -27
@@ -1,13 +1,14 @@
1
1
  import { jsx, jsxs, Fragment as Fragment$1 } from "react/jsx-runtime";
2
2
  import { useState, useCallback, createContext, useContext, useMemo, useId, Fragment, useRef, useEffect, useLayoutEffect } from "react";
3
- import { Field, Typography, Switch, Box, TextInput, Flex, Button, Link, SingleSelect, SingleSelectOption, Accordion, Alert, Badge, Radio, Dialog, Tag, Combobox, ComboboxOption, NumberInput, Divider, Tabs, Textarea, Checkbox } from "@strapi/design-system";
4
- import { ConfirmDialog, useNotification, useFetchClient, useQueryParams, useRBAC, Page, Form, Blocker, useForm } from "@strapi/strapi/admin";
5
- import { EyeStriked, Eye, Key, Duplicate, Cross, Plus, Trash, Download, Check } from "@strapi/icons";
3
+ import { Field, Typography, Switch, Box, TextInput, Flex, Button, Link, SingleSelect, SingleSelectOption, Accordion, Table, Thead, Tr, Th, VisuallyHidden, Tbody, Td, Modal, NumberInput, IconButton, Alert, Badge, Radio, Loader, EmptyStateLayout, Textarea, Dialog, Tag, Combobox, ComboboxOption, Divider, Tabs, Checkbox } from "@strapi/design-system";
4
+ import { useFetchClient, useNotification, useRBAC, ConfirmDialog, useQueryParams, Page, Form, Blocker, useForm } from "@strapi/strapi/admin";
5
+ import { EyeStriked, Eye, Key, Duplicate, Plus, Pencil, Trash, Lock, ArrowClockwise, Cross, Download, Check } from "@strapi/icons";
6
6
  import styled from "styled-components";
7
- import { F as ReadableParagraphs, b as getTranslation, m as logSafeAdminError, R as ReadableText, G as EqualGrid, n as PersistentAlert, P as PropertyList, H as formatSessionDate, C as ConfirmAction, I as refocusIfLost, l as pluginId, s as isCancelledRequest, J as requireSuccessfulMutation, o as pluginPermissions, w as PageShell } from "./index-tt61o2VH.mjs";
7
+ import { y as ReadableParagraphs, b as getTranslation, l as logSafeAdminError, R as ReadableText, f as pluginId, n as isCancelledRequest, h as PersistentAlert, z as EqualGrid, u as useSessionFormatters, j as pluginPermissions, C as ConfirmAction, P as PropertyList, A as formatSessionDate, B as refocusIfLost, F as requireSuccessfulMutation, q as PageShell } from "./index-B102RF2H.mjs";
8
8
  import { useIntl } from "react-intl";
9
9
  import { S as SectionCard } from "./SectionCard-D51bv4Hi.mjs";
10
- import { g as getRiskAvailability, r as riskDependentControl } from "./riskData-CI1gm2yI.mjs";
10
+ import { u as useElementWidth, b as RowActions, s as shouldIsolateActionKey, o as getRiskAvailability, q as riskDependentControl } from "./dashboardModel-0ROcWcB1.mjs";
11
+ import { EmptyPermissions } from "@strapi/icons/symbols";
11
12
  const SETTINGS_TAB_IDS = Object.freeze([
12
13
  "sessions",
13
14
  "login-protection",
@@ -34,10 +35,20 @@ const SETTINGS_TAB_FIELDS = Object.freeze({
34
35
  "cleanupInterval",
35
36
  "cleanupUseDbDirect",
36
37
  "strictSessionEnforcement",
37
- "sessionCreationGraceMs"
38
+ "sessionCreationGraceMs",
39
+ "maxSessionsPerUser",
40
+ "sessionLimitPolicy",
41
+ "endOtherSessionsOnPasswordChange",
42
+ "roleRules"
38
43
  ],
39
44
  "login-protection": [
40
45
  "maxFailedLogins",
46
+ "maxFailedLoginsPerAccount",
47
+ "lockoutWindowMinutes",
48
+ "lockoutDurationMinutes",
49
+ "lockoutTrustedAddresses",
50
+ "lockoutNotifyUser",
51
+ "recordUserSignInEvents",
41
52
  "trustedProxies",
42
53
  "blockSuspiciousSessions",
43
54
  "geoLookupFailureMode",
@@ -87,7 +98,26 @@ const SETTINGS_FIELD_LABELS = Object.freeze({
87
98
  cleanupUseDbDirect: ["settings.config.sessions.idleMethod.label", "Idle check method"],
88
99
  strictSessionEnforcement: ["settings.config.token.check.label", "Strict token check"],
89
100
  sessionCreationGraceMs: ["settings.config.token.grace.label", "Grace period after sign-in"],
90
- maxFailedLogins: ["settings.config.failed.lockout.label", "Temporary IP lockout after"],
101
+ maxFailedLogins: ["settings.config.failed.lockout.label", "Lock an IP address after"],
102
+ maxFailedLoginsPerAccount: ["settings.config.failed.account.label", "Lock an account after"],
103
+ lockoutWindowMinutes: ["settings.config.failed.window.label", "Count failed sign-ins within"],
104
+ lockoutDurationMinutes: ["settings.config.failed.duration.label", "Lock for"],
105
+ lockoutTrustedAddresses: ["settings.config.failed.trusted.label", "Trusted addresses"],
106
+ lockoutNotifyUser: [
107
+ "settings.config.failed.notify.label",
108
+ "Email the user when their account is locked"
109
+ ],
110
+ recordUserSignInEvents: [
111
+ "settings.config.failed.record.label",
112
+ "Record failed and refused sign-ins"
113
+ ],
114
+ maxSessionsPerUser: ["settings.config.sessionLimit.max.label", "Open sessions per user"],
115
+ sessionLimitPolicy: ["settings.config.sessionLimit.policy.label", "When the limit is reached"],
116
+ endOtherSessionsOnPasswordChange: [
117
+ "settings.config.passwordChange.label",
118
+ "End other sessions after a password change"
119
+ ],
120
+ roleRules: ["settings.roleRules.title", "Different rules for some roles"],
91
121
  trustedProxies: ["settings.config.clientIp.trustProxy.label", "Trust proxy headers"],
92
122
  blockSuspiciousSessions: [
93
123
  "settings.config.suspicious.reject.label",
@@ -733,6 +763,441 @@ const TermList = ({ items, label, code = false }) => /* @__PURE__ */ jsx(Terms,
733
763
  ) }),
734
764
  /* @__PURE__ */ jsx("dd", { children: /* @__PURE__ */ jsx(Typography, { variant: "omega", textColor: "neutral700", children: item.description }) })
735
765
  ] }, item.id)) });
766
+ const POLICY_FORM_DEFAULTS = Object.freeze({
767
+ maxFailedLoginsPerAccount: 0,
768
+ lockoutWindowMinutes: 15,
769
+ lockoutDurationMinutes: 15,
770
+ lockoutTrustedAddresses: Object.freeze([]),
771
+ lockoutNotifyUser: false,
772
+ recordUserSignInEvents: true,
773
+ maxSessionsPerUser: 0,
774
+ sessionLimitPolicy: "end-oldest",
775
+ endOtherSessionsOnPasswordChange: true,
776
+ roleRules: Object.freeze([])
777
+ });
778
+ const POLICY_RANGES = Object.freeze({
779
+ maxFailedLoginsPerAccount: Object.freeze({ min: 0, max: 100 }),
780
+ lockoutWindowMinutes: Object.freeze({ min: 1, max: 1440 }),
781
+ lockoutDurationMinutes: Object.freeze({ min: 1, max: 10080 }),
782
+ maxSessionsPerUser: Object.freeze({ min: 0, max: 100 })
783
+ });
784
+ const ROLE_RULE_RANGES = Object.freeze({
785
+ maxSessionsPerUser: Object.freeze({ min: 0, max: 100 }),
786
+ inactivityTimeout: Object.freeze({ min: 1, max: 1440 }),
787
+ maxFailedLoginsPerAccount: Object.freeze({ min: 0, max: 100 })
788
+ });
789
+ const ROLE_RULE_FIELDS = Object.freeze(Object.keys(ROLE_RULE_RANGES));
790
+ const MAX_TRUSTED_ADDRESSES = 100;
791
+ const message$1 = (messageId, defaultMessage, values) => ({ messageId, defaultMessage, values });
792
+ function validateWholeNumber(value, { min, max }) {
793
+ if (value === void 0 || value === null || value === "") {
794
+ return message$1("settings.validation.required", "Enter a value.");
795
+ }
796
+ const number = Number(value);
797
+ if (!Number.isInteger(number) || number < min || number > max) {
798
+ return message$1("settings.validation.range", "Enter a whole number from {min} to {max}.", {
799
+ min,
800
+ max
801
+ });
802
+ }
803
+ return null;
804
+ }
805
+ const IPV4 = /^(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}$/;
806
+ const IPV6_CHARS = /^[0-9a-f:.]{2,45}$/i;
807
+ function isTrustedAddressLine(line) {
808
+ const value = String(line || "").trim();
809
+ if (!value || value.length > 64) return false;
810
+ const [address, prefix, extra] = value.split("/");
811
+ if (extra !== void 0) return false;
812
+ const v4 = IPV4.test(address);
813
+ const v6 = !v4 && address.includes(":") && IPV6_CHARS.test(address) && !address.includes(":::");
814
+ if (!v4 && !v6) return false;
815
+ if (prefix === void 0) return true;
816
+ if (!/^\d{1,3}$/.test(prefix)) return false;
817
+ return Number(prefix) <= (v4 ? 32 : 128);
818
+ }
819
+ function parseTrustedAddressText(text) {
820
+ return String(text || "").split(/[\n,]/).map((line) => line.trim()).filter(Boolean);
821
+ }
822
+ function formatTrustedAddressText(list) {
823
+ return Array.isArray(list) ? list.join("\n") : "";
824
+ }
825
+ function validatePolicyFields(settings) {
826
+ const source = settings || {};
827
+ const errors = {};
828
+ for (const [key, range] of Object.entries(POLICY_RANGES)) {
829
+ if (!Object.prototype.hasOwnProperty.call(source, key)) continue;
830
+ const error = validateWholeNumber(source[key], range);
831
+ if (error) errors[key] = error;
832
+ }
833
+ const entries = Array.isArray(source.lockoutTrustedAddresses) ? source.lockoutTrustedAddresses : [];
834
+ if (entries.length > MAX_TRUSTED_ADDRESSES) {
835
+ errors.lockoutTrustedAddresses = message$1(
836
+ "settings.validation.trustedTooMany",
837
+ "Enter at most {max} addresses.",
838
+ { max: MAX_TRUSTED_ADDRESSES }
839
+ );
840
+ } else {
841
+ const invalid = entries.find((entry) => !isTrustedAddressLine(entry));
842
+ if (invalid !== void 0) {
843
+ errors.lockoutTrustedAddresses = message$1(
844
+ "settings.validation.trustedAddress",
845
+ '"{value}" is not an IP address or CIDR range. Use for example 192.0.2.10 or 192.0.2.0/24.',
846
+ { value: String(invalid).slice(0, 64) }
847
+ );
848
+ }
849
+ }
850
+ return errors;
851
+ }
852
+ function validateRoleRule(draft, takenRoles = []) {
853
+ const errors = {};
854
+ if (!draft?.role) {
855
+ errors.role = message$1("settings.roleRules.validation.role", "Choose a role.");
856
+ } else if (takenRoles.includes(draft.role)) {
857
+ errors.role = message$1(
858
+ "settings.roleRules.validation.duplicate",
859
+ "This role already has a rule."
860
+ );
861
+ }
862
+ let values = 0;
863
+ for (const field of ROLE_RULE_FIELDS) {
864
+ const value = draft?.[field];
865
+ if (value === void 0 || value === null || value === "") continue;
866
+ const error = validateWholeNumber(value, ROLE_RULE_RANGES[field]);
867
+ if (error) errors[field] = error;
868
+ else values += 1;
869
+ }
870
+ if (values === 0 && !ROLE_RULE_FIELDS.some((field) => errors[field])) {
871
+ errors.form = message$1(
872
+ "settings.roleRules.validation.empty",
873
+ "Set at least one value. Empty fields use the general setting."
874
+ );
875
+ }
876
+ return errors;
877
+ }
878
+ function toRoleRule(draft) {
879
+ const rule = { role: draft.role };
880
+ for (const field of ROLE_RULE_FIELDS) {
881
+ const value = draft[field];
882
+ rule[field] = value === void 0 || value === null || value === "" ? null : Number(value);
883
+ }
884
+ return rule;
885
+ }
886
+ function upsertRoleRule(rules, rule, previousRole = null) {
887
+ const list = Array.isArray(rules) ? rules : [];
888
+ const key = previousRole || rule.role;
889
+ const index = list.findIndex((candidate) => candidate.role === key);
890
+ if (index === -1) return [...list, rule];
891
+ return list.map((candidate, position) => position === index ? rule : candidate);
892
+ }
893
+ function removeRoleRule(rules, role) {
894
+ return (Array.isArray(rules) ? rules : []).filter((rule) => rule.role !== role);
895
+ }
896
+ function sortLocks(locks) {
897
+ return (Array.isArray(locks) ? locks : []).slice().sort((a, b) => {
898
+ const until = Date.parse(b.until) - Date.parse(a.until);
899
+ return Number.isFinite(until) && until !== 0 ? until : String(a.id).localeCompare(b.id);
900
+ });
901
+ }
902
+ const TABLE_MIN_WIDTH$1 = 640;
903
+ const keepActionKeys$1 = (event) => {
904
+ if (shouldIsolateActionKey(event.key, true)) event.stopPropagation();
905
+ };
906
+ const EMPTY_DRAFT = Object.freeze({
907
+ role: "",
908
+ maxSessionsPerUser: void 0,
909
+ inactivityTimeout: void 0,
910
+ maxFailedLoginsPerAccount: void 0
911
+ });
912
+ const RuleValue = ({ value, format }) => {
913
+ const { t } = useSettingsTranslate();
914
+ if (value === null || value === void 0) {
915
+ return /* @__PURE__ */ jsx(Typography, { variant: "omega", textColor: "neutral600", children: t("settings.roleRules.general", "General setting") });
916
+ }
917
+ return /* @__PURE__ */ jsx(Typography, { variant: "omega", textColor: "neutral800", children: format(value) });
918
+ };
919
+ const RoleRulesSection = ({ form }) => {
920
+ const { t, tError } = useSettingsTranslate();
921
+ const { get } = useFetchClient();
922
+ const { settings, handleChange } = form;
923
+ const locked = form.canChangeProtected === false;
924
+ const rules = Array.isArray(settings.roleRules) ? settings.roleRules : [];
925
+ const [roles, setRoles] = useState(null);
926
+ const [rolesError, setRolesError] = useState(false);
927
+ const [dialog, setDialog] = useState(null);
928
+ const [draft, setDraft] = useState(EMPTY_DRAFT);
929
+ const [showErrors, setShowErrors] = useState(false);
930
+ const addRef = useRef(null);
931
+ const returnFocusRef = useRef(null);
932
+ const [widthRef, width] = useElementWidth();
933
+ useEffect(() => {
934
+ let active = true;
935
+ get(`/${pluginId}/roles`).then(({ data }) => {
936
+ if (!active) return;
937
+ if (!Array.isArray(data?.data)) throw new Error("Invalid role list");
938
+ setRoles(data.data);
939
+ }).catch((err) => {
940
+ if (!active || isCancelledRequest(err)) return;
941
+ logSafeAdminError("roles", err);
942
+ setRolesError(true);
943
+ });
944
+ return () => {
945
+ active = false;
946
+ };
947
+ }, [get]);
948
+ const roleName = (documentId) => roles?.find((role) => role.documentId === documentId)?.name || t("settings.roleRules.unknownRole", "Removed role");
949
+ const minutes = (value) => t("settings.roleRules.minutes", "{count, plural, one {# minute} other {# minutes}}", {
950
+ count: value
951
+ });
952
+ const sessions = (value) => value === 0 ? t("settings.roleRules.noLimit", "No limit") : t("settings.roleRules.sessions", "{count, plural, one {# session} other {# sessions}}", {
953
+ count: value
954
+ });
955
+ const failures = (value) => value === 0 ? t("settings.roleRules.noAccountLock", "Off") : t("settings.roleRules.failures", "{count, plural, one {# failure} other {# failures}}", {
956
+ count: value
957
+ });
958
+ const open = (rule, trigger) => {
959
+ returnFocusRef.current = trigger || addRef.current;
960
+ setShowErrors(false);
961
+ setDraft(
962
+ rule ? {
963
+ role: rule.role,
964
+ maxSessionsPerUser: rule.maxSessionsPerUser ?? void 0,
965
+ inactivityTimeout: rule.inactivityTimeout ?? void 0,
966
+ maxFailedLoginsPerAccount: rule.maxFailedLoginsPerAccount ?? void 0
967
+ } : EMPTY_DRAFT
968
+ );
969
+ setDialog({ editing: rule ? rule.role : null });
970
+ };
971
+ const close = () => {
972
+ setDialog(null);
973
+ window.requestAnimationFrame?.(() => {
974
+ const target = returnFocusRef.current?.isConnected ? returnFocusRef.current : addRef.current;
975
+ target?.focus?.();
976
+ });
977
+ };
978
+ const taken = rules.map((rule) => rule.role).filter((role) => role !== dialog?.editing);
979
+ const draftErrors = validateRoleRule(draft, taken);
980
+ const submit = () => {
981
+ if (Object.keys(draftErrors).length > 0) {
982
+ setShowErrors(true);
983
+ return;
984
+ }
985
+ handleChange("roleRules", upsertRoleRule(rules, toRoleRule(draft), dialog?.editing));
986
+ close();
987
+ };
988
+ const fieldError = (key) => showErrors ? tError(draftErrors[key]) : void 0;
989
+ const availableRoles = (roles || []).filter((role) => !taken.includes(role.documentId));
990
+ const asTable = width === 0 || width >= TABLE_MIN_WIDTH$1;
991
+ const actions = (rule) => {
992
+ const name = roleName(rule.role);
993
+ return /* @__PURE__ */ jsxs(RowActions, { onKeyDown: keepActionKeys$1, children: [
994
+ /* @__PURE__ */ jsx(
995
+ IconButton,
996
+ {
997
+ variant: "ghost",
998
+ disabled: locked,
999
+ label: t("settings.roleRules.edit", "Edit the rule for {role}", { role: name }),
1000
+ onClick: (event) => open(rule, event.currentTarget),
1001
+ children: /* @__PURE__ */ jsx(Pencil, {})
1002
+ }
1003
+ ),
1004
+ /* @__PURE__ */ jsx(
1005
+ IconButton,
1006
+ {
1007
+ variant: "ghost",
1008
+ disabled: locked,
1009
+ label: t("settings.roleRules.remove", "Remove the rule for {role}", { role: name }),
1010
+ onClick: () => {
1011
+ handleChange("roleRules", removeRoleRule(rules, rule.role));
1012
+ window.requestAnimationFrame?.(() => addRef.current?.focus?.());
1013
+ },
1014
+ children: /* @__PURE__ */ jsx(Trash, {})
1015
+ }
1016
+ )
1017
+ ] });
1018
+ };
1019
+ return /* @__PURE__ */ jsxs(
1020
+ AdvancedSection,
1021
+ {
1022
+ label: t("settings.roleRules.title", "Different rules for some roles"),
1023
+ hasError: Object.keys(form.errors || {}).some((key) => key.startsWith("roleRules")),
1024
+ children: [
1025
+ /* @__PURE__ */ jsx(ReadableText, { variant: "pi", textColor: "neutral600", tag: "p", children: t(
1026
+ "settings.roleRules.intro",
1027
+ "Give a Users & Permissions role its own session limit, inactivity timeout or account lockout. Empty values use the general setting. The overview still counts sessions as idle by the general timeout."
1028
+ ) }),
1029
+ locked ? /* @__PURE__ */ jsx(ProtectedNotice, {}) : null,
1030
+ rolesError ? /* @__PURE__ */ jsx(
1031
+ PersistentAlert,
1032
+ {
1033
+ variant: "warning",
1034
+ closeLabel: t("common.close", "Close"),
1035
+ title: t("settings.roleRules.rolesError", "Roles could not be loaded."),
1036
+ children: t(
1037
+ "settings.roleRules.rolesErrorBody",
1038
+ "Existing rules still apply. Reload the page to add or edit rules."
1039
+ )
1040
+ }
1041
+ ) : null,
1042
+ /* @__PURE__ */ jsx("div", { ref: widthRef, children: rules.length === 0 ? /* @__PURE__ */ jsx(Typography, { variant: "omega", textColor: "neutral600", tag: "p", children: t(
1043
+ "settings.roleRules.empty",
1044
+ "No role has its own rules. Every role uses the general settings."
1045
+ ) }) : asTable ? /* @__PURE__ */ jsx(Box, { hasRadius: true, borderColor: "neutral150", "data-role-rules-table": "", children: /* @__PURE__ */ jsxs(Table, { colCount: 5, rowCount: rules.length + 1, children: [
1046
+ /* @__PURE__ */ jsx(Thead, { children: /* @__PURE__ */ jsxs(Tr, { children: [
1047
+ /* @__PURE__ */ jsx(Th, { children: /* @__PURE__ */ jsx(Typography, { variant: "sigma", textColor: "neutral600", children: t("settings.roleRules.col.role", "Role") }) }),
1048
+ /* @__PURE__ */ jsx(Th, { children: /* @__PURE__ */ jsx(Typography, { variant: "sigma", textColor: "neutral600", children: t("settings.roleRules.col.sessions", "Session limit") }) }),
1049
+ /* @__PURE__ */ jsx(Th, { children: /* @__PURE__ */ jsx(Typography, { variant: "sigma", textColor: "neutral600", children: t("settings.roleRules.col.idle", "Inactivity timeout") }) }),
1050
+ /* @__PURE__ */ jsx(Th, { children: /* @__PURE__ */ jsx(Typography, { variant: "sigma", textColor: "neutral600", children: t("settings.roleRules.col.lockout", "Account lockout") }) }),
1051
+ /* @__PURE__ */ jsx(Th, { children: /* @__PURE__ */ jsx(VisuallyHidden, { children: t("settings.roleRules.col.actions", "Actions") }) })
1052
+ ] }) }),
1053
+ /* @__PURE__ */ jsx(Tbody, { children: rules.map((rule) => /* @__PURE__ */ jsxs(Tr, { "data-role-rule": rule.role, children: [
1054
+ /* @__PURE__ */ jsx(Td, { children: /* @__PURE__ */ jsx(Typography, { variant: "omega", fontWeight: "semiBold", textColor: "neutral800", children: roleName(rule.role) }) }),
1055
+ /* @__PURE__ */ jsx(Td, { children: /* @__PURE__ */ jsx(RuleValue, { value: rule.maxSessionsPerUser, format: sessions }) }),
1056
+ /* @__PURE__ */ jsx(Td, { children: /* @__PURE__ */ jsx(RuleValue, { value: rule.inactivityTimeout, format: minutes }) }),
1057
+ /* @__PURE__ */ jsx(Td, { children: /* @__PURE__ */ jsx(RuleValue, { value: rule.maxFailedLoginsPerAccount, format: failures }) }),
1058
+ /* @__PURE__ */ jsx(Td, { children: actions(rule) })
1059
+ ] }, rule.role)) })
1060
+ ] }) }) : /* @__PURE__ */ jsx(Flex, { direction: "column", alignItems: "stretch", gap: 2, tag: "ul", children: rules.map((rule) => /* @__PURE__ */ jsx(
1061
+ Box,
1062
+ {
1063
+ tag: "li",
1064
+ padding: 4,
1065
+ hasRadius: true,
1066
+ borderColor: "neutral150",
1067
+ "data-role-rule": rule.role,
1068
+ children: /* @__PURE__ */ jsxs(Flex, { justifyContent: "space-between", alignItems: "flex-start", gap: 3, children: [
1069
+ /* @__PURE__ */ jsxs(Flex, { direction: "column", alignItems: "flex-start", gap: 1, minWidth: 0, children: [
1070
+ /* @__PURE__ */ jsx(Typography, { variant: "omega", fontWeight: "semiBold", textColor: "neutral800", children: roleName(rule.role) }),
1071
+ [
1072
+ [
1073
+ "settings.roleRules.col.sessions",
1074
+ "Session limit",
1075
+ rule.maxSessionsPerUser,
1076
+ sessions
1077
+ ],
1078
+ [
1079
+ "settings.roleRules.col.idle",
1080
+ "Inactivity timeout",
1081
+ rule.inactivityTimeout,
1082
+ minutes
1083
+ ],
1084
+ [
1085
+ "settings.roleRules.col.lockout",
1086
+ "Account lockout",
1087
+ rule.maxFailedLoginsPerAccount,
1088
+ failures
1089
+ ]
1090
+ ].map(([id, label, value, format]) => /* @__PURE__ */ jsx(Typography, { variant: "pi", textColor: "neutral600", children: t("settings.roleRules.line", "{label}: {value}", {
1091
+ label: t(id, label),
1092
+ value: value === null || value === void 0 ? t("settings.roleRules.general", "General setting") : format(value)
1093
+ }) }, id))
1094
+ ] }),
1095
+ actions(rule)
1096
+ ] })
1097
+ },
1098
+ rule.role
1099
+ )) }) }),
1100
+ /* @__PURE__ */ jsxs(Flex, { gap: 3, wrap: "wrap", alignItems: "center", children: [
1101
+ /* @__PURE__ */ jsx(
1102
+ Button,
1103
+ {
1104
+ ref: addRef,
1105
+ variant: "secondary",
1106
+ startIcon: /* @__PURE__ */ jsx(Plus, {}),
1107
+ disabled: locked || roles !== null && availableRoles.length === 0 && !dialog,
1108
+ onClick: () => open(null, addRef.current),
1109
+ children: t("settings.roleRules.add", "Add rule")
1110
+ }
1111
+ ),
1112
+ roles !== null && roles.length > 0 && availableRoles.length === 0 ? /* @__PURE__ */ jsx(Typography, { variant: "pi", textColor: "neutral600", "data-role-rules-full": "", children: t(
1113
+ "settings.roleRules.allRoles",
1114
+ "Every role already has a rule. Edit a rule to change it."
1115
+ ) }) : null
1116
+ ] }),
1117
+ /* @__PURE__ */ jsx(Modal.Root, { open: Boolean(dialog), onOpenChange: (next) => next ? null : close(), children: /* @__PURE__ */ jsxs(Modal.Content, { "aria-describedby": void 0, children: [
1118
+ /* @__PURE__ */ jsx(Modal.Header, { closeLabel: t("common.close", "Close"), children: /* @__PURE__ */ jsx(Modal.Title, { children: dialog?.editing ? t("settings.roleRules.dialog.editTitle", "Edit the rule for {role}", {
1119
+ role: roleName(dialog.editing)
1120
+ }) : t("settings.roleRules.dialog.addTitle", "Add a rule for a role") }) }),
1121
+ /* @__PURE__ */ jsx(Modal.Body, { children: /* @__PURE__ */ jsxs(Flex, { direction: "column", alignItems: "stretch", gap: 5, children: [
1122
+ /* @__PURE__ */ jsx(
1123
+ FormField,
1124
+ {
1125
+ id: "role-rule-role",
1126
+ name: "role",
1127
+ label: t("settings.roleRules.col.role", "Role"),
1128
+ error: fieldError("role"),
1129
+ required: true,
1130
+ children: /* @__PURE__ */ jsx(
1131
+ SingleSelect,
1132
+ {
1133
+ value: draft.role || void 0,
1134
+ placeholder: t("settings.roleRules.dialog.rolePlaceholder", "Choose a role"),
1135
+ onChange: (value) => setDraft((previous) => ({ ...previous, role: value })),
1136
+ children: (roles || []).filter(
1137
+ (role) => role.documentId === draft.role || !taken.includes(role.documentId)
1138
+ ).map((role) => /* @__PURE__ */ jsx(SingleSelectOption, { value: role.documentId, children: role.name }, role.documentId))
1139
+ }
1140
+ )
1141
+ }
1142
+ ),
1143
+ [
1144
+ [
1145
+ "maxSessionsPerUser",
1146
+ "role-rule-sessions",
1147
+ t("settings.config.sessionLimit.max.label", "Open sessions per user"),
1148
+ t("settings.roleRules.dialog.sessionsHint", "0 means no limit for this role."),
1149
+ t("settings.roleRules.dialog.sessionsSuffix", "sessions")
1150
+ ],
1151
+ [
1152
+ "inactivityTimeout",
1153
+ "role-rule-idle",
1154
+ t("settings.config.sessions.inactivity.label", "Inactivity timeout"),
1155
+ t("settings.roleRules.dialog.idleHint", "From 1 to 1440 minutes."),
1156
+ t("settings.config.failed.minutes.suffix", "minutes")
1157
+ ],
1158
+ [
1159
+ "maxFailedLoginsPerAccount",
1160
+ "role-rule-lockout",
1161
+ t("settings.config.failed.account.label", "Lock an account after"),
1162
+ t(
1163
+ "settings.roleRules.dialog.lockoutHint",
1164
+ "0 turns the account lockout off for this role."
1165
+ ),
1166
+ t("settings.config.failed.lockout.suffix", "failed sign-ins")
1167
+ ]
1168
+ ].map(([key, id, label, hint, suffix]) => /* @__PURE__ */ jsx(
1169
+ FormField,
1170
+ {
1171
+ id,
1172
+ name: key,
1173
+ label,
1174
+ description: `${hint} ${t("settings.roleRules.dialog.emptyHint", "Leave empty to use the general setting.")}`,
1175
+ suffix,
1176
+ error: fieldError(key),
1177
+ children: /* @__PURE__ */ jsx(
1178
+ NumberInput,
1179
+ {
1180
+ value: draft[key],
1181
+ onValueChange: (value) => setDraft((previous) => ({ ...previous, [key]: value })),
1182
+ min: ROLE_RULE_RANGES[key].min,
1183
+ max: ROLE_RULE_RANGES[key].max,
1184
+ step: 1
1185
+ }
1186
+ )
1187
+ },
1188
+ key
1189
+ )),
1190
+ showErrors && draftErrors.form ? /* @__PURE__ */ jsx(Typography, { variant: "pi", textColor: "danger600", tag: "p", role: "alert", children: tError(draftErrors.form) }) : null
1191
+ ] }) }),
1192
+ /* @__PURE__ */ jsxs(Modal.Footer, { children: [
1193
+ /* @__PURE__ */ jsx(Modal.Close, { children: /* @__PURE__ */ jsx(Button, { variant: "tertiary", children: t("common.cancel", "Cancel") }) }),
1194
+ /* @__PURE__ */ jsx(Button, { onClick: submit, children: dialog?.editing ? t("settings.roleRules.dialog.apply", "Apply") : t("settings.roleRules.dialog.add", "Add rule") })
1195
+ ] })
1196
+ ] }) })
1197
+ ]
1198
+ }
1199
+ );
1200
+ };
736
1201
  const REJECTION_REASONS = [
737
1202
  ["logout", "settings.config.rejected.reason.logout", "The user signed out."],
738
1203
  [
@@ -763,10 +1228,12 @@ const formatReasonCodes = (locale) => {
763
1228
  }
764
1229
  };
765
1230
  const SessionsTab = ({ form }) => {
766
- const { t, locale } = useSettingsTranslate();
1231
+ const { t, tError, locale } = useSettingsTranslate();
767
1232
  const units = useOptionLabels();
768
1233
  const encryptionKeyDraft = useEncryptionKeyDraft();
769
- const { settings, handleChange, relaxedWarningDismissed, setRelaxedWarningDismissed } = form;
1234
+ const { settings, handleChange, relaxedWarningDismissed, setRelaxedWarningDismissed, errors } = form;
1235
+ const sessionLimit = Number(settings.maxSessionsPerUser) || 0;
1236
+ const locked = form.canChangeProtected === false;
770
1237
  const lastSeenTooSlow = Number(settings.lastSeenRateLimit) * 2 > Number(settings.inactivityTimeout) * 60;
771
1238
  return /* @__PURE__ */ jsxs(Flex, { direction: "column", alignItems: "stretch", gap: 6, children: [
772
1239
  /* @__PURE__ */ jsx(IntroText, { children: t(
@@ -957,6 +1424,127 @@ const SessionsTab = ({ form }) => {
957
1424
  ]
958
1425
  }
959
1426
  ),
1427
+ /* @__PURE__ */ jsxs(
1428
+ SectionCard,
1429
+ {
1430
+ id: "session-limit",
1431
+ title: t("settings.config.sessionLimit.title", "Concurrent sessions"),
1432
+ subtitle: t(
1433
+ "settings.config.sessionLimit.intro",
1434
+ "Limits how many sessions one user can have open at the same time."
1435
+ ),
1436
+ children: [
1437
+ locked ? /* @__PURE__ */ jsx(ProtectedNotice, {}) : null,
1438
+ /* @__PURE__ */ jsx(EqualGrid, { columns: 2, stackBelow: "medium", gap: 6, children: /* @__PURE__ */ jsx(
1439
+ FormField,
1440
+ {
1441
+ id: "max-sessions-per-user",
1442
+ name: "maxSessionsPerUser",
1443
+ label: t("settings.config.sessionLimit.max.label", "Open sessions per user"),
1444
+ description: t(
1445
+ "settings.config.sessionLimit.max.hint",
1446
+ "0 means no limit. Sessions that are idle or past their maximum age do not count."
1447
+ ),
1448
+ suffix: t("settings.roleRules.dialog.sessionsSuffix", "sessions"),
1449
+ error: tError(errors.maxSessionsPerUser),
1450
+ required: true,
1451
+ children: /* @__PURE__ */ jsx(
1452
+ NumberInput,
1453
+ {
1454
+ value: settings.maxSessionsPerUser,
1455
+ onValueChange: (value) => handleChange("maxSessionsPerUser", value ?? ""),
1456
+ disabled: locked,
1457
+ min: POLICY_RANGES.maxSessionsPerUser.min,
1458
+ max: POLICY_RANGES.maxSessionsPerUser.max,
1459
+ step: 1
1460
+ },
1461
+ form.draftVersion
1462
+ )
1463
+ }
1464
+ ) }),
1465
+ sessionLimit > 0 ? /* @__PURE__ */ jsxs(Flex, { direction: "column", alignItems: "stretch", gap: 2, "data-session-limit-policy": "", children: [
1466
+ /* @__PURE__ */ jsx(
1467
+ Typography,
1468
+ {
1469
+ id: "session-limit-policy-label",
1470
+ variant: "pi",
1471
+ fontWeight: "bold",
1472
+ tag: "div",
1473
+ textColor: "neutral800",
1474
+ children: t("settings.config.sessionLimit.policy.label", "When the limit is reached")
1475
+ }
1476
+ ),
1477
+ /* @__PURE__ */ jsxs(
1478
+ Radio.Group,
1479
+ {
1480
+ "aria-labelledby": "session-limit-policy-label",
1481
+ value: settings.sessionLimitPolicy || "end-oldest",
1482
+ disabled: locked,
1483
+ onValueChange: (value) => handleChange("sessionLimitPolicy", value),
1484
+ children: [
1485
+ /* @__PURE__ */ jsx(Radio.Item, { value: "end-oldest", children: t("settings.config.sessionLimit.policy.endOldest", "End the oldest session") }),
1486
+ /* @__PURE__ */ jsx(Radio.Item, { value: "refuse", children: t("settings.config.sessionLimit.policy.refuse", "Refuse the new sign-in") })
1487
+ ]
1488
+ }
1489
+ ),
1490
+ settings.sessionLimitPolicy === "refuse" ? /* @__PURE__ */ jsx(
1491
+ Alert,
1492
+ {
1493
+ variant: "warning",
1494
+ closeLabel: t("common.close", "Close"),
1495
+ title: t(
1496
+ "settings.config.sessionLimit.refuse.title",
1497
+ "Users can lock themselves out"
1498
+ ),
1499
+ children: t(
1500
+ "settings.config.sessionLimit.refuse.body",
1501
+ "A user who reaches the limit cannot sign in on a new device until another session ends or times out. The app receives 403 with the code SESSION_LIMIT_REACHED."
1502
+ )
1503
+ }
1504
+ ) : null
1505
+ ] }) : null
1506
+ ]
1507
+ }
1508
+ ),
1509
+ /* @__PURE__ */ jsxs(
1510
+ SectionCard,
1511
+ {
1512
+ id: "password-change",
1513
+ title: t("settings.config.passwordChange.title", "Password change"),
1514
+ children: [
1515
+ locked ? /* @__PURE__ */ jsx(ProtectedNotice, {}) : null,
1516
+ /* @__PURE__ */ jsx(
1517
+ SettingsToggleRow,
1518
+ {
1519
+ id: "end-other-sessions-on-password-change",
1520
+ title: t(
1521
+ "settings.config.passwordChange.label",
1522
+ "End other sessions after a password change"
1523
+ ),
1524
+ description: t(
1525
+ "settings.config.passwordChange.hint",
1526
+ "When a user changes their password, every other session of that user ends. The session that made the change stays. A password reset always ends the other sessions."
1527
+ ),
1528
+ checked: settings.endOtherSessionsOnPasswordChange === true,
1529
+ disabled: locked,
1530
+ onChange: (checked) => handleChange("endOtherSessionsOnPasswordChange", checked)
1531
+ }
1532
+ )
1533
+ ]
1534
+ }
1535
+ ),
1536
+ /* @__PURE__ */ jsx(
1537
+ SectionCard,
1538
+ {
1539
+ id: "role-rules",
1540
+ title: t("settings.roleRules.cardTitle", "Roles"),
1541
+ subtitle: t(
1542
+ "settings.roleRules.cardIntro",
1543
+ "Optional. Most installations need no role rules."
1544
+ ),
1545
+ children: /* @__PURE__ */ jsx(RoleRulesSection, { form })
1546
+ }
1547
+ ),
960
1548
  /* @__PURE__ */ jsxs(
961
1549
  SectionCard,
962
1550
  {
@@ -1010,7 +1598,12 @@ function areSettingsEqual(left, right) {
1010
1598
  (key, index) => key === rightKeys[index] && areSettingsEqual(left[key], right[key])
1011
1599
  );
1012
1600
  }
1013
- const TEMPLATE_KEYS = Object.freeze(["suspiciousLogin", "newLocation", "vpnProxy"]);
1601
+ const TEMPLATE_KEYS = Object.freeze([
1602
+ "suspiciousLogin",
1603
+ "newLocation",
1604
+ "vpnProxy",
1605
+ "accountLocked"
1606
+ ]);
1014
1607
  const TEMPLATE_LIMITS = Object.freeze({ subject: 200, html: 1e4, text: 5e3 });
1015
1608
  const TEMPLATE_VARIABLE_DEFINITIONS = Object.freeze({
1016
1609
  "{{user.email}}": {
@@ -1060,6 +1653,14 @@ const TEMPLATE_VARIABLE_DEFINITIONS = Object.freeze({
1060
1653
  "{{reason.securityScore}}": {
1061
1654
  messageId: "settings.email.templates.variable.securityScore",
1062
1655
  defaultMessage: "Security score (0 to 100)"
1656
+ },
1657
+ "{{lock.minutes}}": {
1658
+ messageId: "settings.email.templates.variable.lockMinutes",
1659
+ defaultMessage: "Lock duration in minutes"
1660
+ },
1661
+ "{{lock.until}}": {
1662
+ messageId: "settings.email.templates.variable.lockUntil",
1663
+ defaultMessage: "Time the lock ends (UTC)"
1063
1664
  }
1064
1665
  });
1065
1666
  const TEMPLATE_VARIABLES = Object.freeze({
@@ -1097,7 +1698,8 @@ const TEMPLATE_VARIABLES = Object.freeze({
1097
1698
  "{{session.userAgent}}",
1098
1699
  "{{reason.isVpn}}",
1099
1700
  "{{reason.isProxy}}"
1100
- ]
1701
+ ],
1702
+ accountLocked: ["{{user.email}}", "{{user.username}}", "{{lock.minutes}}", "{{lock.until}}"]
1101
1703
  });
1102
1704
  const TEMPLATE_PREVIEW_VALUES = Object.freeze({
1103
1705
  "{{user.email}}": "jane.doe@example.com",
@@ -1111,7 +1713,9 @@ const TEMPLATE_PREVIEW_VALUES = Object.freeze({
1111
1713
  "{{reason.isVpn}}": "true",
1112
1714
  "{{reason.isProxy}}": "false",
1113
1715
  "{{reason.isThreat}}": "false",
1114
- "{{reason.securityScore}}": "35"
1716
+ "{{reason.securityScore}}": "35",
1717
+ "{{lock.minutes}}": "15",
1718
+ "{{lock.until}}": "Fri, 06 Nov 2026 09:56:00 GMT"
1115
1719
  });
1116
1720
  function updateEmailTemplate(templates, templateKey, field, value) {
1117
1721
  return { ...templates, [templateKey]: { ...templates[templateKey], [field]: value } };
@@ -1372,6 +1976,28 @@ Login Details:
1372
1976
  - IP Address: {{session.ipAddress}}
1373
1977
  - Location: {{geo.city}}, {{geo.country}}
1374
1978
  - VPN: {{reason.isVpn}}, Proxy: {{reason.isProxy}}`
1979
+ },
1980
+ // Same default as server/src/services/notifications.js (4.17).
1981
+ accountLocked: {
1982
+ subject: "Your account was locked after failed sign-ins",
1983
+ html: `<html>
1984
+ <body style="font-family: Arial, sans-serif; line-height: 1.6; color: #333;">
1985
+ <div style="max-width: 600px; margin: 0 auto; padding: 20px;">
1986
+ <h2>Your account was temporarily locked</h2>
1987
+ <p>Hello {{user.username}},</p>
1988
+ <p>There were several failed sign-in attempts for your account. To protect it, sign-in is locked for {{lock.minutes}} minutes, until {{lock.until}}.</p>
1989
+ <p>If these attempts were not yours, change your password after the lock ends.</p>
1990
+ <p style="color: #666; font-size: 12px;">This is an automated security notification.</p>
1991
+ </div>
1992
+ </body>
1993
+ </html>`,
1994
+ text: `Your account was temporarily locked
1995
+
1996
+ Hello {{user.username}},
1997
+
1998
+ There were several failed sign-in attempts for your account. To protect it, sign-in is locked for {{lock.minutes}} minutes, until {{lock.until}}.
1999
+
2000
+ If these attempts were not yours, change your password after the lock ends.`
1375
2001
  }
1376
2002
  });
1377
2003
  function fillMissingTemplates(templates) {
@@ -1428,7 +2054,8 @@ const SETTINGS_DEFAULTS = Object.freeze({
1428
2054
  securityLogStoreIp: true,
1429
2055
  securityLogAnonymizeIp: false,
1430
2056
  securityLogGeoLookup: false,
1431
- securityLogRetentionDays: 90
2057
+ securityLogRetentionDays: 90,
2058
+ ...POLICY_FORM_DEFAULTS
1432
2059
  });
1433
2060
  const WRITE_ONLY_SETTINGS_KEYS = Object.freeze(["discordWebhookUrl", "slackWebhookUrl"]);
1434
2061
  const MAX_FAILED_LOGINS_RANGE = Object.freeze({ min: 0, max: 100 });
@@ -1451,6 +2078,8 @@ function normalizeSettings(loaded) {
1451
2078
  ...loaded,
1452
2079
  allowedCountries: Array.isArray(loaded.allowedCountries) ? loaded.allowedCountries : [],
1453
2080
  blockedCountries: Array.isArray(loaded.blockedCountries) ? loaded.blockedCountries : [],
2081
+ lockoutTrustedAddresses: Array.isArray(loaded.lockoutTrustedAddresses) ? loaded.lockoutTrustedAddresses : [],
2082
+ roleRules: Array.isArray(loaded.roleRules) ? loaded.roleRules : [],
1454
2083
  emailTemplates: fillMissingTemplates(loaded.emailTemplates)
1455
2084
  };
1456
2085
  }
@@ -1500,6 +2129,7 @@ function validateSettings(settings) {
1500
2129
  const source = settings || {};
1501
2130
  const maxFailed = validateMaxFailedLogins(source.maxFailedLogins);
1502
2131
  if (maxFailed) errors.maxFailedLogins = maxFailed;
2132
+ Object.assign(errors, validatePolicyFields(source));
1503
2133
  if (!isAllowedWebhookUrl(source.discordWebhookUrl, WEBHOOK_HOSTS.discordWebhookUrl)) {
1504
2134
  errors.discordWebhookUrl = message(
1505
2135
  "settings.validation.webhookDiscord",
@@ -1543,6 +2173,312 @@ function getAdjustedFields(submitted, stored, previous) {
1543
2173
  (key) => !WRITE_ONLY_SETTINGS_KEYS.includes(key) && !areSettingsEqual(source[key], stored?.[key]) && (previous === void 0 || !areSettingsEqual(source[key], previous?.[key]))
1544
2174
  );
1545
2175
  }
2176
+ const TABLE_MIN_WIDTH = 640;
2177
+ const keepActionKeys = (event) => {
2178
+ if (shouldIsolateActionKey(event.key, true)) event.stopPropagation();
2179
+ };
2180
+ const LockTarget = ({ lock }) => {
2181
+ const { t } = useSettingsTranslate();
2182
+ if (lock.kind === "ip") {
2183
+ return /* @__PURE__ */ jsx(
2184
+ Typography,
2185
+ {
2186
+ variant: "omega",
2187
+ textColor: "neutral800",
2188
+ tag: "p",
2189
+ style: { overflowWrap: "anywhere" },
2190
+ children: lock.ip || t("settings.lockouts.ipHidden", "IP address not stored")
2191
+ }
2192
+ );
2193
+ }
2194
+ if (!lock.user) {
2195
+ return /* @__PURE__ */ jsx(Typography, { variant: "omega", textColor: "neutral600", children: t("settings.lockouts.unknownAccount", "Account that does not exist") });
2196
+ }
2197
+ return /* @__PURE__ */ jsxs(Flex, { direction: "column", alignItems: "stretch", gap: 1, minWidth: 0, width: "100%", children: [
2198
+ /* @__PURE__ */ jsx(
2199
+ Typography,
2200
+ {
2201
+ variant: "omega",
2202
+ fontWeight: "semiBold",
2203
+ textColor: "neutral800",
2204
+ tag: "p",
2205
+ style: { overflowWrap: "anywhere" },
2206
+ children: lock.user.username || lock.user.email
2207
+ }
2208
+ ),
2209
+ lock.user.email && lock.user.username ? /* @__PURE__ */ jsx(
2210
+ Typography,
2211
+ {
2212
+ variant: "pi",
2213
+ textColor: "neutral600",
2214
+ tag: "p",
2215
+ style: { overflowWrap: "anywhere" },
2216
+ children: lock.user.email
2217
+ }
2218
+ ) : null
2219
+ ] });
2220
+ };
2221
+ const KindBadge = ({ kind }) => {
2222
+ const { t } = useSettingsTranslate();
2223
+ return /* @__PURE__ */ jsx(Badge, { backgroundColor: "neutral150", textColor: "neutral800", children: kind === "ip" ? t("settings.lockouts.kind.ip", "IP address") : t("settings.lockouts.kind.account", "Account") });
2224
+ };
2225
+ const lockName = (lock, t) => {
2226
+ if (lock.kind === "ip")
2227
+ return lock.ip || t("settings.lockouts.ipHidden", "IP address not stored");
2228
+ if (lock.user) return lock.user.username || lock.user.email;
2229
+ return t("settings.lockouts.unknownAccount", "Account that does not exist");
2230
+ };
2231
+ const LockedNowCard = () => {
2232
+ const { t } = useSettingsTranslate();
2233
+ const { get, post } = useFetchClient();
2234
+ const { toggleNotification } = useNotification();
2235
+ const { formatDate } = useSessionFormatters();
2236
+ const {
2237
+ isLoading: permissionsLoading,
2238
+ allowedActions: { canUnlock }
2239
+ } = useRBAC(pluginPermissions.lockoutsUnlock);
2240
+ const [widthRef, width] = useElementWidth();
2241
+ const [locks, setLocks] = useState(null);
2242
+ const [error, setError] = useState(false);
2243
+ const [refreshing, setRefreshing] = useState(false);
2244
+ const refreshRef = useRef(null);
2245
+ const requestRef = useRef(0);
2246
+ const apply = useCallback(async (request, pending) => {
2247
+ try {
2248
+ const { data } = await pending;
2249
+ if (request !== requestRef.current) return;
2250
+ if (!Array.isArray(data?.data)) throw new Error("Invalid lock list");
2251
+ setLocks(sortLocks(data.data));
2252
+ setError(false);
2253
+ } catch (err) {
2254
+ if (isCancelledRequest(err) || request !== requestRef.current) return;
2255
+ logSafeAdminError("lockouts", err);
2256
+ setError(true);
2257
+ } finally {
2258
+ if (request === requestRef.current) setRefreshing(false);
2259
+ }
2260
+ }, []);
2261
+ const load = useCallback(() => {
2262
+ const request = ++requestRef.current;
2263
+ setRefreshing(true);
2264
+ return apply(request, get(`/${pluginId}/lockouts`));
2265
+ }, [apply, get]);
2266
+ useEffect(() => {
2267
+ apply(++requestRef.current, get(`/${pluginId}/lockouts`));
2268
+ }, [apply, get]);
2269
+ const unlock = async (lock) => {
2270
+ try {
2271
+ await post(`/${pluginId}/lockouts/unlock`, { id: lock.id });
2272
+ toggleNotification({
2273
+ type: "success",
2274
+ message: t("settings.lockouts.unlocked", "{name} was unlocked.", {
2275
+ name: lockName(lock, t)
2276
+ })
2277
+ });
2278
+ } catch (err) {
2279
+ if (err?.response?.status === 404) {
2280
+ toggleNotification({
2281
+ type: "info",
2282
+ message: t("settings.lockouts.alreadyEnded", "This lock had already ended.")
2283
+ });
2284
+ } else {
2285
+ logSafeAdminError("lockouts", err);
2286
+ toggleNotification({
2287
+ type: "danger",
2288
+ message: t("settings.lockouts.unlockFailed", "The lock could not be lifted.")
2289
+ });
2290
+ throw err;
2291
+ }
2292
+ } finally {
2293
+ await load();
2294
+ }
2295
+ };
2296
+ const showActions = !permissionsLoading && canUnlock;
2297
+ const asTable = width === 0 || width >= TABLE_MIN_WIDTH;
2298
+ const unlockAction = (lock) => showActions ? /* @__PURE__ */ jsx(
2299
+ ConfirmAction,
2300
+ {
2301
+ fallbackFocusRef: refreshRef,
2302
+ title: t("settings.lockouts.confirm.title", "Unlock {name}?", { name: lockName(lock, t) }),
2303
+ body: lock.kind === "ip" ? t(
2304
+ "settings.lockouts.confirm.bodyIp",
2305
+ "Sign-ins from this address are allowed again at once, and its failed attempts are reset. This is recorded in the security log."
2306
+ ) : t(
2307
+ "settings.lockouts.confirm.bodyAccount",
2308
+ "Sign-ins to this account are allowed again at once, and its failed attempts are reset. This is recorded in the security log."
2309
+ ),
2310
+ confirmLabel: t("settings.lockouts.confirm.action", "Unlock"),
2311
+ variant: "default",
2312
+ onConfirm: () => unlock(lock),
2313
+ trigger: /* @__PURE__ */ jsx(
2314
+ IconButton,
2315
+ {
2316
+ variant: "ghost",
2317
+ label: t("settings.lockouts.unlockLabel", "Unlock {name}", { name: lockName(lock, t) }),
2318
+ children: /* @__PURE__ */ jsx(Key, {})
2319
+ }
2320
+ )
2321
+ },
2322
+ lock.id
2323
+ ) : null;
2324
+ const ends = (lock) => /* @__PURE__ */ jsx(Typography, { tag: "time", dateTime: lock.until, variant: "omega", textColor: "neutral800", children: formatDate(lock.until, { hour: "2-digit", minute: "2-digit" }) });
2325
+ let content;
2326
+ if (locks === null && !error) {
2327
+ content = /* @__PURE__ */ jsx(Flex, { justifyContent: "center", padding: 6, children: /* @__PURE__ */ jsx(Loader, { small: true, children: t("settings.lockouts.loading", "Loading locks…") }) });
2328
+ } else if (error && locks === null) {
2329
+ content = /* @__PURE__ */ jsx(
2330
+ PersistentAlert,
2331
+ {
2332
+ variant: "danger",
2333
+ closeLabel: t("common.close", "Close"),
2334
+ title: t("settings.lockouts.error", "Locks could not be loaded."),
2335
+ action: /* @__PURE__ */ jsx(Button, { variant: "tertiary", onClick: load, children: t("common.tryAgain", "Try again") }),
2336
+ children: t("settings.lockouts.errorBody", "Sign-ins are still checked; only this list is missing.")
2337
+ }
2338
+ );
2339
+ } else if (locks.length === 0) {
2340
+ content = /* @__PURE__ */ jsx(
2341
+ EmptyStateLayout,
2342
+ {
2343
+ icon: /* @__PURE__ */ jsx(EmptyPermissions, { width: "16rem", height: "8rem" }),
2344
+ content: t(
2345
+ "settings.lockouts.empty",
2346
+ "Nothing is locked. Locked IP addresses and accounts appear here until their lock ends."
2347
+ )
2348
+ }
2349
+ );
2350
+ } else if (asTable) {
2351
+ content = /* @__PURE__ */ jsx(Box, { hasRadius: true, borderColor: "neutral150", "data-locks-table": "", children: /* @__PURE__ */ jsxs(Table, { colCount: showActions ? 5 : 4, rowCount: locks.length + 1, "aria-busy": refreshing, children: [
2352
+ /* @__PURE__ */ jsx(Thead, { children: /* @__PURE__ */ jsxs(Tr, { children: [
2353
+ /* @__PURE__ */ jsx(Th, { children: /* @__PURE__ */ jsx(Typography, { variant: "sigma", textColor: "neutral600", children: t("settings.lockouts.col.locked", "Locked") }) }),
2354
+ /* @__PURE__ */ jsx(Th, { children: /* @__PURE__ */ jsx(Typography, { variant: "sigma", textColor: "neutral600", children: t("settings.lockouts.col.kind", "Type") }) }),
2355
+ /* @__PURE__ */ jsx(Th, { children: /* @__PURE__ */ jsx(Typography, { variant: "sigma", textColor: "neutral600", children: t("settings.lockouts.col.failures", "Failed sign-ins") }) }),
2356
+ /* @__PURE__ */ jsx(Th, { children: /* @__PURE__ */ jsx(Typography, { variant: "sigma", textColor: "neutral600", children: t("settings.lockouts.col.until", "Locked until") }) }),
2357
+ showActions ? /* @__PURE__ */ jsx(Th, { children: /* @__PURE__ */ jsx(VisuallyHidden, { children: t("settings.lockouts.col.actions", "Actions") }) }) : null
2358
+ ] }) }),
2359
+ /* @__PURE__ */ jsx(Tbody, { children: locks.map((lock) => /* @__PURE__ */ jsxs(Tr, { "data-lock-row": lock.kind, children: [
2360
+ /* @__PURE__ */ jsx(Td, { style: { maxWidth: 0, width: "40%" }, children: /* @__PURE__ */ jsx(LockTarget, { lock }) }),
2361
+ /* @__PURE__ */ jsx(Td, { children: /* @__PURE__ */ jsx(KindBadge, { kind: lock.kind }) }),
2362
+ /* @__PURE__ */ jsx(Td, { children: /* @__PURE__ */ jsx(Typography, { variant: "omega", textColor: "neutral800", children: lock.failures }) }),
2363
+ /* @__PURE__ */ jsx(Td, { children: ends(lock) }),
2364
+ showActions ? /* @__PURE__ */ jsx(Td, { children: /* @__PURE__ */ jsx(RowActions, { onKeyDown: keepActionKeys, children: unlockAction(lock) }) }) : null
2365
+ ] }, lock.id)) })
2366
+ ] }) });
2367
+ } else {
2368
+ content = /* @__PURE__ */ jsx(Flex, { direction: "column", alignItems: "stretch", gap: 2, tag: "ul", "data-locks-list": "", children: locks.map((lock) => /* @__PURE__ */ jsx(
2369
+ Box,
2370
+ {
2371
+ tag: "li",
2372
+ padding: 4,
2373
+ hasRadius: true,
2374
+ borderColor: "neutral150",
2375
+ "data-lock-row": lock.kind,
2376
+ children: /* @__PURE__ */ jsxs(Flex, { justifyContent: "space-between", alignItems: "flex-start", gap: 3, children: [
2377
+ /* @__PURE__ */ jsxs(Flex, { direction: "column", alignItems: "flex-start", gap: 2, minWidth: 0, children: [
2378
+ /* @__PURE__ */ jsx(LockTarget, { lock }),
2379
+ /* @__PURE__ */ jsxs(Flex, { gap: 2, wrap: "wrap", children: [
2380
+ /* @__PURE__ */ jsx(KindBadge, { kind: lock.kind }),
2381
+ /* @__PURE__ */ jsx(Typography, { variant: "pi", textColor: "neutral600", children: t("settings.lockouts.summary", "{count} failed, until {time}", {
2382
+ count: lock.failures,
2383
+ time: formatDate(lock.until, { hour: "2-digit", minute: "2-digit" })
2384
+ }) })
2385
+ ] })
2386
+ ] }),
2387
+ /* @__PURE__ */ jsx(RowActions, { onKeyDown: keepActionKeys, children: unlockAction(lock) })
2388
+ ] })
2389
+ },
2390
+ lock.id
2391
+ )) });
2392
+ }
2393
+ return /* @__PURE__ */ jsx(
2394
+ SectionCard,
2395
+ {
2396
+ id: "locked-now",
2397
+ title: t("settings.lockouts.title", "Locked now"),
2398
+ subtitle: t(
2399
+ "settings.lockouts.intro",
2400
+ "IP addresses and accounts that are refused right now after failed sign-ins."
2401
+ ),
2402
+ action: /* @__PURE__ */ jsx(
2403
+ Button,
2404
+ {
2405
+ ref: refreshRef,
2406
+ variant: "tertiary",
2407
+ startIcon: /* @__PURE__ */ jsx(ArrowClockwise, {}),
2408
+ onClick: load,
2409
+ loading: refreshing && locks !== null,
2410
+ children: t("settings.lockouts.refresh", "Refresh")
2411
+ }
2412
+ ),
2413
+ children: /* @__PURE__ */ jsxs("div", { ref: widthRef, "aria-live": "polite", children: [
2414
+ error && locks !== null ? /* @__PURE__ */ jsx(Box, { paddingBottom: 3, children: /* @__PURE__ */ jsx(
2415
+ PersistentAlert,
2416
+ {
2417
+ variant: "warning",
2418
+ closeLabel: t("common.close", "Close"),
2419
+ title: t("settings.lockouts.refreshErrorTitle", "Not refreshed"),
2420
+ children: t(
2421
+ "settings.lockouts.refreshError",
2422
+ "The list could not be refreshed. It shows the last known locks."
2423
+ )
2424
+ }
2425
+ ) }) : null,
2426
+ content,
2427
+ locks && locks.length > 0 && !showActions && !permissionsLoading ? /* @__PURE__ */ jsx(Box, { paddingTop: 3, children: /* @__PURE__ */ jsxs(Flex, { gap: 2, alignItems: "center", children: [
2428
+ /* @__PURE__ */ jsx(Lock, { "aria-hidden": true, fill: "neutral600" }),
2429
+ /* @__PURE__ */ jsx(Typography, { variant: "pi", textColor: "neutral600", children: t(
2430
+ "settings.lockouts.noUnlock",
2431
+ 'Unlocking needs the "Unlock locked sign-ins" permission.'
2432
+ ) })
2433
+ ] }) }) : null,
2434
+ /* @__PURE__ */ jsx(VisuallyHidden, { children: locks ? t(
2435
+ "settings.lockouts.count",
2436
+ "{count, plural, =0 {No locks} one {# lock} other {# locks}}",
2437
+ {
2438
+ count: locks.length
2439
+ }
2440
+ ) : null })
2441
+ ] })
2442
+ }
2443
+ );
2444
+ };
2445
+ const TrustedAddressesField = ({ form, disabled = false }) => {
2446
+ const { t, tError } = useSettingsTranslate();
2447
+ const { settings, handleChange, errors, draftVersion } = form;
2448
+ const [text, setText] = useState(
2449
+ () => formatTrustedAddressText(settings.lockoutTrustedAddresses)
2450
+ );
2451
+ const [version, setVersion] = useState(draftVersion);
2452
+ if (version !== draftVersion) {
2453
+ setVersion(draftVersion);
2454
+ setText(formatTrustedAddressText(settings.lockoutTrustedAddresses));
2455
+ }
2456
+ return /* @__PURE__ */ jsx(
2457
+ FormField,
2458
+ {
2459
+ id: "lockout-trusted-addresses",
2460
+ name: "lockoutTrustedAddresses",
2461
+ label: t("settings.config.failed.trusted.label", "Trusted addresses"),
2462
+ description: t(
2463
+ "settings.config.failed.trusted.hint",
2464
+ "One IP address or CIDR range per line, for example 192.0.2.10 or 192.0.2.0/24. These addresses are never locked by IP; accounts can still be locked. Use it for an office network or a server that signs in for many users."
2465
+ ),
2466
+ error: tError(errors.lockoutTrustedAddresses),
2467
+ children: /* @__PURE__ */ jsx(
2468
+ Textarea,
2469
+ {
2470
+ value: text,
2471
+ placeholder: "192.0.2.0/24",
2472
+ disabled,
2473
+ onChange: (event) => {
2474
+ setText(event.target.value);
2475
+ handleChange("lockoutTrustedAddresses", parseTrustedAddressText(event.target.value));
2476
+ }
2477
+ }
2478
+ )
2479
+ }
2480
+ );
2481
+ };
1546
2482
  const COUNTRIES = [
1547
2483
  { code: "DE", name: "Germany", flag: "🇩🇪" },
1548
2484
  { code: "AT", name: "Austria", flag: "🇦🇹" },
@@ -1938,20 +2874,59 @@ const CountryListEditor = ({ settings, handleChange }) => {
1938
2874
  ] })
1939
2875
  ] });
1940
2876
  };
2877
+ const describeLockout = (t, { ip, account, window: window2, duration }) => {
2878
+ if (ip === 0 && account === 0) {
2879
+ return t(
2880
+ "settings.config.failed.lockout.offBoth",
2881
+ "The lockout is off. Failed sign-ins are not limited."
2882
+ );
2883
+ }
2884
+ const parts = [];
2885
+ if (ip > 0) {
2886
+ parts.push(
2887
+ t(
2888
+ "settings.config.failed.preview.ip",
2889
+ "{count, plural, one {# failed sign-in} other {# failed sign-ins}} from one IP address within {window, plural, one {# minute} other {# minutes}} lock that address for {duration, plural, one {# minute} other {# minutes}}.",
2890
+ { count: ip, window: window2, duration }
2891
+ )
2892
+ );
2893
+ }
2894
+ if (account > 0) {
2895
+ parts.push(
2896
+ t(
2897
+ "settings.config.failed.preview.account",
2898
+ "{count, plural, one {# failed sign-in} other {# failed sign-ins}} for one account within {window, plural, one {# minute} other {# minutes}} lock that account for {duration, plural, one {# minute} other {# minutes}}, from every address.",
2899
+ { count: account, window: window2, duration }
2900
+ )
2901
+ );
2902
+ }
2903
+ return parts.join(" ");
2904
+ };
1941
2905
  const LoginProtectionTab = ({ form }) => {
1942
2906
  const { t, tError } = useSettingsTranslate();
1943
2907
  const { settings, handleChange, errors } = form;
1944
2908
  const maxFailedError = tError(errors.maxFailedLogins);
1945
2909
  const maxFailedValue = Number(settings.maxFailedLogins);
2910
+ const accountValue = Number(settings.maxFailedLoginsPerAccount) || 0;
2911
+ const accountByRole = (settings.roleRules || []).some(
2912
+ (rule) => rule.maxFailedLoginsPerAccount !== null && rule.maxFailedLoginsPerAccount !== void 0
2913
+ );
2914
+ const lockoutPreview = describeLockout(t, {
2915
+ ip: maxFailedValue,
2916
+ account: accountValue,
2917
+ window: Number(settings.lockoutWindowMinutes) || 15,
2918
+ duration: Number(settings.lockoutDurationMinutes) || 15
2919
+ });
1946
2920
  const lookupOff = !settings.enableGeolocation;
1947
2921
  const locked = form.canChangeProtected === false;
2922
+ const policyLocked = locked;
1948
2923
  const risk = getRiskAvailability(form.geoIp.status);
1949
2924
  const reject = riskDependentControl(settings.blockSuspiciousSessions, risk.state);
1950
2925
  const autoStillRejects = reject.savedOnButInactive && (settings.geoLookupFailureMode || "auto") === "auto";
1951
2926
  return /* @__PURE__ */ jsxs(Flex, { direction: "column", alignItems: "stretch", gap: 6, children: [
1952
2927
  /* @__PURE__ */ jsx(IntroText, { children: t(
1953
2928
  "settings.config.loginProtection.intro",
1954
- "These rules check new sign-ins before they succeed. Existing sessions are not affected, and refused sign-ins are not recorded."
2929
+ "These rules check new sign-ins before they succeed. Existing sessions are not affected. Failed and refused sign-ins are recorded in the security log while recording is on."
1955
2930
  ) }),
1956
2931
  /* @__PURE__ */ jsxs(
1957
2932
  SectionCard,
@@ -1959,63 +2934,180 @@ const LoginProtectionTab = ({ form }) => {
1959
2934
  title: t("settings.config.failed.title", "Failed sign-ins"),
1960
2935
  subtitle: t(
1961
2936
  "settings.config.failed.intro",
1962
- "Slows down password guessing from one IP address."
2937
+ "Slows down password guessing. Counts are shared by every server process."
1963
2938
  ),
1964
2939
  children: [
1965
- /* @__PURE__ */ jsx(EqualGrid, { columns: 2, stackBelow: "medium", gap: 6, children: /* @__PURE__ */ jsx(
1966
- FormField,
1967
- {
1968
- id: "max-failed-logins",
1969
- name: "maxFailedLogins",
1970
- label: t("settings.config.failed.lockout.label", "Temporary IP lockout after"),
1971
- description: t(
1972
- "settings.config.failed.lockout.hint",
1973
- "A whole number from 0 to 100. 0 turns the lockout off."
1974
- ),
1975
- suffix: t("settings.config.failed.lockout.suffix", "failed sign-ins"),
1976
- error: maxFailedError,
1977
- required: true,
1978
- children: /* @__PURE__ */ jsx(
1979
- NumberInput,
1980
- {
1981
- value: settings.maxFailedLogins,
1982
- onValueChange: (value) => handleChange("maxFailedLogins", value),
1983
- min: MAX_FAILED_LOGINS_RANGE.min,
1984
- max: MAX_FAILED_LOGINS_RANGE.max,
1985
- step: 1
1986
- },
1987
- form.draftVersion
1988
- )
1989
- }
1990
- ) }),
1991
- !maxFailedError ? /* @__PURE__ */ jsx(
2940
+ policyLocked ? /* @__PURE__ */ jsx(ProtectedNotice, {}) : null,
2941
+ /* @__PURE__ */ jsxs(EqualGrid, { columns: 2, stackBelow: "medium", gap: 6, children: [
2942
+ /* @__PURE__ */ jsx(
2943
+ FormField,
2944
+ {
2945
+ id: "max-failed-logins",
2946
+ name: "maxFailedLogins",
2947
+ label: t("settings.config.failed.lockout.label", "Lock an IP address after"),
2948
+ description: t(
2949
+ "settings.config.failed.lockout.hint",
2950
+ "A whole number from 0 to 100. 0 turns the IP lockout off."
2951
+ ),
2952
+ suffix: t("settings.config.failed.lockout.suffix", "failed sign-ins"),
2953
+ error: maxFailedError,
2954
+ required: true,
2955
+ children: /* @__PURE__ */ jsx(
2956
+ NumberInput,
2957
+ {
2958
+ value: settings.maxFailedLogins,
2959
+ onValueChange: (value) => handleChange("maxFailedLogins", value),
2960
+ min: MAX_FAILED_LOGINS_RANGE.min,
2961
+ max: MAX_FAILED_LOGINS_RANGE.max,
2962
+ step: 1
2963
+ },
2964
+ form.draftVersion
2965
+ )
2966
+ }
2967
+ ),
2968
+ /* @__PURE__ */ jsx(
2969
+ FormField,
2970
+ {
2971
+ id: "max-failed-logins-account",
2972
+ name: "maxFailedLoginsPerAccount",
2973
+ label: t("settings.config.failed.account.label", "Lock an account after"),
2974
+ description: t(
2975
+ "settings.config.failed.account.hint",
2976
+ "Counts failed sign-ins for one account from any address. 0 turns it off. Anyone who knows an account name can lock it, so keep this higher than the IP limit."
2977
+ ),
2978
+ suffix: t("settings.config.failed.lockout.suffix", "failed sign-ins"),
2979
+ error: tError(errors.maxFailedLoginsPerAccount),
2980
+ required: true,
2981
+ children: /* @__PURE__ */ jsx(
2982
+ NumberInput,
2983
+ {
2984
+ value: settings.maxFailedLoginsPerAccount,
2985
+ onValueChange: (value) => handleChange("maxFailedLoginsPerAccount", value ?? ""),
2986
+ disabled: policyLocked,
2987
+ min: POLICY_RANGES.maxFailedLoginsPerAccount.min,
2988
+ max: POLICY_RANGES.maxFailedLoginsPerAccount.max,
2989
+ step: 1
2990
+ },
2991
+ form.draftVersion
2992
+ )
2993
+ }
2994
+ ),
2995
+ /* @__PURE__ */ jsx(
2996
+ FormField,
2997
+ {
2998
+ id: "lockout-window",
2999
+ name: "lockoutWindowMinutes",
3000
+ label: t("settings.config.failed.window.label", "Count failed sign-ins within"),
3001
+ description: t(
3002
+ "settings.config.failed.window.hint",
3003
+ "Failures older than this no longer count."
3004
+ ),
3005
+ suffix: t("settings.config.failed.minutes.suffix", "minutes"),
3006
+ error: tError(errors.lockoutWindowMinutes),
3007
+ required: true,
3008
+ children: /* @__PURE__ */ jsx(
3009
+ NumberInput,
3010
+ {
3011
+ value: settings.lockoutWindowMinutes,
3012
+ onValueChange: (value) => handleChange("lockoutWindowMinutes", value ?? ""),
3013
+ disabled: policyLocked,
3014
+ min: POLICY_RANGES.lockoutWindowMinutes.min,
3015
+ max: POLICY_RANGES.lockoutWindowMinutes.max,
3016
+ step: 1
3017
+ },
3018
+ form.draftVersion
3019
+ )
3020
+ }
3021
+ ),
3022
+ /* @__PURE__ */ jsx(
3023
+ FormField,
3024
+ {
3025
+ id: "lockout-duration",
3026
+ name: "lockoutDurationMinutes",
3027
+ label: t("settings.config.failed.duration.label", "Lock for"),
3028
+ description: t(
3029
+ "settings.config.failed.duration.hint",
3030
+ "A locked IP address or account is refused for this long. Admins can unlock it earlier."
3031
+ ),
3032
+ suffix: t("settings.config.failed.minutes.suffix", "minutes"),
3033
+ error: tError(errors.lockoutDurationMinutes),
3034
+ required: true,
3035
+ children: /* @__PURE__ */ jsx(
3036
+ NumberInput,
3037
+ {
3038
+ value: settings.lockoutDurationMinutes,
3039
+ onValueChange: (value) => handleChange("lockoutDurationMinutes", value ?? ""),
3040
+ disabled: policyLocked,
3041
+ min: POLICY_RANGES.lockoutDurationMinutes.min,
3042
+ max: POLICY_RANGES.lockoutDurationMinutes.max,
3043
+ step: 1
3044
+ },
3045
+ form.draftVersion
3046
+ )
3047
+ }
3048
+ )
3049
+ ] }),
3050
+ !maxFailedError && !errors.maxFailedLoginsPerAccount ? /* @__PURE__ */ jsx(
1992
3051
  Box,
1993
3052
  {
1994
3053
  padding: 3,
1995
- background: maxFailedValue === 0 ? "warning100" : "neutral100",
3054
+ background: maxFailedValue === 0 && accountValue === 0 ? "warning100" : "neutral100",
1996
3055
  hasRadius: true,
1997
3056
  "aria-live": "polite",
1998
3057
  children: /* @__PURE__ */ jsx(
1999
3058
  ReadableParagraphs,
2000
3059
  {
2001
3060
  variant: "pi",
2002
- textColor: maxFailedValue === 0 ? "warning700" : "neutral700",
3061
+ textColor: maxFailedValue === 0 && accountValue === 0 ? "warning700" : "neutral700",
2003
3062
  tag: "p",
2004
- text: maxFailedValue === 0 ? t(
2005
- "settings.config.failed.lockout.off",
2006
- "The temporary IP lockout is off. Failed sign-ins are not limited."
2007
- ) : t(
2008
- "settings.config.failed.lockout.preview",
2009
- "After {count, plural, one {# failed sign-in} other {# failed sign-ins}} from one IP address within 15 minutes, that address is refused for 15 minutes. User accounts are not blocked. Counted per server process.",
2010
- { count: maxFailedValue }
2011
- )
3063
+ text: lockoutPreview
2012
3064
  }
2013
3065
  )
2014
3066
  }
2015
- ) : null
3067
+ ) : null,
3068
+ /* @__PURE__ */ jsx(
3069
+ SettingsToggleRow,
3070
+ {
3071
+ id: "lockout-notify-user",
3072
+ title: t(
3073
+ "settings.config.failed.notify.label",
3074
+ "Email the user when their account is locked"
3075
+ ),
3076
+ description: t(
3077
+ "settings.config.failed.notify.hint",
3078
+ "Sent through Strapi's email plugin (and Magic Mail when installed). The text is in Alerts, Email templates."
3079
+ ),
3080
+ checked: !!settings.lockoutNotifyUser,
3081
+ disabled: policyLocked || accountValue === 0 && !accountByRole,
3082
+ onChange: (checked) => handleChange("lockoutNotifyUser", checked)
3083
+ }
3084
+ ),
3085
+ /* @__PURE__ */ jsx(
3086
+ SettingsToggleRow,
3087
+ {
3088
+ id: "record-user-sign-in-events",
3089
+ title: t("settings.config.failed.record.label", "Record failed and refused sign-ins"),
3090
+ description: t(
3091
+ "settings.config.failed.record.hint",
3092
+ "Writes failed sign-ins, refused sign-ins and locks to the security log, with the IP address as the log stores it."
3093
+ ),
3094
+ checked: settings.recordUserSignInEvents !== false,
3095
+ disabled: policyLocked,
3096
+ onChange: (checked) => handleChange("recordUserSignInEvents", checked)
3097
+ }
3098
+ ),
3099
+ /* @__PURE__ */ jsx(
3100
+ AdvancedSection,
3101
+ {
3102
+ label: t("settings.config.failed.trusted.section", "Trusted addresses"),
3103
+ hasError: fieldHasError(errors, "lockoutTrustedAddresses"),
3104
+ children: /* @__PURE__ */ jsx(TrustedAddressesField, { form, disabled: policyLocked })
3105
+ }
3106
+ )
2016
3107
  ]
2017
3108
  }
2018
3109
  ),
3110
+ /* @__PURE__ */ jsx(LockedNowCard, {}),
2019
3111
  /* @__PURE__ */ jsx(
2020
3112
  SectionCard,
2021
3113
  {
@@ -2149,7 +3241,18 @@ const LoginProtectionTab = ({ form }) => {
2149
3241
  {
2150
3242
  id: "lockout",
2151
3243
  term: t("settings.config.refused.lockout.response", "429 with Retry-After"),
2152
- description: t("settings.config.refused.lockout.cause", "Temporary IP lockout")
3244
+ description: t(
3245
+ "settings.config.refused.lockout.cause",
3246
+ "Locked IP address or account after failed sign-ins"
3247
+ )
3248
+ },
3249
+ {
3250
+ id: "limit",
3251
+ term: t("settings.config.refused.limit.response", "403 SESSION_LIMIT_REACHED"),
3252
+ description: t(
3253
+ "settings.config.refused.limit.cause",
3254
+ 'Session limit reached with "Refuse the new sign-in"'
3255
+ )
2153
3256
  },
2154
3257
  {
2155
3258
  id: "rule",
@@ -2173,7 +3276,10 @@ const LoginProtectionTab = ({ form }) => {
2173
3276
  ]
2174
3277
  }
2175
3278
  ),
2176
- /* @__PURE__ */ jsx(ReadableText, { variant: "pi", textColor: "neutral600", tag: "p", children: t("settings.config.refused.noLog", "Session Manager keeps no log of refused sign-ins.") })
3279
+ /* @__PURE__ */ jsx(ReadableText, { variant: "pi", textColor: "neutral600", tag: "p", children: t(
3280
+ "settings.config.refused.log",
3281
+ 'Refused sign-ins are written to the security log while "Record failed and refused sign-ins" is on.'
3282
+ ) })
2177
3283
  ] })
2178
3284
  ] });
2179
3285
  };
@@ -2725,7 +3831,8 @@ const PreviewFrame = styled.iframe`
2725
3831
  const TEMPLATE_TAB_LABELS = {
2726
3832
  suspiciousLogin: ["settings.email.templates.tab.suspicious", "Suspicious sign-in"],
2727
3833
  newLocation: ["settings.email.templates.tab.newLocation", "New country"],
2728
- vpnProxy: ["settings.email.templates.tab.vpnProxy", "VPN or proxy"]
3834
+ vpnProxy: ["settings.email.templates.tab.vpnProxy", "VPN or proxy"],
3835
+ accountLocked: ["settings.email.templates.tab.accountLocked", "Account locked"]
2729
3836
  };
2730
3837
  const BlockLabel = ({ children }) => /* @__PURE__ */ jsx(Typography, { variant: "omega", fontWeight: "bold", tag: "div", textColor: "neutral800", children });
2731
3838
  const TemplateEditor = ({ templateKey, template, templates, handleChange, copyValue, errors }) => {