strapi-plugin-magic-sessionmanager 4.14.3 → 4.16.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 (30) hide show
  1. package/CHANGELOG.md +87 -0
  2. package/README.md +216 -85
  3. package/dist/admin/{Analytics-CFEgpg-G.mjs → Analytics-D4gsVwL0.mjs} +1 -1
  4. package/dist/admin/{Analytics-DSpn7W5A.js → Analytics-me4qzS0I.js} +1 -1
  5. package/dist/admin/{App-BBne8xI6.mjs → App-BJwtFWxl.mjs} +921 -106
  6. package/dist/admin/{App-UlRrLKcx.js → App-BTG-2Q26.js} +920 -105
  7. package/dist/admin/{OnlineUsersWidget-GFcYyZ9L.js → OnlineUsersWidget-DYS3Vy1Q.js} +1 -1
  8. package/dist/admin/{OnlineUsersWidget-C3YMTEGD.mjs → OnlineUsersWidget-Yd283YDy.mjs} +1 -1
  9. package/dist/admin/{Settings-BbUNvjno.mjs → Settings-DIlvfdjZ.mjs} +427 -83
  10. package/dist/admin/{Settings-DVhW9XHB.js → Settings-TPZ9_75s.js} +425 -81
  11. package/dist/admin/{de-B0CBR1Dw.js → de-BuMw1gBJ.js} +130 -8
  12. package/dist/admin/{de-BlKn1pSD.mjs → de-DB9ldYwN.mjs} +130 -8
  13. package/dist/admin/{en-IT0YTY8f.mjs → en-BbLMPQB3.mjs} +130 -8
  14. package/dist/admin/{en-D0ZGIIjz.js → en-BqGhOJDy.js} +130 -8
  15. package/dist/admin/{es-CWee-XCR.js → es-BaIeckl9.js} +130 -8
  16. package/dist/admin/{es-BCGzaaCh.mjs → es-C5iaiE9G.mjs} +130 -8
  17. package/dist/admin/{fr-xBIH4Byq.mjs → fr-BEvBUCwI.mjs} +130 -8
  18. package/dist/admin/{fr-rQS1M7jE.js → fr-D1YKyTex.js} +130 -8
  19. package/dist/admin/{index-1KmiZSfy.js → index-CgZiLcJ1.js} +13 -10
  20. package/dist/admin/{index-MOJkFXcZ.mjs → index-DUESEUaO.mjs} +13 -10
  21. package/dist/admin/index.js +1 -1
  22. package/dist/admin/index.mjs +1 -1
  23. package/dist/admin/{pt-DWDeIDVa.mjs → pt-DeDih9cR.mjs} +130 -8
  24. package/dist/admin/{pt-C-yTLhnS.js → pt-DtnW-s0V.js} +130 -8
  25. package/dist/admin/riskData-BVs9GpgD.js +26 -0
  26. package/dist/admin/riskData-CI1gm2yI.mjs +27 -0
  27. package/dist/server/index.js +2500 -299
  28. package/dist/server/index.mjs +2500 -299
  29. package/package.json +1 -1
  30. package/scripts/geoip-updater.cjs +58 -15
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "4.14.3",
2
+ "version": "4.16.0",
3
3
  "keywords": [
4
4
  "strapi",
5
5
  "strapi-plugin",
@@ -27,6 +27,14 @@ const SUPPORTED_EDITION_IDS = new Set([
27
27
  const SUPPORTED_MMDB_NAMES = new Set(
28
28
  [...SUPPORTED_EDITION_IDS].map((editionId) => `${editionId}.mmdb`)
29
29
  );
30
+ /**
31
+ * Risk databases (VPN, proxy, Tor, hosting). They live in the same folder
32
+ * but are never used as the location database: GeoIP2 Anonymous IP (paid)
33
+ * and GeoLite2 ASN (free, used for a hosting heuristic only).
34
+ */
35
+ const RISK_EDITION_IDS = new Set(['GeoIP2-Anonymous-IP', 'GeoLite2-ASN']);
36
+ const ALL_EDITION_IDS = new Set([...SUPPORTED_EDITION_IDS, ...RISK_EDITION_IDS]);
37
+ const ALL_MMDB_NAMES = new Set([...ALL_EDITION_IDS].map((editionId) => `${editionId}.mmdb`));
30
38
 
31
39
  /**
32
40
  * Resolves a supported MMDB filename into the plugin's dedicated database
@@ -35,10 +43,15 @@ const SUPPORTED_MMDB_NAMES = new Set(
35
43
  *
36
44
  * @param {string} [value] Filename or canonical path to an MMDB file
37
45
  * @param {string} [directory] Dedicated database directory
46
+ * @param {Set<string>} [allowedNames] Accepted filenames (location databases by default)
38
47
  * @returns {string} Lexically resolved MMDB destination
39
48
  * @throws {Error} When the destination escapes the dedicated directory
40
49
  */
41
- function resolveDatabaseTarget(value, directory = DEFAULT_GEOIP_DIRECTORY) {
50
+ function resolveDatabaseTarget(
51
+ value,
52
+ directory = DEFAULT_GEOIP_DIRECTORY,
53
+ allowedNames = SUPPORTED_MMDB_NAMES
54
+ ) {
42
55
  const root = path.resolve(directory);
43
56
  if (value !== undefined && typeof value !== 'string') {
44
57
  throw new Error('GeoIP database path must be a string');
@@ -59,7 +72,7 @@ function resolveDatabaseTarget(value, directory = DEFAULT_GEOIP_DIRECTORY) {
59
72
  filename = requested;
60
73
  }
61
74
 
62
- if (!SUPPORTED_MMDB_NAMES.has(filename)) {
75
+ if (!allowedNames.has(filename)) {
63
76
  throw new Error('GeoIP database path must use a supported MMDB filename');
64
77
  }
65
78
 
@@ -73,12 +86,17 @@ function resolveDatabaseTarget(value, directory = DEFAULT_GEOIP_DIRECTORY) {
73
86
  *
74
87
  * @param {string} [value] Filename or canonical path to an MMDB file
75
88
  * @param {string} [directory] Dedicated database directory
89
+ * @param {Set<string>} [allowedNames] Accepted filenames
76
90
  * @returns {Promise<string>} Canonical MMDB destination
77
91
  * @throws {Error} When the directory, database or sidecar is unsafe
78
92
  */
79
- async function canonicalizeDatabaseTarget(value, directory = DEFAULT_GEOIP_DIRECTORY) {
93
+ async function canonicalizeDatabaseTarget(
94
+ value,
95
+ directory = DEFAULT_GEOIP_DIRECTORY,
96
+ allowedNames = SUPPORTED_MMDB_NAMES
97
+ ) {
80
98
  const root = path.resolve(directory);
81
- const target = resolveDatabaseTarget(value, root);
99
+ const target = resolveDatabaseTarget(value, root, allowedNames);
82
100
  await fs.mkdir(root, { recursive: true, mode: 0o700 });
83
101
 
84
102
  const rootStat = await fs.lstat(root);
@@ -113,10 +131,11 @@ async function canonicalizeDatabaseTarget(value, directory = DEFAULT_GEOIP_DIREC
113
131
  *
114
132
  * @param {string} value Requested edition identifier
115
133
  * @param {string} [fallback=DEFAULT_EDITION_ID] Fallback edition
134
+ * @param {Set<string>} [allowed] Accepted editions (location editions by default)
116
135
  * @returns {string} Supported edition identifier
117
136
  */
118
- function normalizeEditionId(value, fallback = DEFAULT_EDITION_ID) {
119
- return SUPPORTED_EDITION_IDS.has(value) ? value : fallback;
137
+ function normalizeEditionId(value, fallback = DEFAULT_EDITION_ID, allowed = SUPPORTED_EDITION_IDS) {
138
+ return allowed.has(value) ? value : fallback;
120
139
  }
121
140
 
122
141
  /**
@@ -176,13 +195,27 @@ function resolveConfig(env = process.env, argv = process.argv.slice(2), override
176
195
  env.MAGIC_SESSIONMANAGER_GEOIP_DATABASE ||
177
196
  env.GEOIP_DATABASE_PATH ||
178
197
  '';
198
+ const requestedEdition = overrides.editionId || env.MAXMIND_EDITION_ID;
199
+ const databaseDirectory = overrides.databaseDirectory || DEFAULT_GEOIP_DIRECTORY;
200
+ // A risk edition always goes to its own file name; the location path
201
+ // settings never apply to it.
202
+ if (RISK_EDITION_IDS.has(requestedEdition)) {
203
+ return {
204
+ accountId: overrides.accountId || env.MAXMIND_ACCOUNT_ID || env.MAXMIND_USER_ID || '',
205
+ licenseKey: overrides.licenseKey || env.MAXMIND_LICENSE_KEY || '',
206
+ editionId: requestedEdition,
207
+ outputPath: resolveDatabaseTarget(
208
+ `${requestedEdition}.mmdb`,
209
+ databaseDirectory,
210
+ ALL_MMDB_NAMES
211
+ ),
212
+ mmdbFileName: `${requestedEdition}.mmdb`,
213
+ force,
214
+ };
215
+ }
179
216
  const editionId = normalizeEditionId(
180
- overrides.editionId ||
181
- env.MAXMIND_EDITION_ID ||
182
- inferEditionIdFromPath(configuredOutputPath) ||
183
- DEFAULT_EDITION_ID
217
+ requestedEdition || inferEditionIdFromPath(configuredOutputPath) || DEFAULT_EDITION_ID
184
218
  );
185
- const databaseDirectory = overrides.databaseDirectory || DEFAULT_GEOIP_DIRECTORY;
186
219
  const outputPath = resolveDatabaseTarget(
187
220
  configuredOutputPath || `${editionId}.mmdb`,
188
221
  databaseDirectory
@@ -320,7 +353,9 @@ async function fetchHead(url, authHeader) {
320
353
  });
321
354
 
322
355
  if (!response.ok) {
323
- throw new Error(`MaxMind HEAD failed with HTTP ${response.status}`);
356
+ const error = new Error(`MaxMind HEAD failed with HTTP ${response.status}`);
357
+ error.httpStatus = response.status;
358
+ throw error;
324
359
  }
325
360
 
326
361
  return {
@@ -348,7 +383,9 @@ async function fetchArchive(url, authHeader) {
348
383
  });
349
384
 
350
385
  if (!response.ok) {
351
- throw new Error(`MaxMind download failed with HTTP ${response.status}`);
386
+ const error = new Error(`MaxMind download failed with HTTP ${response.status}`);
387
+ error.httpStatus = response.status;
388
+ throw error;
352
389
  }
353
390
 
354
391
  return Buffer.from(await response.arrayBuffer());
@@ -405,8 +442,12 @@ async function updateGeoIpDatabase(config = resolveConfig()) {
405
442
  throw new Error('MAXMIND_ACCOUNT_ID and MAXMIND_LICENSE_KEY are required');
406
443
  }
407
444
 
408
- const editionId = normalizeEditionId(config.editionId);
409
- const outputPath = await canonicalizeDatabaseTarget(config.outputPath);
445
+ const editionId = normalizeEditionId(config.editionId, DEFAULT_EDITION_ID, ALL_EDITION_IDS);
446
+ const outputPath = await canonicalizeDatabaseTarget(
447
+ config.outputPath,
448
+ DEFAULT_GEOIP_DIRECTORY,
449
+ ALL_MMDB_NAMES
450
+ );
410
451
  const mmdbFileName = `${editionId}.mmdb`;
411
452
  if (path.basename(outputPath) !== mmdbFileName) {
412
453
  throw new Error('GeoIP database filename must match the selected edition');
@@ -467,6 +508,8 @@ async function updateGeoIpDatabase(config = resolveConfig()) {
467
508
  }
468
509
 
469
510
  module.exports = {
511
+ ALL_MMDB_NAMES,
512
+ RISK_EDITION_IDS,
470
513
  DEFAULT_EDITION_ID,
471
514
  DEFAULT_GEOIP_DIRECTORY,
472
515
  DEFAULT_MMDB_NAME,