strapi-plugin-magic-sessionmanager 4.9.1 → 4.11.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.
- package/CHANGELOG.md +86 -5
- package/README.md +427 -91
- package/dist/admin/{Analytics-lVDnHBYp.js → Analytics-CBHeWeGn.js} +1 -1
- package/dist/admin/{Analytics-dyJmyxO-.mjs → Analytics-D56O8Q6e.mjs} +1 -1
- package/dist/admin/{App-CdgiY_Y7.js → App-D4cBPwB_.js} +2 -3
- package/dist/admin/{App-Cgf_CSjw.mjs → App-EDIkLJdb.mjs} +2 -3
- package/dist/admin/{OnlineUsersWidget-DMPtuIpm.js → OnlineUsersWidget-BF2R2YIy.js} +1 -1
- package/dist/admin/{OnlineUsersWidget-DJC4V1KS.mjs → OnlineUsersWidget-MwUutkKQ.mjs} +1 -1
- package/dist/admin/{Settings-0QsyY7fe.js → Settings-CMzEF8EH.js} +21 -5
- package/dist/admin/{Settings-DgeuUiMF.mjs → Settings-bLMyi0BN.mjs} +20 -4
- package/dist/admin/{de-j0oZH9Pz.mjs → de-CxfuTF6C.mjs} +1 -42
- package/dist/admin/{de-BFKoGEVT.js → de-DVNTHmSo.js} +1 -42
- package/dist/admin/{en-UY4Tb5tE.mjs → en-BcPIlQYL.mjs} +1 -42
- package/dist/admin/{en-s7Ksdkcg.js → en-BuVXIcHA.js} +1 -42
- package/dist/admin/{es-07OGMe_5.js → es-CEteHmBO.js} +1 -42
- package/dist/admin/{es-DGBcZwQy.mjs → es-DxHpaNA1.mjs} +1 -42
- package/dist/admin/{fr-ETj_2UBY.js → fr-BMd2-wW7.js} +1 -42
- package/dist/admin/{fr-B6-DWhGO.mjs → fr-Dw43lHg7.mjs} +1 -42
- package/dist/admin/{index-D-Nr0TCm.js → index-DvNfekoR.js} +9 -19
- package/dist/admin/{index-Ck19e8qw.mjs → index-qa6Qnfkc.mjs} +9 -19
- package/dist/admin/index.js +1 -1
- package/dist/admin/index.mjs +1 -1
- package/dist/admin/{pt-YMRLm9gx.mjs → pt-7jnxDSX-.mjs} +1 -42
- package/dist/admin/{pt-C7PwrQtV.js → pt-BvO63p01.js} +1 -42
- package/dist/server/index.js +1322 -827
- package/dist/server/index.mjs +1322 -827
- package/package.json +32 -13
- package/dist/admin/License-1XUfQty5.js +0 -443
- package/dist/admin/License-C4WSYoqY.mjs +0 -443
- package/dist/admin/maskSensitiveValue-BWcSjow7.js +0 -9
- package/dist/admin/maskSensitiveValue-lLRhN_S7.mjs +0 -10
package/README.md
CHANGED
|
@@ -1,22 +1,26 @@
|
|
|
1
1
|
# Magic Session Manager
|
|
2
2
|
|
|
3
|
-
**See who is signed in to your Strapi app, and
|
|
3
|
+
**See who is signed in to your Strapi 5 app, end any session in one click, and stop password guessing before it reaches your users.**
|
|
4
4
|
|
|
5
|
-
Session Manager records every sign-in
|
|
5
|
+
Magic Session Manager records every sign-in through Users & Permissions as a session. Admins see who is online, end single sessions or all sessions of a user, block accounts and review sign-in history. Your app gets logout routes, a "my devices" list for users, failed-login lockout and optional country rules. It works with Strapi's native refresh-token sessions and with several server processes on one database.
|
|
6
6
|
|
|
7
|
-
Free and open under the MIT license.
|
|
7
|
+
Free and open source under the MIT license. Every feature works without an account, key or activation, and the plugin sends nothing to its author.
|
|
8
8
|
|
|
9
|
-
[](https://www.npmjs.com/package/strapi-plugin-magic-sessionmanager)
|
|
10
|
+
[](https://www.npmjs.com/package/strapi-plugin-magic-sessionmanager)
|
|
11
|
+
[](https://github.com/Schero94/Magic-Sessionmanager/actions/workflows/test.yml)
|
|
12
|
+
[](LICENSE)
|
|
11
13
|
|
|
12
|
-
[
|
|
14
|
+
Live docs: [https://schero94.github.io/Magic-Sessionmanager/](https://schero94.github.io/Magic-Sessionmanager/) · [npm](https://www.npmjs.com/package/strapi-plugin-magic-sessionmanager) · [Changelog](CHANGELOG.md) · [Report a bug](https://github.com/Schero94/Magic-Sessionmanager/issues/new/choose) · [Discussions](https://github.com/Schero94/Magic-Sessionmanager/discussions)
|
|
13
15
|
|
|
14
|
-
|
|
16
|
+

|
|
15
17
|
|
|
16
18
|
---
|
|
17
19
|
|
|
18
20
|
## Contents
|
|
19
21
|
|
|
22
|
+
- [Features](#features)
|
|
23
|
+
- [Quick start (1 minute)](#quick-start-1-minute)
|
|
20
24
|
- [Screenshots](#screenshots)
|
|
21
25
|
- [Core concepts](#core-concepts)
|
|
22
26
|
- [Screens](#screens)
|
|
@@ -28,26 +32,70 @@ Free and open under the MIT license. All features are available without a paid l
|
|
|
28
32
|
- [Login protection](#login-protection)
|
|
29
33
|
- [Alerts](#alerts)
|
|
30
34
|
- [Content API](#content-api)
|
|
35
|
+
- [Examples](#examples)
|
|
31
36
|
- [Optional route policy: `session-required`](#optional-route-policy-session-required)
|
|
32
37
|
- [Admin API and permissions](#admin-api-and-permissions)
|
|
38
|
+
- [Running several instances (Railway replicas, pm2 cluster)](#running-several-instances-railway-replicas-pm2-cluster)
|
|
39
|
+
- [Performance](#performance)
|
|
33
40
|
- [Security and privacy](#security-and-privacy)
|
|
34
41
|
- [Troubleshooting](#troubleshooting)
|
|
42
|
+
- [FAQ](#faq)
|
|
43
|
+
- [Migration and upgrading](#migration-and-upgrading)
|
|
35
44
|
- [Development and tests](#development-and-tests)
|
|
45
|
+
- [Contributing](#contributing)
|
|
36
46
|
- [Maintenance status](#maintenance-status)
|
|
37
47
|
- [Languages](#languages)
|
|
38
48
|
- [License](#license)
|
|
39
49
|
|
|
40
50
|
---
|
|
41
51
|
|
|
42
|
-
##
|
|
52
|
+
## Features
|
|
53
|
+
|
|
54
|
+
| Area | What you get |
|
|
55
|
+
| ---------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
56
|
+
| Overview | A sessions dashboard with Active, Idle and Ended counts, search, filters, CSV and JSON export, and a details dialog per session (device, browser, IP address, location, security score). |
|
|
57
|
+
| Control | End one session, end all sessions of a user, delete a record, or block a user. Ended sessions are rejected on the next request with 401 and a reason header. |
|
|
58
|
+
| Your users | Content API routes for "my sessions", "current session", log out, log out everywhere and log out other devices. Each user only ever sees their own sessions. |
|
|
59
|
+
| Login protection | Temporary IP lockout after failed sign-ins, Content API rate limits, optional rejection of VPN, proxy or low-score sign-ins, and country allow or block lists. |
|
|
60
|
+
| Location | IP location from a local MaxMind GeoLite2 database (no third party in the sign-in path) or from ipapi.co, or turned off. |
|
|
61
|
+
| Alerts | Security emails to the user through Strapi's Email plugin and sign-in notifications to Discord or Slack. |
|
|
62
|
+
| Admin integration | A Sessions panel next to each user in the Content Manager and an Online users widget on the Strapi homepage. |
|
|
63
|
+
| Native Strapi sessions | Works with `jwtManagement: 'refresh'` (Strapi's own sessions and refresh tokens) and with `'legacy-support'`. |
|
|
64
|
+
| Several processes | Lockout, rate limits, jobs and settings stay consistent across pm2 workers and Railway replicas that share one database. |
|
|
65
|
+
| Privacy | Stored tokens are encrypted (AES-256-GCM) and never returned. Retention deletes old history automatically. No telemetry. |
|
|
43
66
|
|
|
44
|
-
|
|
67
|
+
---
|
|
45
68
|
|
|
46
|
-
|
|
69
|
+
## Quick start (1 minute)
|
|
47
70
|
|
|
48
|
-
|
|
71
|
+
```bash
|
|
72
|
+
npm install strapi-plugin-magic-sessionmanager
|
|
73
|
+
```
|
|
49
74
|
|
|
50
|
-
|
|
75
|
+
```typescript
|
|
76
|
+
// config/plugins.ts
|
|
77
|
+
export default () => ({
|
|
78
|
+
'magic-sessionmanager': { enabled: true },
|
|
79
|
+
});
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
```bash
|
|
83
|
+
# a stable key for token encryption (startup fails without it in production)
|
|
84
|
+
echo "SESSION_ENCRYPTION_KEY=$(node -e "console.log(require('crypto').randomBytes(32).toString('base64'))")" >> .env
|
|
85
|
+
npm run build && npm run develop
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
Sign in to your app as an end user (`POST /api/auth/local`), open **Session Manager** in the admin menu and the new session is listed as **Active**. End it, and the same token gets 401 on its next request.
|
|
89
|
+
|
|
90
|
+
Yarn and pnpm work the same way (`yarn add strapi-plugin-magic-sessionmanager`, `pnpm add strapi-plugin-magic-sessionmanager`).
|
|
91
|
+
|
|
92
|
+
---
|
|
93
|
+
|
|
94
|
+
## Screenshots
|
|
95
|
+
|
|
96
|
+
All screenshots use synthetic data: users `*.example.test`, IP addresses from the documentation range `203.0.113.0/24`, Strapi 5.61.
|
|
97
|
+
|
|
98
|
+
### Sessions dashboard in dark mode
|
|
51
99
|
|
|
52
100
|

|
|
53
101
|
|
|
@@ -125,7 +173,6 @@ Dark mode:
|
|
|
125
173
|
| Strapi homepage | **Online users** widget | Who is online right now? |
|
|
126
174
|
| Settings › Session Manager | **Configuration** | How should sessions and sign-ins behave? |
|
|
127
175
|
| Settings › Session Manager | **Analytics** | How are sessions used over time and by device? |
|
|
128
|
-
| Settings › Session Manager | **License** | Is a license key stored, and is it valid? |
|
|
129
176
|
|
|
130
177
|
### Sessions dashboard
|
|
131
178
|
|
|
@@ -162,7 +209,7 @@ Strapi 5.13 and later. Four tiles: **Online users** (of all registered users), *
|
|
|
162
209
|
|
|
163
210
|
### Settings › Session Manager
|
|
164
211
|
|
|
165
|
-
|
|
212
|
+
Two links: **Configuration** and **Analytics**.
|
|
166
213
|
|
|
167
214
|
**Configuration** has five tabs, deep-linkable with `?tab=sessions|login-protection|location-data|alerts|data-retention`:
|
|
168
215
|
|
|
@@ -178,19 +225,20 @@ Three links: **Configuration**, **Analytics** and **License**.
|
|
|
178
225
|
|
|
179
226
|
**Analytics** shows All sessions, Active sessions, Sign-ins in the last 24 hours and in the last 7 days (rolling windows), sessions by device and by browser, and the average session length, all from the latest loaded sessions.
|
|
180
227
|
|
|
181
|
-
**License** shows whether an optional license key is stored and whether it is valid. It is read-only. All features are available with or without a key.
|
|
182
|
-
|
|
183
228
|
---
|
|
184
229
|
|
|
185
230
|
## Compatibility
|
|
186
231
|
|
|
187
|
-
| Item
|
|
188
|
-
|
|
|
189
|
-
| Strapi
|
|
190
|
-
| Node.js
|
|
191
|
-
| Users & Permissions
|
|
192
|
-
| Homepage widget
|
|
193
|
-
|
|
|
232
|
+
| Item | Supported |
|
|
233
|
+
| ------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
234
|
+
| Strapi | 5 (`@strapi/strapi` peer range `^5.0.0`). Acceptance host: Strapi 5.61.0. |
|
|
235
|
+
| Node.js | `^22.22.2 \|\| >=24.15.0` (`engines.node`) |
|
|
236
|
+
| Users & Permissions | `jwtManagement: 'refresh'` and `'legacy-support'` |
|
|
237
|
+
| Homepage widget | Strapi 5.13 and later (older versions have no widgets API; the rest works) |
|
|
238
|
+
| Required peers | `@strapi/strapi` `^5.0.0`, `@strapi/plugin-users-permissions` `^5.0.0`, `react` / `react-dom` `^18.0.0`, `react-router-dom` `^6.0.0`, `styled-components` `^6.0.0`. A new Strapi 5 app already has all of them. |
|
|
239
|
+
| Optional peers | `@strapi/design-system` `^2.0.0`, `@strapi/icons` `^2.0.0`, `react-intl` `^6.0.0`. Strapi's admin brings them; they are marked optional so npm, Yarn and pnpm do not warn. |
|
|
240
|
+
| Package managers | npm, Yarn 1 and pnpm. Installing into a fresh Strapi 5.61 app prints no warning about this plugin. |
|
|
241
|
+
| Databases | PostgreSQL, MySQL, SQLite (several processes need PostgreSQL or MySQL, see [Running several instances](#running-several-instances-railway-replicas-pm2-cluster)). |
|
|
194
242
|
|
|
195
243
|
---
|
|
196
244
|
|
|
@@ -275,32 +323,32 @@ export default () => ({
|
|
|
275
323
|
|
|
276
324
|
Static defaults from `server/src/config/index.js`; admin units and ranges from the settings validation in `server/src/controllers/settings.js`. Out-of-range admin values are rejected with a field error, not clamped silently.
|
|
277
325
|
|
|
278
|
-
| Key | Default | Admin unit and range | Configuration tab | Meaning
|
|
279
|
-
| ------------------------------------------------------------------- | --------------------------------------------- | ----------------------------------------------------------------- | ----------------------------- |
|
|
280
|
-
| `inactivityTimeout` | 15 min (`900000` ms) | min, 1
|
|
281
|
-
| `maxSessionAgeDays` | 30 | days, 1
|
|
282
|
-
| `lastSeenRateLimit` | 30 s (`30000` ms) | s, 5
|
|
283
|
-
| `cleanupInterval` | 30 min (`1800000` ms) | min, 5
|
|
284
|
-
| `cleanupUseDbDirect` | `false` | boolean | Sessions › Advanced | Idle check with one SQL update instead of the Document Service (skips lifecycle hooks).
|
|
285
|
-
| `strictSessionEnforcement` | `false` (Relaxed) | boolean | Sessions | Strict rejects tokens without a session record and requests where the check itself fails. Ended, expired and revoked sessions and blocked users are rejected in both modes.
|
|
286
|
-
| `sessionCreationGraceMs` | `5000` | ms, 0
|
|
287
|
-
| `maxFailedLogins` | 5 | 0
|
|
288
|
-
| `trustedProxies` | off | boolean | Login protection | Read the client IP from proxy headers. Only behind a proxy you control.
|
|
289
|
-
| `blockSuspiciousSessions` | `false` | boolean | Login protection | Reject suspicious sign-ins.
|
|
290
|
-
| `geoLookupFailureMode` | `'auto'` | auto, allow, block | Login protection | What happens when the location cannot be determined.
|
|
291
|
-
| `enableGeofencing` | `false` | boolean | Login protection | Use country rules.
|
|
292
|
-
| `allowedCountries` / `blockedCountries` | `[]` | ISO 3166-1 alpha-2 codes | Login protection | Allow only listed countries / Reject listed countries.
|
|
293
|
-
| `enableGeolocation` | `true` | boolean | Location data | IP location lookup at sign-in. Required by country rules, suspicious-sign-in checks and alerts.
|
|
294
|
-
| `enableSecurityScoring` | `true` | boolean | Location data | Apply the security score thresholds (below 70: suspicious-sign-in email, below 50: rejection if enabled).
|
|
295
|
-
| `geoIpProvider` | `'auto'` | auto, local-mmdb, ipapi, disabled | Location data | Where location data comes from.
|
|
296
|
-
| `geoIpDatabasePath` | `MAGIC_SESSIONMANAGER_GEOIP_DATABASE` or `''` | file name | Location data › Advanced | Local MaxMind-compatible database.
|
|
297
|
-
| `enableEmailAlerts` | `false` | boolean | Alerts | Security emails to users.
|
|
298
|
-
| `alertOnSuspiciousLogin` / `alertOnNewLocation` / `alertOnVpnProxy` | `true` | boolean | Alerts | Which events send an email.
|
|
299
|
-
| `enableWebhooks` | `false` | boolean | Alerts | Team notifications.
|
|
300
|
-
| `discordWebhookUrl` / `slackWebhookUrl` | `''` | https URL on discord.com / discordapp.com, or hooks.slack.com | Alerts | Any other host is rejected.
|
|
301
|
-
| `retentionDays` | 90 | days, 1
|
|
302
|
-
| `rateLimitWriteMax` / `rateLimitReadMax` / `rateLimitWindowSeconds` | 10 / 120 / 60 | 1
|
|
303
|
-
| `emailTemplates` | empty | subject ≤ 200, HTML ≤ 10,000 (sanitised), text ≤ 5,000 characters | Alerts › Edit email templates | As soon as any template has content, only stored templates are used. Fill in all three, or none.
|
|
326
|
+
| Key | Default | Admin unit and range | Configuration tab | Meaning |
|
|
327
|
+
| ------------------------------------------------------------------- | --------------------------------------------- | ----------------------------------------------------------------- | ----------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
328
|
+
| `inactivityTimeout` | 15 min (`900000` ms) | min, 1 to 1440 | Sessions | Unused this long, a session becomes idle and then ends as "Timed out". Also decides who counts as online. |
|
|
329
|
+
| `maxSessionAgeDays` | 30 | days, 1 to 365 | Sessions | Maximum age from sign-in, regardless of activity. Applied on the session's next request. |
|
|
330
|
+
| `lastSeenRateLimit` | 30 s (`30000` ms) | s, 5 to 300 | Sessions › Advanced | Minimum interval between "Last active" updates. |
|
|
331
|
+
| `cleanupInterval` | 30 min (`1800000` ms) | min, 5 to 1440 | Sessions › Advanced | How often the idle check runs. It ends idle sessions and deletes nothing. It also runs at server start; with several instances only one runs it per interval. |
|
|
332
|
+
| `cleanupUseDbDirect` | `false` | boolean | Sessions › Advanced | Idle check with one SQL update instead of the Document Service (skips lifecycle hooks). |
|
|
333
|
+
| `strictSessionEnforcement` | `false` (Relaxed) | boolean | Sessions | Strict rejects tokens without a session record and requests where the check itself fails. Ended, expired and revoked sessions and blocked users are rejected in both modes. |
|
|
334
|
+
| `sessionCreationGraceMs` | `5000` | ms, 0 to 30000 (shown in seconds) | Sessions › Advanced | Window after sign-in in which a token is accepted while its record is being created. |
|
|
335
|
+
| `maxFailedLogins` | 5 | 0 to 100, 0 = off | Login protection | Temporary IP lockout threshold (failed sign-ins from one IP within 15 minutes). |
|
|
336
|
+
| `trustedProxies` | off | boolean | Login protection | Read the client IP from proxy headers. Only behind a proxy you control. |
|
|
337
|
+
| `blockSuspiciousSessions` | `false` | boolean | Login protection | Reject suspicious sign-ins. |
|
|
338
|
+
| `geoLookupFailureMode` | `'auto'` | auto, allow, block | Login protection | What happens when the location cannot be determined. |
|
|
339
|
+
| `enableGeofencing` | `false` | boolean | Login protection | Use country rules. |
|
|
340
|
+
| `allowedCountries` / `blockedCountries` | `[]` | ISO 3166-1 alpha-2 codes | Login protection | Allow only listed countries / Reject listed countries. |
|
|
341
|
+
| `enableGeolocation` | `true` | boolean | Location data | IP location lookup at sign-in. Required by country rules, suspicious-sign-in checks and alerts. |
|
|
342
|
+
| `enableSecurityScoring` | `true` | boolean | Location data | Apply the security score thresholds (below 70: suspicious-sign-in email, below 50: rejection if enabled). |
|
|
343
|
+
| `geoIpProvider` | `'auto'` | auto, local-mmdb, ipapi, disabled | Location data | Where location data comes from. |
|
|
344
|
+
| `geoIpDatabasePath` | `MAGIC_SESSIONMANAGER_GEOIP_DATABASE` or `''` | file name | Location data › Advanced | Local MaxMind-compatible database. |
|
|
345
|
+
| `enableEmailAlerts` | `false` | boolean | Alerts | Security emails to users. |
|
|
346
|
+
| `alertOnSuspiciousLogin` / `alertOnNewLocation` / `alertOnVpnProxy` | `true` | boolean | Alerts | Which events send an email. |
|
|
347
|
+
| `enableWebhooks` | `false` | boolean | Alerts | Team notifications. |
|
|
348
|
+
| `discordWebhookUrl` / `slackWebhookUrl` | `''` | https URL on discord.com / discordapp.com, or hooks.slack.com | Alerts | Any other host is rejected. |
|
|
349
|
+
| `retentionDays` | 90 | days, 1 to 365 or -1 (forever) | Data and retention | How long records of ended sessions are kept. Checked once a day across all instances, the first time about 5 minutes after the server starts. Open sessions are never deleted by retention. |
|
|
350
|
+
| `rateLimitWriteMax` / `rateLimitReadMax` / `rateLimitWindowSeconds` | 10 / 120 / 60 | 1 to 1000 / 1 to 10000 / 10 to 3600 | not shown | Content API rate limits. Not editable in the UI; Save keeps the stored values. The write limit can only be made stricter than the route floor. |
|
|
351
|
+
| `emailTemplates` | empty | subject ≤ 200, HTML ≤ 10,000 (sanitised), text ≤ 5,000 characters | Alerts › Edit email templates | As soon as any template has content, only stored templates are used. Fill in all three, or none. |
|
|
304
352
|
|
|
305
353
|
### Environment variables
|
|
306
354
|
|
|
@@ -355,12 +403,12 @@ The updater checks MaxMind's `Last-Modified` header and skips the download when
|
|
|
355
403
|
|
|
356
404
|
Configuration › Login protection checks **new sign-ins only**. Existing sessions are not affected, and refused sign-ins are not recorded.
|
|
357
405
|
|
|
358
|
-
| Rule | Response | Notes
|
|
359
|
-
| ----------------------------- | ----------------------------------- |
|
|
360
|
-
| Temporary IP lockout | 429 with `Retry-After` | After `maxFailedLogins` failed sign-ins from one IP address within 15 minutes, that address is refused for 15 minutes. User accounts are not blocked.
|
|
361
|
-
| Reject suspicious sign-ins | 403 | VPN, proxy or known threat address, or, with security scoring on, a score below 50.
|
|
362
|
-
| Country rules | 403 | Allow only listed countries, or reject listed countries. With "Allow only listed countries", an empty list allows every country.
|
|
363
|
-
| Location cannot be determined | 403 "Login temporarily unavailable" | When `geoLookupFailureMode` says reject (`auto` rejects only when "Reject suspicious sign-ins" is on).
|
|
406
|
+
| Rule | Response | Notes |
|
|
407
|
+
| ----------------------------- | ----------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
408
|
+
| Temporary IP lockout | 429 with `Retry-After` | After `maxFailedLogins` failed sign-ins from one IP address within 15 minutes, that address is refused for 15 minutes. User accounts are not blocked. Shared by all server processes. Each attempt is counted before the password check, so a parallel burst cannot exceed the limit; when more attempts from one address are running at once than the limit, the extra ones get 429 with `Retry-After: 1` and no lock. |
|
|
409
|
+
| Reject suspicious sign-ins | 403 | VPN, proxy or known threat address, or, with security scoring on, a score below 50. |
|
|
410
|
+
| Country rules | 403 | Allow only listed countries, or reject listed countries. With "Allow only listed countries", an empty list allows every country. |
|
|
411
|
+
| Location cannot be determined | 403 "Login temporarily unavailable" | When `geoLookupFailureMode` says reject (`auto` rejects only when "Reject suspicious sign-ins" is on). |
|
|
364
412
|
|
|
365
413
|
Requests with an ended session get **401** with the header `X-Session-Terminated-Reason` (`logout`, `manual`, `idle`, `expired` or `blocked`).
|
|
366
414
|
|
|
@@ -444,6 +492,64 @@ Example:
|
|
|
444
492
|
|
|
445
493
|
---
|
|
446
494
|
|
|
495
|
+
## Examples
|
|
496
|
+
|
|
497
|
+
All examples use a synthetic host `https://api.example.test` and a placeholder token.
|
|
498
|
+
|
|
499
|
+
**A "Your devices" list in your app.** Load the caller's sessions; the current one comes first.
|
|
500
|
+
|
|
501
|
+
```js
|
|
502
|
+
const res = await fetch('https://api.example.test/api/magic-sessionmanager/my-sessions', {
|
|
503
|
+
headers: { Authorization: `Bearer ${jwt}` },
|
|
504
|
+
});
|
|
505
|
+
const { data, meta } = await res.json();
|
|
506
|
+
// data[0].isCurrentSession === true, meta.active = number of open sessions
|
|
507
|
+
```
|
|
508
|
+
|
|
509
|
+
**Sign out one other device** (not the current one):
|
|
510
|
+
|
|
511
|
+
```bash
|
|
512
|
+
curl -X DELETE https://api.example.test/api/magic-sessionmanager/my-sessions/k2v8m1x0q9w7e5r3t1y6u4i2 \
|
|
513
|
+
-H "Authorization: Bearer <JWT>"
|
|
514
|
+
# {"message":"...","success":true,"alreadyTerminated":false}
|
|
515
|
+
```
|
|
516
|
+
|
|
517
|
+
**Sign out everywhere except here** (for example after a password change):
|
|
518
|
+
|
|
519
|
+
```bash
|
|
520
|
+
curl -X POST https://api.example.test/api/magic-sessionmanager/logout-others \
|
|
521
|
+
-H "Authorization: Bearer <JWT>"
|
|
522
|
+
# {"message":"2 other session(s) terminated","terminatedCount":2,"currentSessionPreserved":true}
|
|
523
|
+
```
|
|
524
|
+
|
|
525
|
+
**React to an ended session in the client.** A request with an ended session gets 401 and the header `X-Session-Terminated-Reason`. Browsers only let cross-origin JavaScript read that header when CORS exposes it:
|
|
526
|
+
|
|
527
|
+
```js
|
|
528
|
+
// config/middlewares.js
|
|
529
|
+
module.exports = [
|
|
530
|
+
// ...
|
|
531
|
+
{ name: 'strapi::cors', config: { expose: ['X-Session-Terminated-Reason'] } },
|
|
532
|
+
// ...
|
|
533
|
+
];
|
|
534
|
+
```
|
|
535
|
+
|
|
536
|
+
```js
|
|
537
|
+
async function api(path, jwt) {
|
|
538
|
+
const res = await fetch(`https://api.example.test${path}`, {
|
|
539
|
+
headers: { Authorization: `Bearer ${jwt}` },
|
|
540
|
+
});
|
|
541
|
+
if (res.status === 401) {
|
|
542
|
+
const reason = res.headers.get('X-Session-Terminated-Reason'); // logout, manual, idle, expired, blocked
|
|
543
|
+
if (reason === 'blocked') showMessage('This account is blocked.');
|
|
544
|
+
else if (reason) showMessage('You were signed out. Please sign in again.');
|
|
545
|
+
redirectToLogin();
|
|
546
|
+
}
|
|
547
|
+
return res.json();
|
|
548
|
+
}
|
|
549
|
+
```
|
|
550
|
+
|
|
551
|
+
---
|
|
552
|
+
|
|
447
553
|
## Optional route policy: `session-required`
|
|
448
554
|
|
|
449
555
|
You do **not** need this policy for session revocation. The plugin wraps the Users & Permissions JWT check for every Content API request, so an ended, expired or revoked session is rejected on all routes without configuration. No plugin route attaches the policy.
|
|
@@ -479,29 +585,196 @@ module.exports = factories.createCoreRouter('api::order.order', {
|
|
|
479
585
|
|
|
480
586
|
Prefix `/magic-sessionmanager` (Strapi admin API). Every route requires an authenticated Strapi admin **and** the permission `plugin::magic-sessionmanager.access` ("Access the Session Manager plugin"). The same permission controls the menu link, the settings links, the widget and the user panel. Admin responses never contain tokens or the internal `sessionId`.
|
|
481
587
|
|
|
482
|
-
| Method | Path
|
|
483
|
-
| -------- |
|
|
484
|
-
| GET | `/sessions`
|
|
485
|
-
| GET | `/sessions/active`
|
|
486
|
-
| GET | `/user/:userId/sessions`
|
|
487
|
-
| POST | `/sessions/:sessionId/terminate`
|
|
488
|
-
| DELETE | `/sessions/:sessionId`
|
|
489
|
-
| POST | `/sessions/clean-inactive`
|
|
490
|
-
| POST | `/user/:userId/terminate-all`
|
|
491
|
-
| POST | `/user/:userId/toggle-block`
|
|
492
|
-
| GET | `/users/stats`
|
|
493
|
-
| GET | `/geolocation/:ipAddress`
|
|
494
|
-
| GET | `/geoip/status`
|
|
495
|
-
| PUT | `/geoip/credentials`
|
|
496
|
-
| POST | `/geoip/update`
|
|
497
|
-
| GET, PUT | `/settings`
|
|
498
|
-
|
|
|
499
|
-
| POST | `/license/auto-create`, `/license/create`, `/license/ping`, `/license/store-key` | License service routes (no admin UI) |
|
|
500
|
-
| POST | `/sessions/:sessionId/simulate-timeout` | Development only; removed when `NODE_ENV` is `production` or `staging` |
|
|
588
|
+
| Method | Path | Admin UI action |
|
|
589
|
+
| -------- | --------------------------------------- | ----------------------------------------------------------------------------------------------------------- |
|
|
590
|
+
| GET | `/sessions` | Sessions dashboard, widget, Analytics (latest 1,000; `meta.truncated` when more exist) |
|
|
591
|
+
| GET | `/sessions/active` | Open sessions only |
|
|
592
|
+
| GET | `/user/:userId/sessions` | Sessions panel |
|
|
593
|
+
| POST | `/sessions/:sessionId/terminate` | **End session** (reason `manual`; in refresh mode the Strapi session is revoked first; the record stays) |
|
|
594
|
+
| DELETE | `/sessions/:sessionId` | **Delete record** (record removed, token stays revoked; an open session also ends) |
|
|
595
|
+
| POST | `/sessions/clean-inactive` | **Delete ended sessions** (all users; open and idle sessions are not affected; does not run the idle check) |
|
|
596
|
+
| POST | `/user/:userId/terminate-all` | **End all sessions** (reason `manual`) |
|
|
597
|
+
| POST | `/user/:userId/toggle-block` | **Block user** / **Unblock user** |
|
|
598
|
+
| GET | `/users/stats` | Widget totals (`totalUsers`, `blockedUsers`) |
|
|
599
|
+
| GET | `/geolocation/:ipAddress` | **Look up location** |
|
|
600
|
+
| GET | `/geoip/status` | GeoIP database status |
|
|
601
|
+
| PUT | `/geoip/credentials` | Save or remove (`{ "clear": true }`) MaxMind credentials |
|
|
602
|
+
| POST | `/geoip/update` | Update database / Force download |
|
|
603
|
+
| GET, PUT | `/settings` | Configuration (PUT validates every field and returns `error.details.errors` on invalid input) |
|
|
604
|
+
| POST | `/sessions/:sessionId/simulate-timeout` | Development only; removed when `NODE_ENV` is `production` or `staging` |
|
|
501
605
|
|
|
502
606
|
**Block / unblock** (`toggle-block`): send `{ "blocked": true }` or `{ "blocked": false }`. This sets the state, is safe to retry and is what the admin UI sends. A request without a body still toggles, but is deprecated, because a retry after a lost response can reverse the intended state. A non-boolean `blocked` returns 400. The response contains `blocked` and `mode` (`explicit` or `toggle`). Blocking ends all open sessions with the reason `blocked`; if that fails, the response is 500 and the request can be retried.
|
|
503
607
|
|
|
504
|
-
Errors use Strapi's `{ data: null, error }` envelope: 400 for invalid input, 404 for unknown IDs, 500 for server-side failures
|
|
608
|
+
Errors use Strapi's `{ data: null, error }` envelope: 400 for invalid input, 404 for unknown IDs, 500 for server-side failures, 502 for a failed MaxMind download, 409 for a settings save based on an outdated `revision`.
|
|
609
|
+
|
|
610
|
+
---
|
|
611
|
+
|
|
612
|
+
## Running several instances (Railway replicas, pm2 cluster)
|
|
613
|
+
|
|
614
|
+
The plugin works with several Strapi processes that share one database, for example 2 Railway replicas with 4 pm2 cluster workers each (8 processes). No sticky sessions are needed (Railway does not offer them) and no extra infrastructure: the database is the single source of truth.
|
|
615
|
+
|
|
616
|
+
### What is shared and how
|
|
617
|
+
|
|
618
|
+
| State | How it stays consistent across processes |
|
|
619
|
+
| ------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
620
|
+
| Session validity (end, block, revoke, idle, expiry) | Read from `magic_sessions` on every request. State changes are conditional updates (`UPDATE … WHERE isActive = …`), so a stale read on one process can never revive a terminated session or overwrite a `manual` / `blocked` reason set by another one. |
|
|
621
|
+
| Failed-login lockout (`maxFailedLogins`) | One counter per client IP (stored as a SHA-256 hash) in `magic_sm_counters`, updated with a single atomic `UPDATE`. A lock or a successful sign-in applies on every process at once and survives restarts. |
|
|
622
|
+
| Content API rate limits | Same shared counters, keyed by route template and caller. The configured limit is the limit for the whole cluster, not per process. |
|
|
623
|
+
| Idle cleanup, retention | A job lease in `magic_sm_leases`: every process keeps its timer, but only the process that takes the lease runs the job. Cleanup runs about once per `cleanupInterval`, retention once per day (first run about 5 minutes after a start). |
|
|
624
|
+
| Permission setup, session indexes, plugin-store writes (settings, GeoIP credentials) | A cluster-wide critical section: `pg_advisory_xact_lock` on PostgreSQL, a lease row on SQLite and MySQL. Duplicate Core Store rows and duplicate Authenticated-role permissions left by older versions are removed automatically. |
|
|
625
|
+
| Settings cache | Each save bumps a shared revision. Every process checks it at most every 2 seconds and reloads when it changed, so a new policy applies everywhere within about 2 seconds. |
|
|
626
|
+
| Concurrent settings saves | The admin sends the revision it loaded. If another administrator saved in between, the save is refused with 409 and nothing is overwritten. API clients that send no `revision` keep the previous behaviour. |
|
|
627
|
+
| ipapi.co results and back-off | Shared through `magic_sm_cache` (IP stored only as a hash), so one lookup or one HTTP 429 serves all processes. |
|
|
628
|
+
| `SESSION_ENCRYPTION_KEY` | Each process compares an HMAC check value of its key (never the key) at start and logs an error when instances use different keys. |
|
|
629
|
+
|
|
630
|
+
The three `magic_sm_*` tables are created at startup with portable statements (PostgreSQL, MySQL, SQLite 3.24+). The database user needs the `CREATE` privilege once. Strapi leaves tables it does not manage untouched.
|
|
631
|
+
|
|
632
|
+
What stays per process, by design: the fail-open error budget in Relaxed token check mode (10 errors per minute per process; Strict mode never fails open), short in-process caches in front of the shared state, and the GeoIP database file (see below).
|
|
633
|
+
|
|
634
|
+
### Exact setup
|
|
635
|
+
|
|
636
|
+
1. **One PostgreSQL (or MySQL) database for all instances.** SQLite works only when all processes run on one machine and share the file.
|
|
637
|
+
2. **Identical secrets on every instance.** On Railway, define them as shared variables: `SESSION_ENCRYPTION_KEY`, `APP_KEYS`, `JWT_SECRET`, `ADMIN_JWT_SECRET`, `API_TOKEN_SALT`, `TRANSFER_TOKEN_SALT`, `ENCRYPTION_KEY`, and `NODE_ENV=production`. Different `SESSION_ENCRYPTION_KEY` values make stored tokens unreadable on the other instances; the plugin logs an error at startup when it detects that.
|
|
638
|
+
3. **The real client IP.** Railway and most platforms put a proxy in front of the app. Turn on Koa's proxy mode identically everywhere, otherwise lockout and rate limits see the proxy address:
|
|
639
|
+
|
|
640
|
+
```js
|
|
641
|
+
// config/server.js
|
|
642
|
+
module.exports = ({ env }) => ({
|
|
643
|
+
host: env('HOST', '0.0.0.0'),
|
|
644
|
+
port: env.int('PORT', 1337),
|
|
645
|
+
app: { keys: env.array('APP_KEYS') },
|
|
646
|
+
proxy: { koa: env.bool('IS_PROXIED', true), maxIpsCount: env.int('MAX_IPS_COUNT', 1) },
|
|
647
|
+
});
|
|
648
|
+
```
|
|
649
|
+
|
|
650
|
+
With `proxy.koa` on, the plugin reads the client IP from the proxy headers (`CF-Connecting-IP`, `X-Real-IP`, then the first `X-Forwarded-For` entry). Only enable it behind a proxy you control.
|
|
651
|
+
|
|
652
|
+
4. **pm2 in cluster mode** (one container or VM):
|
|
653
|
+
|
|
654
|
+
```js
|
|
655
|
+
// ecosystem.config.js
|
|
656
|
+
module.exports = {
|
|
657
|
+
apps: [
|
|
658
|
+
{
|
|
659
|
+
name: 'strapi',
|
|
660
|
+
script: 'node_modules/@strapi/strapi/bin/strapi.js',
|
|
661
|
+
args: 'start',
|
|
662
|
+
instances: 4,
|
|
663
|
+
exec_mode: 'cluster',
|
|
664
|
+
env: { NODE_ENV: 'production' },
|
|
665
|
+
},
|
|
666
|
+
],
|
|
667
|
+
};
|
|
668
|
+
```
|
|
669
|
+
|
|
670
|
+
Start it with `pm2-runtime start ecosystem.config.js` in containers.
|
|
671
|
+
|
|
672
|
+
5. **Start one process first after a schema change.** Strapi itself syncs its database schema at every start. On an empty database, several processes starting at the same moment race on Strapi's own tables (`strapi_migrations` already exists / duplicate key in `pg_type`) and crash; we reproduced this with 4 processes on PostgreSQL 16 and Strapi 5.61. This is Strapi core behaviour, not the plugin's. For the first deploy and for deploys that change content types, start a single process once (for example a Railway [pre-deploy command](https://docs.railway.com/deployments/pre-deploy-command) or one replica with `instances: 1`), then scale out. The plugin's own start-up work is safe to run in parallel.
|
|
673
|
+
6. **GeoIP database file on every instance.** Railway replicas cannot use volumes ([Railway docs](https://docs.railway.com/volumes/reference#caveats)), and the file is local to each container. With `local-mmdb`, download it during the build or before pm2 starts, so every replica has it:
|
|
674
|
+
|
|
675
|
+
```bash
|
|
676
|
+
# build or start command, before pm2 forks the workers
|
|
677
|
+
npx strapi-magic-sessionmanager-geoip && pm2-runtime start ecosystem.config.js
|
|
678
|
+
```
|
|
679
|
+
|
|
680
|
+
with `MAXMIND_ACCOUNT_ID`, `MAXMIND_LICENSE_KEY` and `MAXMIND_EDITION_ID=GeoLite2-City` set. **Update database** in the admin downloads the file only on the instance that answered; the GeoIP status reports `scope: "instance"` and a non-reversible `instance` fingerprint so you can tell instances apart. The pm2 workers of one container share the file.
|
|
681
|
+
|
|
682
|
+
### Configuration
|
|
683
|
+
|
|
684
|
+
```js
|
|
685
|
+
// config/plugins.js
|
|
686
|
+
module.exports = () => ({
|
|
687
|
+
'magic-sessionmanager': {
|
|
688
|
+
enabled: true,
|
|
689
|
+
config: {
|
|
690
|
+
coordination: {
|
|
691
|
+
enabled: true, // false = per-process state, the behaviour before 4.10
|
|
692
|
+
counterStore: null, // optional: Redis (or other) store for lockout and rate-limit counters
|
|
693
|
+
},
|
|
694
|
+
},
|
|
695
|
+
},
|
|
696
|
+
});
|
|
697
|
+
```
|
|
698
|
+
|
|
699
|
+
The database store needs nothing else. If you already run Redis and want the counters there, pass an object with four async methods (`hit` must return the count written by that call, as the Lua script below does) and an optional `release`. Example with [node-redis](https://github.com/redis/node-redis) (`npm i redis`); when Redis fails, the plugin falls back to the database for that call:
|
|
700
|
+
|
|
701
|
+
```js
|
|
702
|
+
// config/plugins.js
|
|
703
|
+
const { createClient } = require('redis');
|
|
704
|
+
|
|
705
|
+
const redis = createClient({ url: process.env.REDIS_URL });
|
|
706
|
+
redis.connect();
|
|
707
|
+
|
|
708
|
+
const HIT = `
|
|
709
|
+
local start = tonumber(redis.call('HGET', KEYS[1], 's') or '0')
|
|
710
|
+
local now, win = tonumber(ARGV[1]), tonumber(ARGV[2])
|
|
711
|
+
if start <= now - win then redis.call('HSET', KEYS[1], 'h', 1, 's', now)
|
|
712
|
+
else redis.call('HINCRBY', KEYS[1], 'h', 1) end
|
|
713
|
+
if redis.call('PTTL', KEYS[1]) < win then redis.call('PEXPIRE', KEYS[1], win) end
|
|
714
|
+
return redis.call('HMGET', KEYS[1], 'h', 's', 'b')`;
|
|
715
|
+
|
|
716
|
+
const toState = ([h, s, b]) =>
|
|
717
|
+
h === null && b === null
|
|
718
|
+
? null
|
|
719
|
+
: { hits: Number(h || 0), windowStart: Number(s || 0), blockedUntil: Number(b || 0) };
|
|
720
|
+
|
|
721
|
+
module.exports = () => ({
|
|
722
|
+
'magic-sessionmanager': {
|
|
723
|
+
config: {
|
|
724
|
+
coordination: {
|
|
725
|
+
counterStore: {
|
|
726
|
+
hit: async (key, windowMs) =>
|
|
727
|
+
toState(
|
|
728
|
+
await redis.eval(HIT, {
|
|
729
|
+
keys: [`msm:${key}`],
|
|
730
|
+
arguments: [String(Date.now()), String(windowMs)],
|
|
731
|
+
})
|
|
732
|
+
),
|
|
733
|
+
peek: async (key) => toState(await redis.hmGet(`msm:${key}`, ['h', 's', 'b'])),
|
|
734
|
+
block: async (key, untilMs) => {
|
|
735
|
+
await redis.hSet(`msm:${key}`, 'b', String(untilMs));
|
|
736
|
+
// Keep the key at least until the block ends (-1 = no expiry yet).
|
|
737
|
+
if ((await redis.pTTL(`msm:${key}`)) < untilMs - Date.now()) {
|
|
738
|
+
await redis.pExpireAt(`msm:${key}`, untilMs);
|
|
739
|
+
}
|
|
740
|
+
},
|
|
741
|
+
clear: async (key) => {
|
|
742
|
+
await redis.del(`msm:${key}`);
|
|
743
|
+
},
|
|
744
|
+
// Optional: gives back one hit (a login that ended with a 5xx or
|
|
745
|
+
// was turned away as over the limit). Without it the hit stays.
|
|
746
|
+
release: async (key) => {
|
|
747
|
+
await redis.hIncrBy(`msm:${key}`, 'h', -1);
|
|
748
|
+
},
|
|
749
|
+
},
|
|
750
|
+
},
|
|
751
|
+
},
|
|
752
|
+
},
|
|
753
|
+
});
|
|
754
|
+
```
|
|
755
|
+
|
|
756
|
+
### Verifying
|
|
757
|
+
|
|
758
|
+
`npm run test:concurrency` starts 8 Node processes against one database and checks exact shared counts (every hit also reports its own count), a single job-lease winner, lock-protected read-modify-write, no duplicate check-then-create rows, exact revision bumps and a cluster-wide lockout. It runs on SQLite by default and also on PostgreSQL with `MSM_TEST_PG_URL=postgres://user@host:5432/db`. A control step does the same check-then-create without the lock and reports the duplicates that Strapi's Core Store produces in that case.
|
|
759
|
+
|
|
760
|
+
Measured over HTTP on an isolated Strapi 5.61 host with one PostgreSQL 16 database (synthetic users and IPs, outbound network blocked), once with 4 separate processes and once with pm2 cluster mode (4 workers): 48 parallel wrong passwords from one IP let exactly `maxFailedLogins` (5) reach the password check, after which every process answers 429; 48 parallel `logout-others` calls with a limit of 10 allowed exactly 10; 50 parallel refreshes with one refresh token produced exactly one new token and one active session; 60 parallel partial settings saves lost no field; 20 saves with the same `revision` gave one 200 and nineteen 409; a settings change reached the other processes within 2.5 seconds; idle cleanup ran exactly once per interval and retention once. The same suite passed on SQLite with one process. Not covered: MySQL, the Redis counter store over HTTP, and Railway itself.
|
|
761
|
+
|
|
762
|
+
---
|
|
763
|
+
|
|
764
|
+
## Performance
|
|
765
|
+
|
|
766
|
+
The plugin sits in the request path of every authenticated Content API call, so it keeps that path short:
|
|
767
|
+
|
|
768
|
+
| Work | How it is kept cheap |
|
|
769
|
+
| ------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
|
|
770
|
+
| Session check per request | One lookup by token hash. Startup creates the indexes `idx_magic_sessions_token_hash` and `idx_magic_sessions_refresh_hash` if they are missing. |
|
|
771
|
+
| "Last active" updates | At most one write per session per `lastSeenRateLimit` (30 seconds by default), as a conditional update. |
|
|
772
|
+
| Settings | Cached for 30 seconds per process; a shared revision is checked at most every 2 seconds (one primary-key read). |
|
|
773
|
+
| User lookups | Resolving a user's `documentId` is cached for 5 minutes per process. |
|
|
774
|
+
| ipapi.co lookups | Results are cached for 24 hours (failures for 5 minutes) and shared across processes, with the IP stored only as a hash. A local MaxMind database avoids the network call entirely. |
|
|
775
|
+
| Admin lists | The dashboard and Analytics load at most the latest 1,000 sessions and say so when more exist. `GET /my-sessions` returns at most 200. |
|
|
776
|
+
| Idle cleanup | Runs on one process per interval (job lease). In `legacy-support` mode, `cleanupUseDbDirect: true` ends idle sessions with a single SQL update instead of one Document Service call per session. |
|
|
777
|
+
| Old history | Retention deletes ended sessions older than `retentionDays` (90 by default) once a day, so the table does not grow without bound. |
|
|
505
778
|
|
|
506
779
|
---
|
|
507
780
|
|
|
@@ -517,6 +790,8 @@ Errors use Strapi's `{ data: null, error }` envelope: 400 for invalid input, 404
|
|
|
517
790
|
- **Revocation.** Ended, expired and revoked sessions and blocked users are rejected on every Content API request, in both token check modes. Tokens of deleted records stay on a revocation list.
|
|
518
791
|
- **Password reset.** A successful password reset ends every older session of the user in both JWT modes.
|
|
519
792
|
- **Privacy.** Session records contain IP addresses, user agents and location data. With the `auto` or `ipapi` provider, IP addresses can be sent to ipapi.co; use `local-mmdb` or turn off IP location lookup to avoid that. The details dialog never looks up a location unless you click **Look up location**. Set **Keep ended sessions for** to match your retention policy, and use **Delete ended sessions** or **Delete record** to remove history.
|
|
793
|
+
- **What leaves your server.** Only what you turn on: IP lookups at ipapi.co (provider `auto` without a local database, or `ipapi`), Discord or Slack webhooks (Team notifications), emails through your own Email provider (Security emails) and the MaxMind database download when you click **Update database** or run the updater. There is no telemetry, no install ping and no license check.
|
|
794
|
+
- **Reporting a vulnerability.** Please do not post exploit details in a public issue. Open an issue that asks for a private contact, or use the email address on the maintainer's GitHub profile, and you will get a reply before anything is published.
|
|
520
795
|
- **Secrets.** MaxMind license keys are never returned to the browser. Webhook URLs grant posting rights to your channel; treat them as secrets. Exports never contain tokens.
|
|
521
796
|
- **Admin sessions** of Strapi administrators are out of scope.
|
|
522
797
|
|
|
@@ -524,25 +799,79 @@ Errors use Strapi's `{ data: null, error }` envelope: 400 for invalid input, 404
|
|
|
524
799
|
|
|
525
800
|
## Troubleshooting
|
|
526
801
|
|
|
527
|
-
| Problem | Fix
|
|
528
|
-
| --------------------------------------------------------------------- |
|
|
529
|
-
| No Session Manager menu item | Check `config/plugins.ts`, run `npm run build`, restart, hard-refresh the browser. For non-Super-Admin roles, grant "Access the Session Manager plugin".
|
|
530
|
-
| No sessions appear | Only end-user sign-ins through Users & Permissions are recorded, not Strapi admin sign-ins. Check the Strapi log.
|
|
531
|
-
| Startup fails with `SESSION_ENCRYPTION_KEY is required in production` | Set the variable and restart.
|
|
532
|
-
| 401 on every request after a sign-in | Check the `X-Session-Terminated-Reason` header. With Strict token check, tokens without a session record are rejected.
|
|
533
|
-
| 429 on sign-in | Temporary IP lockout. Wait 15 minutes or raise `maxFailedLogins`. Behind a proxy, turn on Trust proxy headers so the lockout targets the real client.
|
|
534
|
-
| Location is always "—" | IP location lookup is off, the provider is `disabled`, or `local-mmdb` has no database. See Configuration › Location data.
|
|
535
|
-
| Numbers differ from 4.x | The widget and Analytics now count Active and Idle by the configured inactivity timeout; "Online now" is now "Active sessions".
|
|
802
|
+
| Problem | Fix |
|
|
803
|
+
| --------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
|
|
804
|
+
| No Session Manager menu item | Check `config/plugins.ts`, run `npm run build`, restart, hard-refresh the browser. For non-Super-Admin roles, grant "Access the Session Manager plugin". |
|
|
805
|
+
| No sessions appear | Only end-user sign-ins through Users & Permissions are recorded, not Strapi admin sign-ins. Check the Strapi log. |
|
|
806
|
+
| Startup fails with `SESSION_ENCRYPTION_KEY is required in production` | Set the variable and restart. |
|
|
807
|
+
| 401 on every request after a sign-in | Check the `X-Session-Terminated-Reason` header. With Strict token check, tokens without a session record are rejected. |
|
|
808
|
+
| 429 on sign-in | Temporary IP lockout. Wait 15 minutes or raise `maxFailedLogins`. Behind a proxy, turn on Trust proxy headers so the lockout targets the real client. With `Retry-After: 1`: more sign-ins from one address were running at once than `maxFailedLogins`; retry after a second. |
|
|
809
|
+
| Location is always "—" | IP location lookup is off, the provider is `disabled`, or `local-mmdb` has no database. See Configuration › Location data. |
|
|
810
|
+
| Numbers differ from 4.x | The widget and Analytics now count Active and Idle by the configured inactivity timeout; "Online now" is now "Active sessions". |
|
|
536
811
|
|
|
537
812
|
The plugin stores sessions in the `magic_sessions` table and revocations in its own revoked-token table.
|
|
538
813
|
|
|
539
814
|
---
|
|
540
815
|
|
|
816
|
+
## FAQ
|
|
817
|
+
|
|
818
|
+
**Does it manage Strapi admin accounts?**
|
|
819
|
+
No. It manages end users of Users & Permissions (`plugin::users-permissions.user`). Strapi administrator sessions are out of scope.
|
|
820
|
+
|
|
821
|
+
**Do I need a license key, account or activation?**
|
|
822
|
+
No. Everything is free under MIT, and the plugin does not contact any license or telemetry server. The only key you may add is your own MaxMind key for the GeoLite2 database.
|
|
823
|
+
|
|
824
|
+
**Do I have to add the `session-required` policy to my routes?**
|
|
825
|
+
No. Revocation works on every Content API route without configuration. The policy is an optional, explicit per-route check.
|
|
826
|
+
|
|
827
|
+
**Does it work with `jwtManagement: 'refresh'`?**
|
|
828
|
+
Yes. Strapi issues, rotates and revokes its own sessions; the plugin adds device, IP address, location and history, and ends the native session when you end it in the admin.
|
|
829
|
+
|
|
830
|
+
**Can I run it on Railway with several replicas, or with pm2 in cluster mode?**
|
|
831
|
+
Yes, with PostgreSQL or MySQL shared by all processes. See [Running several instances](#running-several-instances-railway-replicas-pm2-cluster). No sticky sessions or Redis are needed.
|
|
832
|
+
|
|
833
|
+
**Does it send my users' IP addresses anywhere?**
|
|
834
|
+
Only if location lookup uses ipapi.co: provider `ipapi`, or `auto` without a local database. Choose `local-mmdb` with a MaxMind database, or `disabled`, to keep IP addresses on your server.
|
|
835
|
+
|
|
836
|
+
**Why do my sign-ins get 429?**
|
|
837
|
+
The temporary IP lockout counts failed sign-ins per IP address. Behind a proxy, turn on Koa's proxy mode or **Trust proxy headers**, otherwise all users share the proxy's address. See [Troubleshooting](#troubleshooting).
|
|
838
|
+
|
|
839
|
+
**What happens to my data when I uninstall?**
|
|
840
|
+
Session history lives in the content-type tables `magic_sessions` and `magic_session_revocations`, which Strapi's schema sync manages. The three coordination tables `magic_sm_counters`, `magic_sm_leases` and `magic_sm_cache` are not managed by Strapi and stay until you drop them.
|
|
841
|
+
|
|
842
|
+
---
|
|
843
|
+
|
|
844
|
+
## Migration and upgrading
|
|
845
|
+
|
|
846
|
+
### To the next release (license removal, from 4.10.x)
|
|
847
|
+
|
|
848
|
+
Nothing to do for most apps.
|
|
849
|
+
|
|
850
|
+
1. The Settings › Session Manager › License page is gone; Settings shows **Configuration** and **Analytics**. Bookmarks to `/admin/settings/magic-sessionmanager/license` open an empty settings page, as any unknown settings route does in Strapi 5.61.
|
|
851
|
+
2. The admin routes `GET /magic-sessionmanager/license/status` and `POST /magic-sessionmanager/license/{auto-create,create,ping,store-key}` are removed. Only the plugin's own License page called them. If you scripted them with an admin token, remove those calls.
|
|
852
|
+
3. On first start the plugin deletes its stored `licenseKey`, `lastValidated` and `deviceId` values from the Core Store. Your MaxMind credentials and all settings stay.
|
|
853
|
+
4. The environment variables `MAGIC_LICENSE_SERVER_URL` and `MAGIC_LICENSE_TIMEOUT_MS` are no longer read; you can delete them.
|
|
854
|
+
5. `@strapi/utils` moved from `peerDependencies` to `dependencies`, and `@strapi/design-system`, `@strapi/icons` and `react-intl` are now optional peers. Package managers stop warning about them; no change in your `package.json` is needed.
|
|
855
|
+
|
|
856
|
+
### From 4.8.x or older 4.x
|
|
857
|
+
|
|
858
|
+
Upgrade to the latest 4.x directly. Notable changes on the way:
|
|
859
|
+
|
|
860
|
+
- 4.9.0: `POST /magic-sessionmanager/user/:userId/toggle-block` should get `{ "blocked": true }` or `{ "blocked": false }`; a bodyless toggle still works but is deprecated. Settings reject out-of-range values with field errors instead of clamping them.
|
|
861
|
+
- 4.10.0: three tables (`magic_sm_counters`, `magic_sm_leases`, `magic_sm_cache`) are created at startup; the database user needs the `CREATE` privilege once. Lockout counters start empty after the upgrade. `coordination: { enabled: false }` restores per-process state.
|
|
862
|
+
|
|
863
|
+
### From 3.x (Strapi 4) to 4.x (Strapi 5)
|
|
864
|
+
|
|
865
|
+
Version 4.0.0 moved to Strapi 5 and its Document Service API. Upgrade Strapi itself first with the [official Strapi 5 upgrade guide](https://docs.strapi.io/cms/migration/v4-to-v5/introduction-and-faq), then install the latest 4.x of this plugin, rebuild the admin (`npm run build`) and restart. Sessions are addressed by `documentId` in 4.x; clients that stored numeric session ids must switch to `documentId`.
|
|
866
|
+
|
|
867
|
+
---
|
|
868
|
+
|
|
541
869
|
## Development and tests
|
|
542
870
|
|
|
543
871
|
```bash
|
|
544
872
|
npm ci --legacy-peer-deps
|
|
545
873
|
npm test # node --test tests/*.test.js tests/*.test.mjs
|
|
874
|
+
npm run test:concurrency # 8 processes on one database (SQLite; PostgreSQL with MSM_TEST_PG_URL)
|
|
546
875
|
npm run test:ts:front
|
|
547
876
|
npm run test:ts:back
|
|
548
877
|
npm run build
|
|
@@ -558,14 +887,23 @@ Releases use Conventional Commits and semantic-release on Node.js 22 with npm Tr
|
|
|
558
887
|
|
|
559
888
|
---
|
|
560
889
|
|
|
890
|
+
## Contributing
|
|
891
|
+
|
|
892
|
+
Issues and pull requests are welcome.
|
|
893
|
+
|
|
894
|
+
- Bugs and feature ideas: [open an issue](https://github.com/Schero94/Magic-Sessionmanager/issues/new/choose) (templates included). Questions: [Discussions](https://github.com/Schero94/Magic-Sessionmanager/discussions).
|
|
895
|
+
- Pull requests: branch from `main`, write a failing test first, and use Conventional Commits (`fix:`, `feat:`, `docs:`; a breaking change needs a `BREAKING CHANGE:` footer). Before you push, run `npm run lint`, `npm run format:check`, `npm test`, both type checks and `npm run build && npm run verify`.
|
|
896
|
+
- Use synthetic data only in tests, screenshots and issues: `*.example.test` addresses and IP addresses from `203.0.113.0/24`. Never paste real tokens.
|
|
897
|
+
|
|
898
|
+
---
|
|
899
|
+
|
|
561
900
|
## Maintenance status
|
|
562
901
|
|
|
563
|
-
|
|
902
|
+
Actively maintained for the Strapi 5 line. Releases are cut by semantic-release from `main` using Conventional Commits and published to npm with npm Trusted Publishing (GitHub OIDC). Dependabot proposes weekly dependency updates; patch and minor updates are merged only after lint, tests, both type checks, build and `verify` pass.
|
|
564
903
|
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
- **Dependency advisories:** the recorded high-severity findings come through the Strapi 5 core dependency chain (`braces` GHSA-vfj7-8cjw-p6xm, Zod GHSA-mrhx-c7xc-m3w5 via `@strapi/utils` 5.61.0). No compatible fix exists; the forced npm fix downgrades to Strapi 4, so none was applied.
|
|
904
|
+
Dependency advisories: the remaining high-severity findings come through the Strapi 5 core dependency chain (`braces` GHSA-vfj7-8cjw-p6xm, Zod GHSA-mrhx-c7xc-m3w5 via `@strapi/utils` 5.61.0). The plugin cannot fix them; the forced npm fix would downgrade to Strapi 4, so it is not applied.
|
|
905
|
+
|
|
906
|
+
Version 4.8.0 was published before its acceptance gates closed and has known defects that 4.9.0 fixed (see the [CHANGELOG](CHANGELOG.md)). Use 4.9.0 or later.
|
|
569
907
|
|
|
570
908
|
Report bugs at https://github.com/Schero94/Magic-Sessionmanager/issues.
|
|
571
909
|
|
|
@@ -580,5 +918,3 @@ The admin interface is available in English, German (formal "Sie"), French, Span
|
|
|
580
918
|
## License
|
|
581
919
|
|
|
582
920
|
MIT License. Copyright © 2025 Schero D. See [LICENSE](./LICENSE).
|
|
583
|
-
|
|
584
|
-
**License page.** Settings › Session Manager › License shows whether an optional license key is stored and valid. The key is used for install tracking and support context only; it does not unlock or restrict any feature.
|