diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 6e3a75e..9a1941d 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -180,3 +180,49 @@ jobs: run: | node --test tests/isolated-http-access.test.js SESSION_HTTP_MODE=refresh node --test tests/isolated-http-access.test.js + + strapi-floor: + name: Real Strapi HTTP suites on the peer floor (Strapi 5.50.0) + runs-on: ubuntu-latest + timeout-minutes: 25 + + steps: + - name: Checkout code + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + persist-credentials: false + + - name: Setup Node.js + uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0 + with: + node-version: '22' + cache: npm + + - name: Install dependencies + run: npm ci --legacy-peer-deps + + # package.json peers: @strapi/strapi and @strapi/plugin-users-permissions ^5.50.0. + # 5.50.0 added sessionManager listSessions/revokeSessionById and admin session + # metadata; the suites below fail on 5.49.0 and older. + - name: Install the Strapi 5.50.0 floor host + run: | + mkdir -p "$RUNNER_TEMP/strapi-floor" + cd "$RUNNER_TEMP/strapi-floor" + echo '{"name":"strapi-floor-host","version":"0.0.0","private":true}' > package.json + npm install --no-audit --no-fund --legacy-peer-deps @strapi/strapi@5.50.0 @strapi/plugin-users-permissions@5.50.0 better-sqlite3@13 jsonwebtoken + for pkg in strapi core admin plugin-users-permissions; do + version=$(node -p "require('./node_modules/@strapi/$pkg/package.json').version") + echo "@strapi/$pkg $version" + test "$version" = 5.50.0 + done + + - name: HTTP suites on Strapi 5.50.0 + env: + SESSION_HTTP_REQUIRED: '1' + SESSION_HTTP_STRAPI_NODE_MODULES: ${{ runner.temp }}/strapi-floor/node_modules + run: | + node --test tests/isolated-http-access.test.js + SESSION_HTTP_MODE=refresh node --test tests/isolated-http-access.test.js + SESSION_HTTP_FALLBACK=1 node --test tests/isolated-http-access.test.js + node --test tests/isolated-admin-sessions-http.test.js + node --test tests/isolated-native-capture-http.test.js diff --git a/CHANGELOG.md b/CHANGELOG.md index 5c6b6ce..a09da45 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,24 @@ +## [Unreleased] + +Release type: patch (`fix`). This corrects an untested compatibility claim; it is not a breaking change, because the plugin never worked fully on the Strapi versions now excluded. + +### Fixed + +* **Strapi peer floor corrected from `^5.0.0` to `^5.50.0`** (`@strapi/strapi` and `@strapi/plugin-users-permissions`). The old range was never tested. Strapi 5.50.0 added the session-manager methods the plugin calls (`listSessions`, `revokeSessionById`) and the `metadata` column of `admin::session` ([strapi/strapi#26628](https://github.com/strapi/strapi/pull/26628)). Measured with the real-HTTP suites on isolated hosts: on 5.24.0, 5.30.0, 5.40.0, 5.45.0 and 5.49.0, sign-in with `jwtManagement: 'refresh'` fails closed with 503, session list and revoke routes fail, and the Admin panel sessions routes return 500 in both JWT modes; 5.0.4 and 5.23.6 have no session manager or `admin::session` at all; 5.0.0 to 5.0.3 declare Node.js 20 or older, outside this plugin's `engines`. On 5.50.0 and 5.62.0 every suite passes. +* The plugin logs one clear error at start-up on Strapi older than 5.50.0 (`Strapi 5.x.y is not supported: Magic Session Manager requires Strapi 5.50.0 or later …`) instead of failing later on single requests. +* README badge, Compatibility table and project site now say Strapi 5.50+. + +### Upgrade note + +* Strapi 5.50.0 or later: nothing to do. +* Strapi older than 5.50.0: upgrade Strapi first (`npx @strapi/upgrade minor`), rebuild the admin and restart. npm 7+ refuses to install this release next to an older Strapi because of the peer range; until you upgrade Strapi, stay on your current plugin version. + +### Tests + +* New CI job `strapi-floor` installs Strapi 5.50.0 and Users & Permissions 5.50.0 into a separate directory and runs the HTTP access suite (legacy, refresh, fallback logout), the admin panel sessions suite and the native session capture suite against it. +* `tests/strapi-version-floor.test.js` checks the floor constant, the start-up error, that the peers and the CI job name the same floor. +* The native capture suite's provider-callback case now also sends the provider token in the query string, which Strapi 5.50 reads (5.62 reads the grant session), so it runs on both versions. + # [4.14.0](https://github.com/Schero94/Magic-Sessionmanager/compare/v4.13.1...v4.14.0) (2026-11-18) diff --git a/README.md b/README.md index 530762a..d32f4d7 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ Free and open source under the MIT license. Every feature works without an accou [![npm downloads](https://img.shields.io/npm/dm/strapi-plugin-magic-sessionmanager.svg)](https://www.npmjs.com/package/strapi-plugin-magic-sessionmanager) [![CI build status](https://img.shields.io/github/actions/workflow/status/Schero94/Magic-Sessionmanager/test.yml?branch=main&label=CI&logo=github)](https://github.com/Schero94/Magic-Sessionmanager/actions/workflows/test.yml?query=branch%3Amain) [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://github.com/Schero94/Magic-Sessionmanager/blob/main/LICENSE) -[![Strapi 5.0+](https://img.shields.io/badge/Strapi-5.0%2B-4945FF.svg)](https://github.com/Schero94/Magic-Sessionmanager#compatibility) +[![Strapi 5.50+](https://img.shields.io/badge/Strapi-5.50%2B-4945FF.svg)](https://github.com/Schero94/Magic-Sessionmanager#compatibility) [![Documentation site](https://img.shields.io/badge/docs-project%20site-6d4aff.svg)](https://schero94.github.io/Magic-Sessionmanager/) 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](https://github.com/Schero94/Magic-Sessionmanager/blob/main/CHANGELOG.md) · [Report a bug](https://github.com/Schero94/Magic-Sessionmanager/issues/new/choose) · [Discussions](https://github.com/Schero94/Magic-Sessionmanager/discussions) @@ -224,7 +224,7 @@ Shown on the edit view of a Users & Permissions user only. ### Online users widget -Strapi 5.13 and later. Four tiles: **Online users** (of all registered users), **Active sessions**, **Idle sessions** and **Blocked users**, plus a link **Open Session Manager**. The widget refreshes every 30 seconds. +Part of every supported Strapi version (the widgets API exists since Strapi 5.13). Four tiles: **Online users** (of all registered users), **Active sessions**, **Idle sessions** and **Blocked users**, plus a link **Open Session Manager**. The widget refreshes every 30 seconds. ### Settings › Session Manager @@ -248,17 +248,17 @@ Two links: **Configuration** and **Analytics**. ## Compatibility -| Item | Supported | -| -------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -| Strapi | 5 (`@strapi/strapi` peer range `^5.0.0`). Acceptance host: Strapi 5.62.0. | -| Node.js | `^22.22.2 \|\| >=24.15.0` (`engines.node`) | -| Users & Permissions | `jwtManagement: 'refresh'` and `'legacy-support'` | -| Homepage widget | Strapi 5.13 and later (older versions have no widgets API; the rest works) | -| Admin panel sessions | Strapi 5 with Strapi's session manager (`strapi.sessionManager`, admin origin); tested with 5.62.0. Without it the view says it is not available and the sign-out routes return 503. | -| 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. | -| 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. | -| Package managers | npm, Yarn 1 and pnpm. Installing into a fresh Strapi 5.61 app prints no warning about this plugin. | -| Databases | PostgreSQL, MySQL, SQLite (several processes need PostgreSQL or MySQL, see [Running several instances](#running-several-instances-railway-replicas-pm2-cluster)). | +| Item | Supported | +| -------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| Strapi | 5.50.0 and later 5.x (`@strapi/strapi` peer range `^5.50.0`). Tested in CI on 5.50.0 (floor) and 5.62.0 (acceptance host). Strapi 5.0 to 5.49 are not supported, see [Upgrading › Strapi older than 5.50](#strapi-older-than-550). | +| Node.js | `^22.22.2 \|\| >=24.15.0` (`engines.node`) | +| Users & Permissions | `jwtManagement: 'refresh'` and `'legacy-support'` | +| Homepage widget | Included (Strapi's widgets API exists since 5.13). | +| Admin panel sessions | Uses Strapi's session manager (`strapi.sessionManager('admin')`) and the device label in `admin::session` metadata, both available from Strapi 5.50.0; tested on 5.50.0 and 5.62.0. | +| Required peers | `@strapi/strapi` `^5.50.0`, `@strapi/plugin-users-permissions` `^5.50.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. | +| 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. | +| Package managers | npm, Yarn 1 and pnpm. Installing into a fresh Strapi 5.61 app prints no warning about this plugin. | +| Databases | PostgreSQL, MySQL, SQLite (several processes need PostgreSQL or MySQL, see [Running several instances](#running-several-instances-railway-replicas-pm2-cluster)). | --- @@ -920,6 +920,18 @@ Session history lives in the content-type tables `magic_sessions` and `magic_ses ## Migration and upgrading +### Strapi older than 5.50 + +Earlier releases said "Strapi 5.0+" (`^5.0.0`) without testing older versions. The real floor is **Strapi 5.50.0**: the plugin calls `listSessions` and `revokeSessionById` on Strapi's session manager and reads the device label in `admin::session` metadata, which Strapi added in 5.50.0 ([strapi/strapi#26628](https://github.com/strapi/strapi/pull/26628)). Measured with this repository's real-HTTP suites: + +| Strapi | Result | +| ---------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| 5.0.0 to 5.23.x | No session manager and no `admin::session` table (added in 5.24.0). 5.0.0 to 5.0.3 also declare Node.js 20 or older, outside this plugin's `engines`. | +| 5.24.0 to 5.49.x | With `jwtManagement: 'refresh'`, sign-in fails closed with 503 and session routes fail; the Admin panel view returns 500 in both modes. | +| 5.50.0, 5.62.0 | All suites pass (both JWT modes, the fallback logout, admin panel sessions, native session capture); the packed plugin installs without peer warnings and the admin panel builds on 5.50.0. | + +On Strapi below 5.50.0 the plugin logs one error at start-up (`Strapi 5.x.y is not supported: Magic Session Manager requires Strapi 5.50.0 or later …`). Upgrade Strapi to 5.50.0 or later ([Strapi upgrade tool](https://docs.strapi.io/cms/upgrade-tool)), rebuild the admin and restart. If you cannot upgrade Strapi yet, stay on your current plugin version; it never worked fully on those versions either. + ### To the next release (license removal, from 4.10.x) Nothing to do for most apps. @@ -963,6 +975,8 @@ SESSION_HTTP_REQUIRED=1 SESSION_HTTP_STRAPI_NODE_MODULES=$PWD/node_modules node # PostgreSQL: add SESSION_HTTP_DB=postgres MSM_TEST_PG_URL=postgres://user:pass@127.0.0.1:5432/db ``` +CI runs the same suites a second time against Strapi 5.50.0, the peer floor, installed into a separate directory (`SESSION_HTTP_STRAPI_NODE_MODULES=/node_modules`), so the floor stays tested. + The admin panel suite signs synthetic admins in through `POST /admin/login` and checks listing, signing out one browser and everywhere, self sign-out, the Super Admin guard, RBAC denials, the rate limit, that the next request and the refresh are rejected, and that admin sessions never reach the app-user numbers. Quick manual check: sign in to your app as an end user (`POST /api/auth/local`), open Session Manager and find the session as **Active**, click **End session** and confirm, then call any Content API route with the same token: it returns 401 and the row shows **Ended · Ended manually**. diff --git a/docs/site/index.html b/docs/site/index.html index de1da08..9d4b070 100644 --- a/docs/site/index.html +++ b/docs/site/index.html @@ -114,8 +114,8 @@

