strapi-plugin-magic-sessionmanager 4.17.0 → 4.19.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 (29) hide show
  1. package/CHANGELOG.md +59 -0
  2. package/README.md +115 -53
  3. package/dist/admin/{Analytics-BTIByTUY.js → Analytics-AzG-hPvn.js} +1 -1
  4. package/dist/admin/{Analytics-B-p2Q7th.mjs → Analytics-DSXe9BPn.mjs} +1 -1
  5. package/dist/admin/{App-DmesuM2g.mjs → App-7UDfLwMK.mjs} +1132 -163
  6. package/dist/admin/{App-CH6635JB.js → App-D08oGxy4.js} +1129 -160
  7. package/dist/admin/{OnlineUsersWidget-TlOp8nie.js → OnlineUsersWidget-CK0_o7Jk.js} +1 -1
  8. package/dist/admin/{OnlineUsersWidget-CuqeQ0tb.mjs → OnlineUsersWidget-DIhJZ77w.mjs} +1 -1
  9. package/dist/admin/{Settings-C4IgGBjQ.mjs → Settings-CneNJppG.mjs} +866 -38
  10. package/dist/admin/{Settings-DtP_H4JS.js → Settings-DnNBDP1I.js} +866 -38
  11. package/dist/admin/{dashboardModel-BSJhZdXI.js → dashboardModel-CjU0V7Sx.js} +1 -1
  12. package/dist/admin/{dashboardModel-0ROcWcB1.mjs → dashboardModel-OyQ_39aF.mjs} +1 -1
  13. package/dist/admin/{de-C_ooq6EF.js → de-CJZtJdhC.js} +151 -6
  14. package/dist/admin/{de-BoahnYIP.mjs → de-DvYUwhjB.mjs} +151 -6
  15. package/dist/admin/{en-DHme92L-.mjs → en-B8m9k-qd.mjs} +151 -6
  16. package/dist/admin/{en-CuUVE2K0.js → en-BZ2YkNIU.js} +151 -6
  17. package/dist/admin/{es-lbDNXcQi.js → es-BBsMtof1.js} +151 -6
  18. package/dist/admin/{es-CjcTgS9Z.mjs → es-DBH36rrX.mjs} +151 -6
  19. package/dist/admin/{fr-BPwnrSaC.mjs → fr-CLvB1rGe.mjs} +151 -6
  20. package/dist/admin/{fr-RtypjgGp.js → fr-Cw6nc38j.js} +151 -6
  21. package/dist/admin/{index-B102RF2H.mjs → index-5Zb3GVml.mjs} +9 -9
  22. package/dist/admin/{index-w0OuPYFm.js → index-BSUrdxxt.js} +9 -9
  23. package/dist/admin/index.js +1 -1
  24. package/dist/admin/index.mjs +1 -1
  25. package/dist/admin/{pt-D5FHSP2y.mjs → pt-CVht14if.mjs} +151 -6
  26. package/dist/admin/{pt-BMCAKRQ4.js → pt-CjnMe7Z-.js} +151 -6
  27. package/dist/server/index.js +1725 -32
  28. package/dist/server/index.mjs +1725 -32
  29. package/package.json +1 -1
