strapi-plugin-magic-sessionmanager 4.14.3 → 4.15.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 +48 -0
- package/README.md +124 -77
- package/dist/admin/{Analytics-DSpn7W5A.js → Analytics-Dbs5QXLb.js} +1 -1
- package/dist/admin/{Analytics-CFEgpg-G.mjs → Analytics-HK6_TEmk.mjs} +1 -1
- package/dist/admin/{App-UlRrLKcx.js → App-7SxOBJP5.js} +59 -26
- package/dist/admin/{App-BBne8xI6.mjs → App-BOFzZ5d8.mjs} +59 -26
- package/dist/admin/{OnlineUsersWidget-C3YMTEGD.mjs → OnlineUsersWidget-CoCxnww-.mjs} +1 -1
- package/dist/admin/{OnlineUsersWidget-GFcYyZ9L.js → OnlineUsersWidget-Dns_74xJ.js} +1 -1
- package/dist/admin/{Settings-DVhW9XHB.js → Settings-B6CrR-07.js} +257 -64
- package/dist/admin/{Settings-BbUNvjno.mjs → Settings-DYRShQ8W.mjs} +258 -65
- package/dist/admin/{de-BlKn1pSD.mjs → de-B3mPtxsW.mjs} +39 -7
- package/dist/admin/{de-B0CBR1Dw.js → de-bkkCvSxX.js} +39 -7
- package/dist/admin/{en-IT0YTY8f.mjs → en-BnU8BNkN.mjs} +39 -7
- package/dist/admin/{en-D0ZGIIjz.js → en-DMICyIow.js} +39 -7
- package/dist/admin/{es-BCGzaaCh.mjs → es-BxMgfJ1Y.mjs} +39 -7
- package/dist/admin/{es-CWee-XCR.js → es-OSzHGRIu.js} +39 -7
- package/dist/admin/{fr-rQS1M7jE.js → fr-Bu_8miJ4.js} +39 -7
- package/dist/admin/{fr-xBIH4Byq.mjs → fr-WPrbtx8k.mjs} +39 -7
- package/dist/admin/{index-1KmiZSfy.js → index-CNSJITRX.js} +9 -9
- package/dist/admin/{index-MOJkFXcZ.mjs → index-lnZBc5n0.mjs} +9 -9
- package/dist/admin/index.js +1 -1
- package/dist/admin/index.mjs +1 -1
- package/dist/admin/{pt-C-yTLhnS.js → pt-B08xnb0K.js} +39 -7
- package/dist/admin/{pt-DWDeIDVa.mjs → pt-C41KyEDN.mjs} +39 -7
- package/dist/admin/riskData-BVs9GpgD.js +26 -0
- package/dist/admin/riskData-CI1gm2yI.mjs +27 -0
- package/dist/server/index.js +565 -178
- package/dist/server/index.mjs +565 -178
- package/package.json +1 -1
- package/scripts/geoip-updater.cjs +58 -15
package/package.json
CHANGED
|
@@ -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(
|
|
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 (!
|
|
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(
|
|
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
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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(
|
|
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,
|