See who is signed in. End access in one click.

/> Strapi 5.0+ Compatibility Strapi - 5 (@strapi/strapi ^5.0.0); acceptance host Strapi 5.62.0 + + 5.50.0 and later 5.x (@strapi/strapi ^5.50.0); tested on 5.50.0 and + 5.62.0 (acceptance host) + Node.js @@ -1125,7 +1128,7 @@

Compatibility

Homepage widget - Strapi 5.13 and later + Included Admin languages diff --git a/package-lock.json b/package-lock.json index 5fc35fd..1d713e5 100644 --- a/package-lock.json +++ b/package-lock.json @@ -51,8 +51,8 @@ "peerDependencies": { "@strapi/design-system": "^2.0.0", "@strapi/icons": "^2.0.0", - "@strapi/plugin-users-permissions": "^5.0.0", - "@strapi/strapi": "^5.0.0", + "@strapi/plugin-users-permissions": "^5.50.0", + "@strapi/strapi": "^5.50.0", "react": "^18.0.0", "react-dom": "^18.0.0", "react-intl": "^6.0.0", diff --git a/package.json b/package.json index 64033d3..49ebad6 100644 --- a/package.json +++ b/package.json @@ -101,8 +101,8 @@ "peerDependencies": { "@strapi/design-system": "^2.0.0", "@strapi/icons": "^2.0.0", - "@strapi/plugin-users-permissions": "^5.0.0", - "@strapi/strapi": "^5.0.0", + "@strapi/plugin-users-permissions": "^5.50.0", + "@strapi/strapi": "^5.50.0", "react": "^18.0.0", "react-dom": "^18.0.0", "react-intl": "^6.0.0", diff --git a/server/src/register.js b/server/src/register.js index 95eb75a..fb2bafe 100644 --- a/server/src/register.js +++ b/server/src/register.js @@ -3,12 +3,15 @@ const { createLogger } = require('./utils/logger'); const { createContentApiPermissionsLifecycle } = require('./utils/content-api-permissions'); const { isCallerRevocationScope } = require('./utils/block-revocation-scope'); +const { checkStrapiVersion } = require('./utils/strapi-version'); const USER_UID = 'plugin::users-permissions.user'; /** * Plugin register hook. * + * - Logs one error when the running Strapi is older than the supported floor + * (`MIN_STRAPI_VERSION`, 5.50.0). * - Registers the `access` RBAC action for admin access control and the * `admin-sessions.read` / `admin-sessions.revoke` actions for the Strapi * admin panel sessions view. @@ -24,6 +27,7 @@ module.exports = async ({ strapi }) => { const log = createLogger(strapi); log.info('[START] Plugin registration starting...'); + checkStrapiVersion(strapi, log); strapi.admin.services.permission.actionProvider.registerMany([ { diff --git a/server/src/utils/strapi-version.js b/server/src/utils/strapi-version.js new file mode 100644 index 0000000..9c27c17 --- /dev/null +++ b/server/src/utils/strapi-version.js @@ -0,0 +1,66 @@ +'use strict'; + +/** + * Oldest Strapi release this plugin works on. Strapi 5.50.0 added the + * session-manager methods the plugin calls (`listSessions`, + * `revokeSessionById`) and the `metadata` column of `admin::session` + * ("active devices session management", strapi/strapi#26628). On older + * releases the refresh-mode sign-in fails closed with 503 and the admin panel + * sessions routes return 500 (measured with the real-HTTP suites on 5.24.0, + * 5.30.0, 5.40.0, 5.45.0 and 5.49.0). Keep in sync with the `@strapi/strapi` + * and `@strapi/plugin-users-permissions` peer ranges and the CI floor job. + */ +const MIN_STRAPI_VERSION = '5.50.0'; + +/** + * Parses a plain `major.minor.patch` version (pre-release suffix ignored). + * + * @param {unknown} version Version string. + * @returns {number[]|null} `[major, minor, patch]`, or null when not a version. + */ +function parseVersion(version) { + if (typeof version !== 'string') return null; + const match = version.trim().match(/^(\d+)\.(\d+)\.(\d+)/); + return match ? match.slice(1, 4).map(Number) : null; +} + +/** + * Tells whether a Strapi version is inside the supported range + * `^MIN_STRAPI_VERSION` (same major, not older than the floor). + * + * @param {unknown} version Running Strapi version, e.g. `strapi.config.get('info.strapi')`. + * @returns {boolean|null} true or false, or null when the version is unknown. + */ +function isSupportedStrapiVersion(version) { + const current = parseVersion(version); + if (!current) return null; + const floor = /** @type {number[]} */ (parseVersion(MIN_STRAPI_VERSION)); + if (current[0] !== floor[0]) return false; + for (let i = 1; i < 3; i += 1) { + if (current[i] !== floor[i]) return current[i] > floor[i]; + } + return true; +} + +/** + * Logs one error at start-up when the running Strapi is older than the floor. + * It does not stop Strapi: the host decides, and the message says what to do. + * + * @param {any} strapi Strapi instance (reads `info.strapi` from its config). + * @param {{error: Function}} log Plugin logger. + * @returns {boolean|null} The result of {@link isSupportedStrapiVersion}. + * @sideeffect Writes one error log line on an unsupported version. + */ +function checkStrapiVersion(strapi, log) { + const version = + typeof strapi?.config?.get === 'function' ? strapi.config.get('info.strapi') : undefined; + const supported = isSupportedStrapiVersion(version); + if (supported === false) { + log.error( + `Strapi ${version} is not supported: Magic Session Manager requires Strapi ${MIN_STRAPI_VERSION} or later (session-manager listSessions/revokeSessionById and admin session metadata). Upgrade Strapi; sign-in in refresh mode and the admin panel sessions view fail on this version.` + ); + } + return supported; +} + +module.exports = { MIN_STRAPI_VERSION, isSupportedStrapiVersion, checkStrapiVersion }; diff --git a/tests/isolated-native-capture-http.test.js b/tests/isolated-native-capture-http.test.js index 21d521c..d668db0 100644 --- a/tests/isolated-native-capture-http.test.js +++ b/tests/isolated-native-capture-http.test.js @@ -395,7 +395,13 @@ test( }); await t.test('provider callback is linked', async () => { - const result = await request('GET', api('/auth/synthetic/callback')); + // Strapi 5.62 reads the grant response from the session (injected above); + // Strapi 5.50 reads the provider token from the query string. Send both so + // the suite runs on the peer floor and on the current release. + const result = await request( + 'GET', + api('/auth/synthetic/callback?access_token=synthetic-provider-token') + ); assert.equal(result.status, 200, JSON.stringify(result.body?.error || null)); await assertLinked(await sessionOfRefresh(result.body.refreshToken), 'provider callback'); }); diff --git a/tests/strapi-version-floor.test.js b/tests/strapi-version-floor.test.js new file mode 100644 index 0000000..e6b715e --- /dev/null +++ b/tests/strapi-version-floor.test.js @@ -0,0 +1,96 @@ +'use strict'; + +// Strapi peer floor. The real-HTTP suites fail below Strapi 5.50.0: the +// plugin calls `listSessions` / `revokeSessionById` on Strapi's session +// manager and reads the `metadata` column of `admin::session`, all added in +// Strapi 5.50.0 ("active devices session management", strapi/strapi#26628). +// The peer range, the start-up check and the CI floor job must agree. +const assert = require('node:assert/strict'); +const fs = require('node:fs'); +const path = require('node:path'); +const test = require('node:test'); + +const register = require('../server/src/register'); +const { + MIN_STRAPI_VERSION, + isSupportedStrapiVersion, +} = require('../server/src/utils/strapi-version'); + +const root = path.resolve(__dirname, '..'); +const pkg = JSON.parse(fs.readFileSync(path.join(root, 'package.json'), 'utf8')); + +/** + * Minimal Strapi double for the register hook, with a given runtime version. + * + * @param {string|undefined} version Value of `info.strapi`. + * @returns {{strapi: object, errors: string[]}} The double and the error lines it received. + */ +function fakeStrapi(version) { + const errors = []; + const strapi = { + admin: { services: { permission: { actionProvider: { registerMany() {} } } } }, + config: { get: (key, fallback) => (key === 'info.strapi' ? version : fallback) }, + contentType: () => ({ attributes: {} }), + db: { lifecycles: { subscribe() {} } }, + plugin: () => ({ service: () => ({}) }), + log: { + debug() {}, + info() {}, + warn() {}, + error: (message) => errors.push(String(message)), + }, + }; + return { strapi, errors }; +} + +test('the floor is Strapi 5.50.0', () => { + assert.equal(MIN_STRAPI_VERSION, '5.50.0'); +}); + +test('versions below the floor are unsupported, the floor and later 5.x are supported', () => { + for (const version of ['5.0.0', '5.13.0', '5.24.0', '5.49.0', '5.49.9']) + assert.equal(isSupportedStrapiVersion(version), false, version); + for (const version of ['5.50.0', '5.50.1', '5.62.0', '5.100.0']) + assert.equal(isSupportedStrapiVersion(version), true, version); + assert.equal(isSupportedStrapiVersion('6.0.0'), false, 'Strapi 6 is not a tested peer'); +}); + +test('an unknown or malformed version is not judged', () => { + for (const version of [undefined, null, '', 'latest', 5]) + assert.equal(isSupportedStrapiVersion(version), null, String(version)); +}); + +test('register logs one clear error on a Strapi version below the floor', async () => { + const { strapi, errors } = fakeStrapi('5.49.0'); + await register({ strapi }); + const floorErrors = errors.filter((line) => line.includes('5.50.0')); + assert.equal(floorErrors.length, 1, errors.join('\n')); + assert.match(floorErrors[0], /Strapi 5\.49\.0/); + assert.match(floorErrors[0], /requires Strapi 5\.50\.0 or later/); +}); + +test('register logs no floor error on a supported or unknown Strapi version', async () => { + for (const version of ['5.50.0', '5.62.0', undefined]) { + const { strapi, errors } = fakeStrapi(version); + await register({ strapi }); + assert.deepEqual( + errors.filter((line) => line.includes('5.50.0')), + [], + String(version) + ); + } +}); + +test('the Strapi peers declare the same floor', () => { + assert.equal(pkg.peerDependencies['@strapi/strapi'], `^${MIN_STRAPI_VERSION}`); + assert.equal(pkg.peerDependencies['@strapi/plugin-users-permissions'], `^${MIN_STRAPI_VERSION}`); +}); + +test('CI installs and tests the floor', () => { + const workflow = fs.readFileSync(path.join(root, '.github/workflows/test.yml'), 'utf8'); + assert.match(workflow, new RegExp(`@strapi/strapi@${MIN_STRAPI_VERSION.replace(/\./g, '\\.')}`)); + assert.match( + workflow, + new RegExp(`@strapi/plugin-users-permissions@${MIN_STRAPI_VERSION.replace(/\./g, '\\.')}`) + ); +});