@@ -4,10 +4,10 @@ import { Field, Typography, Switch, Box, TextInput, Flex, Button, Link, SingleSe
4
4
  import { useFetchClient, useNotification, useRBAC, ConfirmDialog, useQueryParams, Page, Form, Blocker, useForm } from "@strapi/strapi/admin";
5
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 { 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";
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-5Zb3GVml.mjs";
8
8
  import { useIntl } from "react-intl";
9
9
  import { S as SectionCard } from "./SectionCard-D51bv4Hi.mjs";
10
- import { u as useElementWidth, b as RowActions, s as shouldIsolateActionKey, o as getRiskAvailability, q as riskDependentControl } from "./dashboardModel-0ROcWcB1.mjs";
10
+ import { u as useElementWidth, b as RowActions, s as shouldIsolateActionKey, o as getRiskAvailability, q as riskDependentControl } from "./dashboardModel-OyQ_39aF.mjs";
11
11
  import { EmptyPermissions } from "@strapi/icons/symbols";
12
12
  const SETTINGS_TAB_IDS = Object.freeze([
13
13
  "sessions",
@@ -49,6 +49,10 @@ const SETTINGS_TAB_FIELDS = Object.freeze({
49
49
  "lockoutTrustedAddresses",
50
50
  "lockoutNotifyUser",
51
51
  "recordUserSignInEvents",
52
+ "impossibleTravelEnabled",
53
+ "impossibleTravelSpeedKmh",
54
+ "impossibleTravelMinDistanceKm",
55
+ "impossibleTravelAction",
52
56
  "trustedProxies",
53
57
  "blockSuspiciousSessions",
54
58
  "geoLookupFailureMode",
@@ -70,9 +74,15 @@ const SETTINGS_TAB_FIELDS = Object.freeze({
70
74
  "emailTemplates",
71
75
  "enableWebhooks",
72
76
  "discordWebhookUrl",
73
- "slackWebhookUrl"
77
+ "slackWebhookUrl",
78
+ "alertOnNewDevice",
79
+ "alertOnImpossibleTravel",
80
+ "webhookEvents",
81
+ "genericWebhookEnabled",
82
+ "genericWebhookUrl",
83
+ "genericWebhookSecret"
74
84
  ],
75
- "data-retention": ["retentionDays"],
85
+ "data-retention": ["retentionDays", "sessionIpAnonymize"],
76
86
  "admin-activity": [
77
87
  "adminSignInHistory",
78
88
  "adminContentActivity",
@@ -118,6 +128,17 @@ const SETTINGS_FIELD_LABELS = Object.freeze({
118
128
  "End other sessions after a password change"
119
129
  ],
120
130
  roleRules: ["settings.roleRules.title", "Different rules for some roles"],
131
+ impossibleTravelEnabled: ["settings.config.travel.enable.label", "Detect impossible travel"],
132
+ impossibleTravelSpeedKmh: ["settings.config.travel.speed.label", "Faster than"],
133
+ impossibleTravelMinDistanceKm: ["settings.config.travel.distance.label", "Over at least"],
134
+ impossibleTravelAction: ["settings.config.travel.action.label", "Then"],
135
+ alertOnNewDevice: ["settings.config.email.newDevice.label", "Sign-in from a new device"],
136
+ alertOnImpossibleTravel: ["settings.config.email.travel.label", "Impossible travel"],
137
+ webhookEvents: ["settings.webhookEvents.title", "Events to send"],
138
+ genericWebhookEnabled: ["settings.signedWebhook.enable.label", "Send to the signed webhook"],
139
+ genericWebhookUrl: ["settings.signedWebhook.url.label", "Webhook URL"],
140
+ genericWebhookSecret: ["settings.signedWebhook.secret.label", "Signing secret"],
141
+ sessionIpAnonymize: ["settings.config.privacy.shortIp.label", "Shorten IP addresses of sessions"],
121
142
  trustedProxies: ["settings.config.clientIp.trustProxy.label", "Trust proxy headers"],
122
143
  blockSuspiciousSessions: [
123
144
  "settings.config.suspicious.reject.label",
@@ -788,14 +809,14 @@ const ROLE_RULE_RANGES = Object.freeze({
788
809
  });
789
810
  const ROLE_RULE_FIELDS = Object.freeze(Object.keys(ROLE_RULE_RANGES));
790
811
  const MAX_TRUSTED_ADDRESSES = 100;
791
- const message$1 = (messageId, defaultMessage, values) => ({ messageId, defaultMessage, values });
812
+ const message$2 = (messageId, defaultMessage, values) => ({ messageId, defaultMessage, values });
792
813
  function validateWholeNumber(value, { min, max }) {
793
814
  if (value === void 0 || value === null || value === "") {
794
- return message$1("settings.validation.required", "Enter a value.");
815
+ return message$2("settings.validation.required", "Enter a value.");
795
816
  }
796
817
  const number = Number(value);
797
818
  if (!Number.isInteger(number) || number < min || number > max) {
798
- return message$1("settings.validation.range", "Enter a whole number from {min} to {max}.", {
819
+ return message$2("settings.validation.range", "Enter a whole number from {min} to {max}.", {
799
820
  min,
800
821
  max
801
822
  });
@@ -832,7 +853,7 @@ function validatePolicyFields(settings) {
832
853
  }
833
854
  const entries = Array.isArray(source.lockoutTrustedAddresses) ? source.lockoutTrustedAddresses : [];
834
855
  if (entries.length > MAX_TRUSTED_ADDRESSES) {
835
- errors.lockoutTrustedAddresses = message$1(
856
+ errors.lockoutTrustedAddresses = message$2(
836
857
  "settings.validation.trustedTooMany",
837
858
  "Enter at most {max} addresses.",
838
859
  { max: MAX_TRUSTED_ADDRESSES }
@@ -840,7 +861,7 @@ function validatePolicyFields(settings) {
840
861
  } else {
841
862
  const invalid = entries.find((entry) => !isTrustedAddressLine(entry));
842
863
  if (invalid !== void 0) {
843
- errors.lockoutTrustedAddresses = message$1(
864
+ errors.lockoutTrustedAddresses = message$2(
844
865
  "settings.validation.trustedAddress",
845
866
  '"{value}" is not an IP address or CIDR range. Use for example 192.0.2.10 or 192.0.2.0/24.',
846
867
  { value: String(invalid).slice(0, 64) }
@@ -852,9 +873,9 @@ function validatePolicyFields(settings) {
852
873
  function validateRoleRule(draft, takenRoles = []) {
853
874
  const errors = {};
854
875
  if (!draft?.role) {
855
- errors.role = message$1("settings.roleRules.validation.role", "Choose a role.");
876
+ errors.role = message$2("settings.roleRules.validation.role", "Choose a role.");
856
877
  } else if (takenRoles.includes(draft.role)) {
857
- errors.role = message$1(
878
+ errors.role = message$2(
858
879
  "settings.roleRules.validation.duplicate",
859
880
  "This role already has a rule."
860
881
  );
@@ -868,7 +889,7 @@ function validateRoleRule(draft, takenRoles = []) {
868
889
  else values += 1;
869
890
  }
870
891
  if (values === 0 && !ROLE_RULE_FIELDS.some((field) => errors[field])) {
871
- errors.form = message$1(
892
+ errors.form = message$2(
872
893
  "settings.roleRules.validation.empty",
873
894
  "Set at least one value. Empty fields use the general setting."
874
895
  );
@@ -1602,7 +1623,9 @@ const TEMPLATE_KEYS = Object.freeze([
1602
1623
  "suspiciousLogin",
1603
1624
  "newLocation",
1604
1625
  "vpnProxy",
1605
- "accountLocked"
1626
+ "accountLocked",
1627
+ "newDevice",
1628
+ "impossibleTravel"
1606
1629
  ]);
1607
1630
  const TEMPLATE_LIMITS = Object.freeze({ subject: 200, html: 1e4, text: 5e3 });
1608
1631
  const TEMPLATE_VARIABLE_DEFINITIONS = Object.freeze({
@@ -1661,6 +1684,22 @@ const TEMPLATE_VARIABLE_DEFINITIONS = Object.freeze({
1661
1684
  "{{lock.until}}": {
1662
1685
  messageId: "settings.email.templates.variable.lockUntil",
1663
1686
  defaultMessage: "Time the lock ends (UTC)"
1687
+ },
1688
+ "{{device.browser}}": {
1689
+ messageId: "settings.email.templates.variable.deviceBrowser",
1690
+ defaultMessage: "Browser of the sign-in"
1691
+ },
1692
+ "{{device.os}}": {
1693
+ messageId: "settings.email.templates.variable.deviceOs",
1694
+ defaultMessage: "Operating system of the sign-in"
1695
+ },
1696
+ "{{travel.distanceKm}}": {
1697
+ messageId: "settings.email.templates.variable.travelDistance",
1698
+ defaultMessage: "Distance from the previous sign-in in km"
1699
+ },
1700
+ "{{link.notMe}}": {
1701
+ messageId: "settings.email.templates.variable.notMe",
1702
+ defaultMessage: "“This wasn’t me” link (works once, 72 hours)"
1664
1703
  }
1665
1704
  });
1666
1705
  const TEMPLATE_VARIABLES = Object.freeze({
@@ -1699,7 +1738,29 @@ const TEMPLATE_VARIABLES = Object.freeze({
1699
1738
  "{{reason.isVpn}}",
1700
1739
  "{{reason.isProxy}}"
1701
1740
  ],
1702
- accountLocked: ["{{user.email}}", "{{user.username}}", "{{lock.minutes}}", "{{lock.until}}"]
1741
+ accountLocked: ["{{user.email}}", "{{user.username}}", "{{lock.minutes}}", "{{lock.until}}"],
1742
+ newDevice: [
1743
+ "{{user.email}}",
1744
+ "{{user.username}}",
1745
+ "{{session.loginTime}}",
1746
+ "{{session.ipAddress}}",
1747
+ "{{geo.city}}",
1748
+ "{{geo.country}}",
1749
+ "{{device.browser}}",
1750
+ "{{device.os}}",
1751
+ "{{link.notMe}}"
1752
+ ],
1753
+ impossibleTravel: [
1754
+ "{{user.email}}",
1755
+ "{{user.username}}",
1756
+ "{{session.loginTime}}",
1757
+ "{{geo.city}}",
1758
+ "{{geo.country}}",
1759
+ "{{device.browser}}",
1760
+ "{{device.os}}",
1761
+ "{{travel.distanceKm}}",
1762
+ "{{link.notMe}}"
1763
+ ]
1703
1764
  });
1704
1765
  const TEMPLATE_PREVIEW_VALUES = Object.freeze({
1705
1766
  "{{user.email}}": "jane.doe@example.com",
@@ -1715,7 +1776,11 @@ const TEMPLATE_PREVIEW_VALUES = Object.freeze({
1715
1776
  "{{reason.isThreat}}": "false",
1716
1777
  "{{reason.securityScore}}": "35",
1717
1778
  "{{lock.minutes}}": "15",
1718
- "{{lock.until}}": "Fri, 06 Nov 2026 09:56:00 GMT"
1779
+ "{{lock.until}}": "Fri, 06 Nov 2026 09:56:00 GMT",
1780
+ "{{device.browser}}": "Firefox",
1781
+ "{{device.os}}": "macOS",
1782
+ "{{travel.distanceKm}}": "16032",
1783
+ "{{link.notMe}}": "https://app.example.com/api/magic-sessionmanager/not-me?token=preview"
1719
1784
  });
1720
1785
  function updateEmailTemplate(templates, templateKey, field, value) {
1721
1786
  return { ...templates, [templateKey]: { ...templates[templateKey], [field]: value } };
@@ -1998,6 +2063,75 @@ Hello {{user.username}},
1998
2063
  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
2064
 
2000
2065
  If these attempts were not yours, change your password after the lock ends.`
2066
+ },
2067
+ newDevice: {
2068
+ subject: "New sign-in to your account",
2069
+ html: `<html>
2070
+ <body style="font-family: Arial, sans-serif; line-height: 1.6; color: #333;">
2071
+ <div style="max-width: 600px; margin: 0 auto; padding: 20px;">
2072
+ <h2>New sign-in to your account</h2>
2073
+ <p>Hello {{user.username}},</p>
2074
+ <p>Your account was just used on a device we have not seen before.</p>
2075
+ <ul>
2076
+ <li>Time: {{session.loginTime}}</li>
2077
+ <li>Device: {{device.browser}} on {{device.os}}</li>
2078
+ <li>Location: {{geo.city}}, {{geo.country}}</li>
2079
+ <li>IP address: {{session.ipAddress}}</li>
2080
+ </ul>
2081
+ <p>If this was you, you can ignore this email.</p>
2082
+ <p>If this was not you, <a href="{{link.notMe}}">sign this device out</a> and change your password.</p>
2083
+ <p style="color: #666; font-size: 12px;">The link works once and expires after 72 hours.</p>
2084
+ </div>
2085
+ </body>
2086
+ </html>`,
2087
+ text: `New sign-in to your account
2088
+
2089
+ Hello {{user.username}},
2090
+
2091
+ Your account was just used on a device we have not seen before.
2092
+
2093
+ Time: {{session.loginTime}}
2094
+ Device: {{device.browser}} on {{device.os}}
2095
+ Location: {{geo.city}}, {{geo.country}}
2096
+ IP address: {{session.ipAddress}}
2097
+
2098
+ If this was not you, sign this device out and change your password:
2099
+ {{link.notMe}}
2100
+
2101
+ The link works once and expires after 72 hours.`
2102
+ },
2103
+ impossibleTravel: {
2104
+ subject: "Unusual sign-in to your account",
2105
+ html: `<html>
2106
+ <body style="font-family: Arial, sans-serif; line-height: 1.6; color: #333;">
2107
+ <div style="max-width: 600px; margin: 0 auto; padding: 20px;">
2108
+ <h2>Unusual sign-in to your account</h2>
2109
+ <p>Hello {{user.username}},</p>
2110
+ <p>Your account was used about {{travel.distanceKm}} km away from your previous sign-in, sooner than anyone could travel that far.</p>
2111
+ <ul>
2112
+ <li>Time: {{session.loginTime}}</li>
2113
+ <li>Location: {{geo.city}}, {{geo.country}}</li>
2114
+ <li>Device: {{device.browser}} on {{device.os}}</li>
2115
+ </ul>
2116
+ <p>A VPN or a mobile network can cause this. If this was not you, <a href="{{link.notMe}}">sign this device out</a> and change your password.</p>
2117
+ <p style="color: #666; font-size: 12px;">The link works once and expires after 72 hours.</p>
2118
+ </div>
2119
+ </body>
2120
+ </html>`,
2121
+ text: `Unusual sign-in to your account
2122
+
2123
+ Hello {{user.username}},
2124
+
2125
+ Your account was used about {{travel.distanceKm}} km away from your previous sign-in, sooner than anyone could travel that far.
2126
+
2127
+ Time: {{session.loginTime}}
2128
+ Location: {{geo.city}}, {{geo.country}}
2129
+ Device: {{device.browser}} on {{device.os}}
2130
+
2131
+ A VPN or a mobile network can cause this. If this was not you, sign this device out and change your password:
2132
+ {{link.notMe}}
2133
+
2134
+ The link works once and expires after 72 hours.`
2001
2135
  }
2002
2136
  });
2003
2137
  function fillMissingTemplates(templates) {
@@ -2017,6 +2151,156 @@ function fillMissingTemplates(templates) {
2017
2151
  })
2018
2152
  );
2019
2153
  }
2154
+ const SIGNALS_FORM_DEFAULTS = Object.freeze({
2155
+ alertOnNewDevice: false,
2156
+ alertOnImpossibleTravel: false,
2157
+ impossibleTravelEnabled: false,
2158
+ impossibleTravelSpeedKmh: 1e3,
2159
+ impossibleTravelMinDistanceKm: 500,
2160
+ impossibleTravelAction: "alert",
2161
+ webhookEvents: Object.freeze([
2162
+ "login.suspicious",
2163
+ "login.new_location",
2164
+ "login.new_device",
2165
+ "login.impossible_travel",
2166
+ "lockout",
2167
+ "user.not_me"
2168
+ ]),
2169
+ genericWebhookEnabled: false,
2170
+ // Read-only facts from the server: the URL and the secret are write-only.
2171
+ hasGenericWebhook: false,
2172
+ genericWebhookHint: null,
2173
+ hasGenericWebhookSecret: false,
2174
+ sessionIpAnonymize: false
2175
+ });
2176
+ const WEBHOOK_EVENT_OPTIONS = Object.freeze([
2177
+ ["login.success", "settings.webhookEvents.loginSuccess", "Every successful sign-in"],
2178
+ ["login.suspicious", "settings.webhookEvents.loginSuspicious", "Suspicious sign-in"],
2179
+ ["login.new_location", "settings.webhookEvents.loginNewLocation", "Sign-in from a new country"],
2180
+ ["login.new_device", "settings.webhookEvents.loginNewDevice", "Sign-in from a new device"],
2181
+ ["login.impossible_travel", "settings.webhookEvents.impossibleTravel", "Impossible travel"],
2182
+ ["login.failed", "settings.webhookEvents.loginFailed", "Failed sign-in"],
2183
+ ["login.refused", "settings.webhookEvents.loginRefused", "Refused sign-in"],
2184
+ ["lockout", "settings.webhookEvents.lockout", "IP address or account locked"],
2185
+ ["lockout.lifted", "settings.webhookEvents.lockoutLifted", "Lock lifted by an admin"],
2186
+ ["session.limit", "settings.webhookEvents.sessionLimit", "Session limit reached"],
2187
+ [
2188
+ "password.changed",
2189
+ "settings.webhookEvents.passwordChanged",
2190
+ "Sessions ended after a password change"
2191
+ ],
2192
+ ["user.not_me", "settings.webhookEvents.notMe", `"This wasn't me" used`]
2193
+ ]);
2194
+ const SIGNALS_RANGES = Object.freeze({
2195
+ impossibleTravelSpeedKmh: Object.freeze({ min: 100, max: 5e3 }),
2196
+ impossibleTravelMinDistanceKm: Object.freeze({ min: 50, max: 2e4 })
2197
+ });
2198
+ const RETENTION_PRESETS = Object.freeze({
2199
+ minimal: Object.freeze({ retentionDays: 7, securityLogRetentionDays: 30 }),
2200
+ standard: Object.freeze({ retentionDays: 90, securityLogRetentionDays: 90 }),
2201
+ extended: Object.freeze({ retentionDays: 365, securityLogRetentionDays: 365 })
2202
+ });
2203
+ const message$1 = (messageId, defaultMessage, values) => ({ messageId, defaultMessage, values });
2204
+ function currentRetentionPreset(settings) {
2205
+ const match = Object.entries(RETENTION_PRESETS).find(
2206
+ ([, values]) => Number(settings?.retentionDays) === values.retentionDays && Number(settings?.securityLogRetentionDays) === values.securityLogRetentionDays
2207
+ );
2208
+ return match ? match[0] : "custom";
2209
+ }
2210
+ function isWebhookUrl(value) {
2211
+ if (typeof value !== "string" || value.length > 2048) return false;
2212
+ try {
2213
+ const url = new URL(value.trim());
2214
+ const host = url.hostname.toLowerCase();
2215
+ return url.protocol === "https:" && !url.username && !url.password && !!host && host !== "localhost" && !host.endsWith(".localhost") && !host.endsWith(".local");
2216
+ } catch {
2217
+ return false;
2218
+ }
2219
+ }
2220
+ function validateSignalFields(settings) {
2221
+ const source = settings || {};
2222
+ const errors = {};
2223
+ for (const [key, { min, max }] of Object.entries(SIGNALS_RANGES)) {
2224
+ if (!Object.prototype.hasOwnProperty.call(source, key)) continue;
2225
+ const value = source[key];
2226
+ const number = Number(value);
2227
+ if (value === void 0 || value === null || value === "") {
2228
+ errors[key] = message$1("settings.validation.required", "Enter a value.");
2229
+ } else if (!Number.isInteger(number) || number < min || number > max) {
2230
+ errors[key] = message$1(
2231
+ "settings.validation.range",
2232
+ "Enter a whole number from {min} to {max}.",
2233
+ {
2234
+ min,
2235
+ max
2236
+ }
2237
+ );
2238
+ }
2239
+ }
2240
+ if (typeof source.genericWebhookUrl === "string" && source.genericWebhookUrl && !isWebhookUrl(source.genericWebhookUrl)) {
2241
+ errors.genericWebhookUrl = message$1(
2242
+ "settings.validation.webhookUrl",
2243
+ "Enter an https address without a user name or password, for example https://hooks.example.com/sessions."
2244
+ );
2245
+ }
2246
+ if (typeof source.genericWebhookSecret === "string" && source.genericWebhookSecret && !/^[\x21-\x7e]{32,256}$/.test(source.genericWebhookSecret)) {
2247
+ errors.genericWebhookSecret = message$1(
2248
+ "settings.validation.webhookSecret",
2249
+ "Use 32 to 256 characters without spaces, or generate one."
2250
+ );
2251
+ }
2252
+ return errors;
2253
+ }
2254
+ function generateWebhookSecret(cryptoApi = globalThis.crypto) {
2255
+ const bytes = cryptoApi.getRandomValues(new Uint8Array(48));
2256
+ let binary = "";
2257
+ for (const byte of bytes) binary += String.fromCharCode(byte);
2258
+ return btoa(binary).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
2259
+ }
2260
+ function describeWebhookTest(result) {
2261
+ if (result?.ok) {
2262
+ return {
2263
+ ...message$1("settings.signedWebhook.test.ok", "Delivered. The receiver answered {status}.", {
2264
+ status: result.status
2265
+ }),
2266
+ tone: "success"
2267
+ };
2268
+ }
2269
+ const code = String(result?.code || "network_error");
2270
+ const known = {
2271
+ no_url: ["settings.signedWebhook.test.noUrl", "Save a URL first."],
2272
+ no_secret: ["settings.signedWebhook.test.noSecret", "Save a secret first."],
2273
+ invalid_url: [
2274
+ "settings.signedWebhook.test.invalidUrl",
2275
+ "The saved URL is not a valid https address."
2276
+ ],
2277
+ dns_failed: ["settings.signedWebhook.test.dns", "The host name could not be resolved."],
2278
+ address_not_allowed: [
2279
+ "settings.signedWebhook.test.blocked",
2280
+ "Not sent: the host resolves to a private, local or reserved address."
2281
+ ],
2282
+ timeout: [
2283
+ "settings.signedWebhook.test.timeout",
2284
+ "The receiver did not answer within 5 seconds."
2285
+ ],
2286
+ redirect_not_followed: [
2287
+ "settings.signedWebhook.test.redirect",
2288
+ "The receiver answered with a redirect. Redirects are not followed; use the final URL."
2289
+ ],
2290
+ network_error: ["settings.signedWebhook.test.network", "The connection failed."]
2291
+ };
2292
+ if (known[code]) return { ...message$1(known[code][0], known[code][1]), tone: "danger" };
2293
+ const status = /^http_(\d{3})$/.exec(code);
2294
+ if (status) {
2295
+ return {
2296
+ ...message$1("settings.signedWebhook.test.http", "The receiver answered {status}.", {
2297
+ status: Number(status[1])
2298
+ }),
2299
+ tone: "danger"
2300
+ };
2301
+ }
2302
+ return { ...message$1(known.network_error[0], known.network_error[1]), tone: "danger" };
2303
+ }
2020
2304
  const SETTINGS_DEFAULTS = Object.freeze({
2021
2305
  inactivityTimeout: 15,
2022
2306
  cleanupInterval: 30,
@@ -2055,9 +2339,15 @@ const SETTINGS_DEFAULTS = Object.freeze({
2055
2339
  securityLogAnonymizeIp: false,
2056
2340
  securityLogGeoLookup: false,
2057
2341
  securityLogRetentionDays: 90,
2058
- ...POLICY_FORM_DEFAULTS
2342
+ ...POLICY_FORM_DEFAULTS,
2343
+ ...SIGNALS_FORM_DEFAULTS
2059
2344
  });
2060
- const WRITE_ONLY_SETTINGS_KEYS = Object.freeze(["discordWebhookUrl", "slackWebhookUrl"]);
2345
+ const WRITE_ONLY_SETTINGS_KEYS = Object.freeze([
2346
+ "discordWebhookUrl",
2347
+ "slackWebhookUrl",
2348
+ "genericWebhookUrl",
2349
+ "genericWebhookSecret"
2350
+ ]);
2061
2351
  const MAX_FAILED_LOGINS_RANGE = Object.freeze({ min: 0, max: 100 });
2062
2352
  const WEBHOOK_HOSTS = Object.freeze({
2063
2353
  discordWebhookUrl: ["discord.com", "discordapp.com"],
@@ -2080,6 +2370,7 @@ function normalizeSettings(loaded) {
2080
2370
  blockedCountries: Array.isArray(loaded.blockedCountries) ? loaded.blockedCountries : [],
2081
2371
  lockoutTrustedAddresses: Array.isArray(loaded.lockoutTrustedAddresses) ? loaded.lockoutTrustedAddresses : [],
2082
2372
  roleRules: Array.isArray(loaded.roleRules) ? loaded.roleRules : [],
2373
+ webhookEvents: Array.isArray(loaded.webhookEvents) ? loaded.webhookEvents : [...SIGNALS_FORM_DEFAULTS.webhookEvents],
2083
2374
  emailTemplates: fillMissingTemplates(loaded.emailTemplates)
2084
2375
  };
2085
2376
  }
@@ -2130,6 +2421,7 @@ function validateSettings(settings) {
2130
2421
  const maxFailed = validateMaxFailedLogins(source.maxFailedLogins);
2131
2422
  if (maxFailed) errors.maxFailedLogins = maxFailed;
2132
2423
  Object.assign(errors, validatePolicyFields(source));
2424
+ Object.assign(errors, validateSignalFields(source));
2133
2425
  if (!isAllowedWebhookUrl(source.discordWebhookUrl, WEBHOOK_HOSTS.discordWebhookUrl)) {
2134
2426
  errors.discordWebhookUrl = message(
2135
2427
  "settings.validation.webhookDiscord",
@@ -2479,6 +2771,147 @@ const TrustedAddressesField = ({ form, disabled = false }) => {
2479
2771
  }
2480
2772
  );
2481
2773
  };
2774
+ const ImpossibleTravelCard = ({ form }) => {
2775
+ const { t, tError } = useSettingsTranslate();
2776
+ const { settings, handleChange, errors } = form;
2777
+ const lookupOff = !settings.enableGeolocation;
2778
+ const enabled = settings.impossibleTravelEnabled === true;
2779
+ const locked = form.canChangeProtected === false;
2780
+ return /* @__PURE__ */ jsxs(
2781
+ SectionCard,
2782
+ {
2783
+ id: "impossible-travel",
2784
+ title: t("settings.config.travel.title", "Impossible travel"),
2785
+ subtitle: t(
2786
+ "settings.config.travel.intro",
2787
+ "Flags a sign-in that is farther from the user's previous sign-in than anyone could travel in the time between."
2788
+ ),
2789
+ children: [
2790
+ lookupOff ? /* @__PURE__ */ jsx(RequiresGeolocation, {}) : null,
2791
+ locked ? /* @__PURE__ */ jsx(ProtectedNotice, {}) : null,
2792
+ /* @__PURE__ */ jsx(
2793
+ SettingsToggleRow,
2794
+ {
2795
+ id: "impossible-travel-enabled",
2796
+ title: t("settings.config.travel.enable.label", "Detect impossible travel"),
2797
+ description: t(
2798
+ "settings.config.travel.enable.hint",
2799
+ "Needs a location database with cities (coordinates). While this is on, the location of each sign-in is stored rounded to about 11 km. VPNs and mobile networks can cause false alarms."
2800
+ ),
2801
+ checked: enabled,
2802
+ disabled: locked || lookupOff && !enabled,
2803
+ onChange: (checked) => handleChange("impossibleTravelEnabled", checked)
2804
+ }
2805
+ ),
2806
+ enabled ? /* @__PURE__ */ jsxs(Flex, { direction: "column", alignItems: "stretch", gap: 2, "data-travel-action": "", children: [
2807
+ /* @__PURE__ */ jsx(
2808
+ Typography,
2809
+ {
2810
+ id: "impossible-travel-action-label",
2811
+ variant: "pi",
2812
+ fontWeight: "bold",
2813
+ tag: "div",
2814
+ textColor: "neutral800",
2815
+ children: t("settings.config.travel.action.label", "Then")
2816
+ }
2817
+ ),
2818
+ /* @__PURE__ */ jsxs(
2819
+ Radio.Group,
2820
+ {
2821
+ "aria-labelledby": "impossible-travel-action-label",
2822
+ value: settings.impossibleTravelAction || "alert",
2823
+ disabled: locked,
2824
+ onValueChange: (value) => handleChange("impossibleTravelAction", value),
2825
+ children: [
2826
+ /* @__PURE__ */ jsx(Radio.Item, { value: "alert", children: t("settings.config.travel.action.alert", "Record it and alert") }),
2827
+ /* @__PURE__ */ jsx(Radio.Item, { value: "reauthenticate", children: t("settings.config.travel.action.reauthenticate", "Require a new sign-in") })
2828
+ ]
2829
+ }
2830
+ ),
2831
+ settings.impossibleTravelAction === "reauthenticate" ? /* @__PURE__ */ jsx(
2832
+ Alert,
2833
+ {
2834
+ variant: "warning",
2835
+ closeLabel: t("common.close", "Close"),
2836
+ title: t("settings.config.travel.reauth.title", "Every session of the user ends"),
2837
+ children: t(
2838
+ "settings.config.travel.reauth.body",
2839
+ "The flagged sign-in gets 401 with the code REAUTHENTICATION_REQUIRED and all sessions of the user end. Signing in again from the new place works."
2840
+ )
2841
+ }
2842
+ ) : null,
2843
+ /* @__PURE__ */ jsx(ReadableText, { variant: "pi", textColor: "neutral600", tag: "p", children: t(
2844
+ "settings.config.travel.alerts",
2845
+ "The email to the user and the webhook event are chosen under Alerts."
2846
+ ) })
2847
+ ] }) : null,
2848
+ /* @__PURE__ */ jsx(
2849
+ AdvancedSection,
2850
+ {
2851
+ hasError: fieldHasError(errors, "impossibleTravelSpeedKmh") || fieldHasError(errors, "impossibleTravelMinDistanceKm"),
2852
+ disabled: !enabled,
2853
+ children: /* @__PURE__ */ jsxs(EqualGrid, { columns: 2, stackBelow: "medium", gap: 6, children: [
2854
+ /* @__PURE__ */ jsx(
2855
+ FormField,
2856
+ {
2857
+ id: "impossible-travel-speed",
2858
+ name: "impossibleTravelSpeedKmh",
2859
+ label: t("settings.config.travel.speed.label", "Faster than"),
2860
+ description: t(
2861
+ "settings.config.travel.speed.hint",
2862
+ "From 100 to 5000. A plane flies at about 900 km/h."
2863
+ ),
2864
+ suffix: t("settings.config.travel.speed.suffix", "km/h"),
2865
+ error: tError(errors.impossibleTravelSpeedKmh),
2866
+ required: true,
2867
+ children: /* @__PURE__ */ jsx(
2868
+ NumberInput,
2869
+ {
2870
+ value: settings.impossibleTravelSpeedKmh,
2871
+ disabled: locked,
2872
+ onValueChange: (value) => handleChange("impossibleTravelSpeedKmh", value ?? ""),
2873
+ min: SIGNALS_RANGES.impossibleTravelSpeedKmh.min,
2874
+ max: SIGNALS_RANGES.impossibleTravelSpeedKmh.max,
2875
+ step: 50
2876
+ },
2877
+ form.draftVersion
2878
+ )
2879
+ }
2880
+ ),
2881
+ /* @__PURE__ */ jsx(
2882
+ FormField,
2883
+ {
2884
+ id: "impossible-travel-distance",
2885
+ name: "impossibleTravelMinDistanceKm",
2886
+ label: t("settings.config.travel.distance.label", "Over at least"),
2887
+ description: t(
2888
+ "settings.config.travel.distance.hint",
2889
+ "Shorter distances are never flagged (location data is not precise)."
2890
+ ),
2891
+ suffix: t("settings.config.travel.distance.suffix", "km"),
2892
+ error: tError(errors.impossibleTravelMinDistanceKm),
2893
+ required: true,
2894
+ children: /* @__PURE__ */ jsx(
2895
+ NumberInput,
2896
+ {
2897
+ value: settings.impossibleTravelMinDistanceKm,
2898
+ disabled: locked,
2899
+ onValueChange: (value) => handleChange("impossibleTravelMinDistanceKm", value ?? ""),
2900
+ min: SIGNALS_RANGES.impossibleTravelMinDistanceKm.min,
2901
+ max: SIGNALS_RANGES.impossibleTravelMinDistanceKm.max,
2902
+ step: 50
2903
+ },
2904
+ form.draftVersion
2905
+ )
2906
+ }
2907
+ )
2908
+ ] })
2909
+ }
2910
+ )
2911
+ ]
2912
+ }
2913
+ );
2914
+ };
2482
2915
  const COUNTRIES = [
2483
2916
  { code: "DE", name: "Germany", flag: "🇩🇪" },
2484
2917
  { code: "AT", name: "Austria", flag: "🇦🇹" },
@@ -3208,6 +3641,7 @@ const LoginProtectionTab = ({ form }) => {
3208
3641
  ]
3209
3642
  }
3210
3643
  ),
3644
+ /* @__PURE__ */ jsx(ImpossibleTravelCard, { form }),
3211
3645
  /* @__PURE__ */ jsxs(
3212
3646
  SectionCard,
3213
3647
  {
@@ -3832,7 +4266,9 @@ const TEMPLATE_TAB_LABELS = {
3832
4266
  suspiciousLogin: ["settings.email.templates.tab.suspicious", "Suspicious sign-in"],
3833
4267
  newLocation: ["settings.email.templates.tab.newLocation", "New country"],
3834
4268
  vpnProxy: ["settings.email.templates.tab.vpnProxy", "VPN or proxy"],
3835
- accountLocked: ["settings.email.templates.tab.accountLocked", "Account locked"]
4269
+ accountLocked: ["settings.email.templates.tab.accountLocked", "Account locked"],
4270
+ newDevice: ["settings.email.templates.tab.newDevice", "New device"],
4271
+ impossibleTravel: ["settings.email.templates.tab.impossibleTravel", "Impossible travel"]
3836
4272
  };
3837
4273
  const BlockLabel = ({ children }) => /* @__PURE__ */ jsx(Typography, { variant: "omega", fontWeight: "bold", tag: "div", textColor: "neutral800", children });
3838
4274
  const TemplateEditor = ({ templateKey, template, templates, handleChange, copyValue, errors }) => {
@@ -4180,6 +4616,299 @@ const WebhookUrlField = ({
4180
4616
  stored ? /* @__PURE__ */ jsx(Flex, { gap: 2, wrap: "wrap", children: /* @__PURE__ */ jsx(Button, { variant: "tertiary", size: "S", onClick: cancel, children: t("settings.webhooks.cancelReplace", "Keep the saved URL") }) }) : null
4181
4617
  ] }) });
4182
4618
  };
4619
+ const WriteOnlyField = ({
4620
+ field,
4621
+ saved,
4622
+ form,
4623
+ label,
4624
+ hint,
4625
+ type,
4626
+ placeholder,
4627
+ savedHint = null,
4628
+ disabled = false,
4629
+ extra
4630
+ }) => {
4631
+ const { t, tError } = useSettingsTranslate();
4632
+ const { settings, handleChange, errors } = form;
4633
+ const draft = settings[field];
4634
+ const [editing, setEditing] = useState(false);
4635
+ const removing = draft === "";
4636
+ const showInput = editing || !saved || typeof draft === "string" && draft !== "";
4637
+ if (!showInput) {
4638
+ return /* @__PURE__ */ jsx(FormField, { id: `generic-${field}`, name: field, label, description: hint, children: /* @__PURE__ */ jsxs(Flex, { gap: 2, wrap: "wrap", alignItems: "center", children: [
4639
+ /* @__PURE__ */ jsx(Typography, { variant: "omega", textColor: removing ? "danger600" : "neutral800", children: removing ? t("settings.signedWebhook.removed", "Removed when you save.") : t("settings.signedWebhook.saved", "Saved. It is never shown again.") }),
4640
+ savedHint && !removing ? /* @__PURE__ */ jsx(Typography, { variant: "pi", textColor: "neutral600", children: savedHint }) : null,
4641
+ !removing ? /* @__PURE__ */ jsxs(Fragment$1, { children: [
4642
+ /* @__PURE__ */ jsx(
4643
+ Button,
4644
+ {
4645
+ variant: "tertiary",
4646
+ startIcon: /* @__PURE__ */ jsx(Pencil, {}),
4647
+ disabled,
4648
+ onClick: () => setEditing(true),
4649
+ children: t("settings.signedWebhook.replace", "Replace")
4650
+ }
4651
+ ),
4652
+ /* @__PURE__ */ jsx(
4653
+ Button,
4654
+ {
4655
+ variant: "danger-light",
4656
+ startIcon: /* @__PURE__ */ jsx(Trash, {}),
4657
+ disabled,
4658
+ onClick: () => handleChange(field, ""),
4659
+ children: t("settings.signedWebhook.remove", "Remove")
4660
+ }
4661
+ )
4662
+ ] }) : /* @__PURE__ */ jsx(
4663
+ Button,
4664
+ {
4665
+ variant: "tertiary",
4666
+ disabled,
4667
+ onClick: () => handleChange(field, void 0),
4668
+ children: t("settings.signedWebhook.keep", "Keep it")
4669
+ }
4670
+ )
4671
+ ] }) });
4672
+ }
4673
+ return /* @__PURE__ */ jsx(
4674
+ FormField,
4675
+ {
4676
+ id: `generic-${field}`,
4677
+ name: field,
4678
+ label,
4679
+ description: hint,
4680
+ error: tError(errors[field]),
4681
+ children: /* @__PURE__ */ jsxs(Flex, { direction: "column", alignItems: "stretch", gap: 2, children: [
4682
+ /* @__PURE__ */ jsx(
4683
+ TextInput,
4684
+ {
4685
+ type,
4686
+ value: typeof draft === "string" ? draft : "",
4687
+ placeholder,
4688
+ disabled,
4689
+ autoComplete: "off",
4690
+ spellCheck: false,
4691
+ onChange: (event) => handleChange(field, event.target.value || void 0)
4692
+ }
4693
+ ),
4694
+ extra || saved ? /* @__PURE__ */ jsxs(Flex, { gap: 2, wrap: "wrap", children: [
4695
+ extra,
4696
+ saved ? /* @__PURE__ */ jsx(
4697
+ Button,
4698
+ {
4699
+ variant: "tertiary",
4700
+ onClick: () => {
4701
+ handleChange(field, void 0);
4702
+ setEditing(false);
4703
+ },
4704
+ children: t("settings.signedWebhook.keepSaved", "Keep the saved value")
4705
+ }
4706
+ ) : null
4707
+ ] }) : null
4708
+ ] })
4709
+ }
4710
+ );
4711
+ };
4712
+ const SignedWebhookCard = ({ form }) => {
4713
+ const { t } = useSettingsTranslate();
4714
+ const { post } = useFetchClient();
4715
+ const { settings, handleChange } = form;
4716
+ const [testing, setTesting] = useState(false);
4717
+ const [result, setResult] = useState(null);
4718
+ const locked = form.canChangeProtected === false;
4719
+ const pendingWriteOnly = settings.genericWebhookUrl !== void 0 || settings.genericWebhookSecret !== void 0;
4720
+ const sendTest = async () => {
4721
+ setTesting(true);
4722
+ setResult(null);
4723
+ try {
4724
+ const { data } = await post(`/${pluginId}/webhook/test`, {});
4725
+ setResult(describeWebhookTest(data?.data));
4726
+ } catch (err) {
4727
+ logSafeAdminError("webhook-test", err);
4728
+ setResult({
4729
+ messageId: "settings.signedWebhook.test.failed",
4730
+ defaultMessage: "The test could not be started.",
4731
+ tone: "danger"
4732
+ });
4733
+ } finally {
4734
+ setTesting(false);
4735
+ }
4736
+ };
4737
+ return /* @__PURE__ */ jsxs(
4738
+ SectionCard,
4739
+ {
4740
+ id: "signed-webhook",
4741
+ title: t("settings.signedWebhook.title", "Signed webhook"),
4742
+ subtitle: t(
4743
+ "settings.signedWebhook.intro",
4744
+ "Sends the selected events as signed JSON to your own endpoint, for example a SIEM. Only https; private and local addresses are refused, redirects are not followed."
4745
+ ),
4746
+ children: [
4747
+ /* @__PURE__ */ jsx(
4748
+ SettingsToggleRow,
4749
+ {
4750
+ id: "generic-webhook-enabled",
4751
+ title: t("settings.signedWebhook.enable.label", "Send to the signed webhook"),
4752
+ description: t(
4753
+ "settings.signedWebhook.enable.hint",
4754
+ "Failed deliveries are retried twice (after 2 and 10 seconds). Data sent: user documentId, IP as the security log stores it, browser, country and city, and the event details. No email addresses."
4755
+ ),
4756
+ checked: settings.genericWebhookEnabled === true,
4757
+ disabled: locked,
4758
+ onChange: (checked) => handleChange("genericWebhookEnabled", checked)
4759
+ }
4760
+ ),
4761
+ locked ? /* @__PURE__ */ jsx(ProtectedNotice, {}) : null,
4762
+ /* @__PURE__ */ jsxs(EqualGrid, { columns: 2, stackBelow: "medium", gap: 6, children: [
4763
+ /* @__PURE__ */ jsx(
4764
+ WriteOnlyField,
4765
+ {
4766
+ field: "genericWebhookUrl",
4767
+ saved: settings.hasGenericWebhook === true,
4768
+ savedHint: settings.genericWebhookHint,
4769
+ disabled: locked,
4770
+ form,
4771
+ type: "url",
4772
+ label: t("settings.signedWebhook.url.label", "Webhook URL"),
4773
+ hint: t(
4774
+ "settings.signedWebhook.url.hint",
4775
+ "https only. Treat it like a password: it may contain a token."
4776
+ ),
4777
+ placeholder: "https://hooks.example.com/sessions"
4778
+ }
4779
+ ),
4780
+ /* @__PURE__ */ jsx(
4781
+ WriteOnlyField,
4782
+ {
4783
+ field: "genericWebhookSecret",
4784
+ saved: settings.hasGenericWebhookSecret === true,
4785
+ disabled: locked,
4786
+ form,
4787
+ type: "text",
4788
+ label: t("settings.signedWebhook.secret.label", "Signing secret"),
4789
+ hint: t(
4790
+ "settings.signedWebhook.secret.hint",
4791
+ "Your endpoint uses it to verify the signature. Copy it before you save: it is never shown again."
4792
+ ),
4793
+ extra: /* @__PURE__ */ jsxs(Fragment$1, { children: [
4794
+ /* @__PURE__ */ jsx(
4795
+ Button,
4796
+ {
4797
+ variant: "secondary",
4798
+ startIcon: /* @__PURE__ */ jsx(Key, {}),
4799
+ disabled: locked,
4800
+ onClick: () => handleChange("genericWebhookSecret", generateWebhookSecret()),
4801
+ children: t("settings.signedWebhook.generate", "Generate")
4802
+ }
4803
+ ),
4804
+ typeof settings.genericWebhookSecret === "string" && settings.genericWebhookSecret ? /* @__PURE__ */ jsx(
4805
+ Button,
4806
+ {
4807
+ variant: "tertiary",
4808
+ onClick: () => form.copyValue(
4809
+ settings.genericWebhookSecret,
4810
+ t("settings.signedWebhook.copied", "Secret copied."),
4811
+ "webhook-secret"
4812
+ ),
4813
+ children: t("settings.signedWebhook.copy", "Copy")
4814
+ }
4815
+ ) : null
4816
+ ] })
4817
+ }
4818
+ )
4819
+ ] }),
4820
+ /* @__PURE__ */ jsxs(Flex, { direction: "column", alignItems: "flex-start", gap: 2, children: [
4821
+ /* @__PURE__ */ jsx(
4822
+ Button,
4823
+ {
4824
+ variant: "secondary",
4825
+ startIcon: /* @__PURE__ */ jsx(Check, {}),
4826
+ loading: testing,
4827
+ disabled: locked || pendingWriteOnly || !settings.hasGenericWebhook,
4828
+ onClick: sendTest,
4829
+ children: t("settings.signedWebhook.test.action", "Send test")
4830
+ }
4831
+ ),
4832
+ pendingWriteOnly ? /* @__PURE__ */ jsx(ReadableText, { variant: "pi", textColor: "neutral600", tag: "p", children: t(
4833
+ "settings.signedWebhook.test.saveFirst",
4834
+ "Save first: the test uses the saved URL and secret."
4835
+ ) }) : null,
4836
+ /* @__PURE__ */ jsx(Box, { "aria-live": "polite", "data-webhook-test-result": "", children: result ? /* @__PURE__ */ jsx(
4837
+ Typography,
4838
+ {
4839
+ variant: "pi",
4840
+ textColor: result.tone === "success" ? "success600" : "danger600",
4841
+ children: t(result.messageId, result.defaultMessage, result.values)
4842
+ }
4843
+ ) : null })
4844
+ ] })
4845
+ ]
4846
+ }
4847
+ );
4848
+ };
4849
+ const EventGrid = styled.div`
4850
+ container-type: inline-size;
4851
+ min-width: 0;
4852
+
4853
+ & > ul {
4854
+ display: grid;
4855
+ grid-template-columns: minmax(0, 1fr);
4856
+ gap: ${({ theme }) => theme.spaces[3]};
4857
+ align-items: center;
4858
+ margin: 0;
4859
+ padding: 0;
4860
+ list-style: none;
4861
+ }
4862
+
4863
+ /* Every item starts on the row line (an inherited li + li margin
4864
+ offset the second column). */
4865
+ & > ul > li {
4866
+ margin: 0;
4867
+ }
4868
+
4869
+ @container (min-width: 520px) {
4870
+ & > ul {
4871
+ grid-template-columns: repeat(2, minmax(0, 1fr));
4872
+ }
4873
+ }
4874
+ `;
4875
+ const WebhookEventsCard = ({ form }) => {
4876
+ const { t } = useSettingsTranslate();
4877
+ const { settings, handleChange } = form;
4878
+ const locked = form.canChangeProtected === false;
4879
+ const selected = Array.isArray(settings.webhookEvents) ? settings.webhookEvents : [];
4880
+ const toggle = (event, checked) => {
4881
+ const next = checked ? [.../* @__PURE__ */ new Set([...selected, event])] : selected.filter((value) => value !== event);
4882
+ handleChange(
4883
+ "webhookEvents",
4884
+ WEBHOOK_EVENT_OPTIONS.map(([value]) => value).filter((value) => next.includes(value))
4885
+ );
4886
+ };
4887
+ return /* @__PURE__ */ jsxs(
4888
+ SectionCard,
4889
+ {
4890
+ id: "webhook-events",
4891
+ title: t("settings.webhookEvents.title", "Events to send"),
4892
+ subtitle: t(
4893
+ "settings.webhookEvents.intro",
4894
+ "Applies to Discord, Slack and the signed webhook. Every successful sign-in is usually too much; choose the events your team acts on."
4895
+ ),
4896
+ children: [
4897
+ locked ? /* @__PURE__ */ jsx(ProtectedNotice, {}) : null,
4898
+ /* @__PURE__ */ jsx(EventGrid, { children: /* @__PURE__ */ jsx("ul", { "aria-label": t("settings.webhookEvents.title", "Events to send"), children: WEBHOOK_EVENT_OPTIONS.map(([event, id, label]) => /* @__PURE__ */ jsx("li", { children: /* @__PURE__ */ jsx(Flex, { alignItems: "center", minWidth: 0, children: /* @__PURE__ */ jsx(
4899
+ Checkbox,
4900
+ {
4901
+ checked: selected.includes(event),
4902
+ disabled: locked,
4903
+ onCheckedChange: (checked) => toggle(event, checked === true),
4904
+ "data-webhook-event": event,
4905
+ children: t(id, label)
4906
+ }
4907
+ ) }) }, event)) }) })
4908
+ ]
4909
+ }
4910
+ );
4911
+ };
4183
4912
  const WEBHOOK_EVENTS = Object.freeze({
4184
4913
  suspicious: "login.suspicious",
4185
4914
  newLocation: "login.new_location",
@@ -4215,7 +4944,13 @@ const AlertTypeCell = ({ checked, disabled, children }) => /* @__PURE__ */ jsx(
4215
4944
  const AlertsTab = ({ form }) => {
4216
4945
  const { t, tError } = useSettingsTranslate();
4217
4946
  const { settings, handleChange, errors } = form;
4218
- const hintIds = { suspicious: useId(), newCountry: useId(), vpnProxy: useId() };
4947
+ const hintIds = {
4948
+ suspicious: useId(),
4949
+ newCountry: useId(),
4950
+ vpnProxy: useId(),
4951
+ newDevice: useId(),
4952
+ travel: useId()
4953
+ };
4219
4954
  const lookupOff = !settings.enableGeolocation;
4220
4955
  const emailTypesDisabled = lookupOff || !settings.enableEmailAlerts;
4221
4956
  const webhookFieldsDisabled = lookupOff || !settings.enableWebhooks;
@@ -4251,6 +4986,25 @@ const AlertsTab = ({ form }) => {
4251
4986
  "settings.config.email.vpnProxy.hint",
4252
4987
  "Sign-in from a VPN, or from a public or residential proxy."
4253
4988
  )
4989
+ },
4990
+ {
4991
+ field: "alertOnNewDevice",
4992
+ hintId: hintIds.newDevice,
4993
+ label: t("settings.config.email.newDevice.label", "Sign-in from a new device"),
4994
+ hint: t(
4995
+ "settings.config.email.newDevice.hint",
4996
+ `Browser and system not seen in the user's last 50 sessions. With a "This wasn't me" link that signs that device out.`
4997
+ )
4998
+ },
4999
+ {
5000
+ field: "alertOnImpossibleTravel",
5001
+ hintId: hintIds.travel,
5002
+ needsTravel: true,
5003
+ label: t("settings.config.email.travel.label", "Impossible travel"),
5004
+ hint: t(
5005
+ "settings.config.email.travel.hint",
5006
+ `Farther from the previous sign-in than anyone could travel. With a "This wasn't me" link.`
5007
+ )
4254
5008
  }
4255
5009
  ];
4256
5010
  return /* @__PURE__ */ jsxs(Flex, { direction: "column", alignItems: "stretch", gap: 6, children: [
@@ -4288,9 +5042,10 @@ const AlertsTab = ({ form }) => {
4288
5042
  /* @__PURE__ */ jsxs(Flex, { direction: "column", alignItems: "stretch", gap: 3, children: [
4289
5043
  /* @__PURE__ */ jsx(Typography, { variant: "pi", fontWeight: "bold", tag: "div", textColor: "neutral800", children: t("settings.config.email.types.label", "Send an email for") }),
4290
5044
  !lookupOff && !settings.enableEmailAlerts ? /* @__PURE__ */ jsx(RequiresNotice, { children: t("settings.config.requires.emailAlerts", "Requires Send security emails") }) : null,
4291
- /* @__PURE__ */ jsx(EmailTypeGrid, { children: /* @__PURE__ */ jsx("div", { children: emailTypes.map(({ field, needsRiskData, hintId, label, hint }) => {
5045
+ /* @__PURE__ */ jsx(EmailTypeGrid, { children: /* @__PURE__ */ jsx("div", { children: emailTypes.map(({ field, needsRiskData, needsTravel, hintId, label, hint }) => {
4292
5046
  const control = needsRiskData ? riskDependentControl(settings[field], risk.state) : { checked: settings[field], disabled: false, savedOnButInactive: false };
4293
- const disabled = emailTypesDisabled || control.disabled;
5047
+ const travelOff = needsTravel && settings.impossibleTravelEnabled !== true;
5048
+ const disabled = emailTypesDisabled || control.disabled || travelOff;
4294
5049
  return /* @__PURE__ */ jsxs(AlertTypeCell, { checked: control.checked, disabled, children: [
4295
5050
  /* @__PURE__ */ jsx(
4296
5051
  Checkbox,
@@ -4303,7 +5058,8 @@ const AlertsTab = ({ form }) => {
4303
5058
  }
4304
5059
  ),
4305
5060
  /* @__PURE__ */ jsx(ReadableText, { id: hintId, variant: "pi", textColor: "neutral600", tag: "p", children: hint }),
4306
- !lookupOff && control.disabled ? /* @__PURE__ */ jsx(RiskSourceNotice, { savedOn: control.savedOnButInactive }) : null
5061
+ !lookupOff && control.disabled ? /* @__PURE__ */ jsx(RiskSourceNotice, { savedOn: control.savedOnButInactive }) : null,
5062
+ travelOff ? /* @__PURE__ */ jsx(RequiresNotice, { tab: "login-protection", children: t("settings.config.requires.travel", "Requires Detect impossible travel") }) : null
4307
5063
  ] }, field);
4308
5064
  }) }) })
4309
5065
  ] }),
@@ -4331,7 +5087,7 @@ const AlertsTab = ({ form }) => {
4331
5087
  title: t("settings.config.webhooks.title", "Team notifications (webhooks)"),
4332
5088
  subtitle: t(
4333
5089
  "settings.config.webhooks.intro",
4334
- "Posts every sign-in to Discord or Slack as 'suspicious', 'new country' or 'success'."
5090
+ "Posts the selected events to Discord or Slack."
4335
5091
  ),
4336
5092
  children: [
4337
5093
  /* @__PURE__ */ jsx(
@@ -4341,7 +5097,7 @@ const AlertsTab = ({ form }) => {
4341
5097
  title: t("settings.config.webhooks.enable.label", "Send team notifications"),
4342
5098
  description: t(
4343
5099
  "settings.config.webhooks.enable.hint",
4344
- "Event per sign-in: {suspicious}, otherwise {newLocation}, otherwise {success}.",
5100
+ "A sign-in is sent as {suspicious}, otherwise {newLocation}, otherwise {success}, when that event is selected below.",
4345
5101
  WEBHOOK_EVENTS
4346
5102
  ),
4347
5103
  checked: settings.enableWebhooks,
@@ -4404,7 +5160,9 @@ const AlertsTab = ({ form }) => {
4404
5160
  ] })
4405
5161
  ]
4406
5162
  }
4407
- )
5163
+ ),
5164
+ /* @__PURE__ */ jsx(WebhookEventsCard, { form }),
5165
+ /* @__PURE__ */ jsx(SignedWebhookCard, { form })
4408
5166
  ] });
4409
5167
  };
4410
5168
  const DangerButton = styled(Button)`
@@ -4415,27 +5173,97 @@ const DataRetentionTab = ({ form }) => {
4415
5173
  const { t } = useSettingsTranslate();
4416
5174
  const units = useOptionLabels();
4417
5175
  const { settings, handleChange, handleCleanInactive } = form;
5176
+ const {
5177
+ allowedActions: { canRead: canReadLog }
5178
+ } = useRBAC(pluginPermissions.adminActivityRead);
5179
+ const locked = form.canChangeProtected === false;
5180
+ const canChangeLogRetention = canReadLog && !locked;
5181
+ const preset = currentRetentionPreset(settings);
5182
+ const applyPreset = (key) => {
5183
+ const values = RETENTION_PRESETS[key];
5184
+ if (!values) return;
5185
+ handleChange("retentionDays", values.retentionDays);
5186
+ if (canChangeLogRetention) {
5187
+ handleChange("securityLogRetentionDays", values.securityLogRetentionDays);
5188
+ }
5189
+ };
4418
5190
  return /* @__PURE__ */ jsxs(Flex, { direction: "column", alignItems: "stretch", gap: 6, children: [
4419
5191
  /* @__PURE__ */ jsx(IntroText, { children: t(
4420
5192
  "settings.config.retention.intro",
4421
5193
  "Ended sessions stay in the history until they are deleted. The tokens of deleted sessions stay revoked."
4422
5194
  ) }),
4423
- /* @__PURE__ */ jsx(SectionCard, { title: t("settings.config.retention.title", "History retention"), children: /* @__PURE__ */ jsx(EqualGrid, { columns: 2, stackBelow: "medium", gap: 6, children: /* @__PURE__ */ jsx(
4424
- PresetSelect,
5195
+ /* @__PURE__ */ jsx(SectionCard, { title: t("settings.config.retention.title", "History retention"), children: /* @__PURE__ */ jsxs(EqualGrid, { columns: 2, stackBelow: "medium", gap: 6, children: [
5196
+ /* @__PURE__ */ jsx(
5197
+ FormField,
5198
+ {
5199
+ id: "retention-preset",
5200
+ name: "retentionPreset",
5201
+ label: t("settings.config.retention.preset.label", "Retention preset"),
5202
+ description: canChangeLogRetention ? t(
5203
+ "settings.config.retention.preset.hint",
5204
+ "Sets how long ended sessions and security events are kept. You can still change each value."
5205
+ ) : t(
5206
+ "settings.config.retention.preset.hintSessionsOnly",
5207
+ 'Sets how long ended sessions are kept. The security log retention needs "View admin activity" and "Change protected settings".'
5208
+ ),
5209
+ children: /* @__PURE__ */ jsxs(SingleSelect, { value: preset, onChange: (value) => applyPreset(value), children: [
5210
+ /* @__PURE__ */ jsx(SingleSelectOption, { value: "minimal", children: t("settings.config.retention.preset.minimal", "Minimal: 7 days, events 30 days") }),
5211
+ /* @__PURE__ */ jsx(SingleSelectOption, { value: "standard", children: t(
5212
+ "settings.config.retention.preset.standard",
5213
+ "Standard: 90 days, events 90 days"
5214
+ ) }),
5215
+ /* @__PURE__ */ jsx(SingleSelectOption, { value: "extended", children: t(
5216
+ "settings.config.retention.preset.extended",
5217
+ "Extended: 365 days, events 365 days"
5218
+ ) }),
5219
+ /* @__PURE__ */ jsx(SingleSelectOption, { value: "custom", disabled: true, children: t("settings.config.retention.preset.custom", "Custom values") })
5220
+ ] })
5221
+ }
5222
+ ),
5223
+ /* @__PURE__ */ jsx(
5224
+ PresetSelect,
5225
+ {
5226
+ id: "session-retention-period",
5227
+ name: "retentionDays",
5228
+ label: t("settings.config.retention.keep.label", "Keep ended sessions for"),
5229
+ description: t(
5230
+ "settings.config.retention.keep.hint",
5231
+ "Checked once a day, the first time about 24 hours after the server starts. Open sessions are never deleted by retention. 'Forever' keeps them."
5232
+ ),
5233
+ value: settings.retentionDays,
5234
+ presets: SELECT_PRESETS.retentionDays,
5235
+ format: units.retentionDays,
5236
+ onChange: (value) => handleChange("retentionDays", value)
5237
+ }
5238
+ )
5239
+ ] }) }),
5240
+ /* @__PURE__ */ jsxs(
5241
+ SectionCard,
4425
5242
  {
4426
- id: "session-retention-period",
4427
- name: "retentionDays",
4428
- label: t("settings.config.retention.keep.label", "Keep ended sessions for"),
4429
- description: t(
4430
- "settings.config.retention.keep.hint",
4431
- "Checked once a day, the first time about 24 hours after the server starts. Open sessions are never deleted by retention. 'Forever' keeps them."
5243
+ title: t("settings.config.privacy.title", "Privacy"),
5244
+ subtitle: t(
5245
+ "settings.config.privacy.intro",
5246
+ "What Session Manager records about app users. The README has a fact sheet for data protection and works councils."
4432
5247
  ),
4433
- value: settings.retentionDays,
4434
- presets: SELECT_PRESETS.retentionDays,
4435
- format: units.retentionDays,
4436
- onChange: (value) => handleChange("retentionDays", value)
5248
+ children: [
5249
+ /* @__PURE__ */ jsx(
5250
+ SettingsToggleRow,
5251
+ {
5252
+ id: "session-ip-anonymize",
5253
+ title: t("settings.config.privacy.shortIp.label", "Shorten IP addresses of sessions"),
5254
+ description: t(
5255
+ "settings.config.privacy.shortIp.hint",
5256
+ "Stores 203.0.113.0 instead of 203.0.113.42 (IPv6: the first 48 bits) for new sessions. Country rules and lockouts still use the full address while the request runs. Existing sessions are not changed."
5257
+ ),
5258
+ checked: settings.sessionIpAnonymize === true,
5259
+ disabled: locked,
5260
+ onChange: (checked) => handleChange("sessionIpAnonymize", checked)
5261
+ }
5262
+ ),
5263
+ locked ? /* @__PURE__ */ jsx(ProtectedNotice, {}) : null
5264
+ ]
4437
5265
  }
4438
- ) }) }),
5266
+ ),
4439
5267
  /* @__PURE__ */ jsx(
4440
5268
  SectionCard,
4441
5269
  {