strapi-plugin-magic-sessionmanager 4.14.2 → 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.
Files changed (30) hide show
  1. package/CHANGELOG.md +64 -0
  2. package/README.md +151 -79
  3. package/dist/admin/{Analytics-Box2STtg.js → Analytics-Dbs5QXLb.js} +1 -1
  4. package/dist/admin/{Analytics-DfDdcjMe.mjs → Analytics-HK6_TEmk.mjs} +1 -1
  5. package/dist/admin/{App-DzxXcTYs.js → App-7SxOBJP5.js} +63 -29
  6. package/dist/admin/{App-B2JIOiNM.mjs → App-BOFzZ5d8.mjs} +64 -30
  7. package/dist/admin/{OnlineUsersWidget-BOd7p_MF.mjs → OnlineUsersWidget-CoCxnww-.mjs} +1 -1
  8. package/dist/admin/{OnlineUsersWidget-D4M4D6rm.js → OnlineUsersWidget-Dns_74xJ.js} +1 -1
  9. package/dist/admin/{Settings-DNgH9qRy.js → Settings-B6CrR-07.js} +257 -64
  10. package/dist/admin/{Settings-BFdr77zD.mjs → Settings-DYRShQ8W.mjs} +258 -65
  11. package/dist/admin/{de-BlKn1pSD.mjs → de-B3mPtxsW.mjs} +39 -7
  12. package/dist/admin/{de-B0CBR1Dw.js → de-bkkCvSxX.js} +39 -7
  13. package/dist/admin/{en-IT0YTY8f.mjs → en-BnU8BNkN.mjs} +39 -7
  14. package/dist/admin/{en-D0ZGIIjz.js → en-DMICyIow.js} +39 -7
  15. package/dist/admin/{es-BCGzaaCh.mjs → es-BxMgfJ1Y.mjs} +39 -7
  16. package/dist/admin/{es-CWee-XCR.js → es-OSzHGRIu.js} +39 -7
  17. package/dist/admin/{fr-rQS1M7jE.js → fr-Bu_8miJ4.js} +39 -7
  18. package/dist/admin/{fr-xBIH4Byq.mjs → fr-WPrbtx8k.mjs} +39 -7
  19. package/dist/admin/{index-CmW1DJ0c.js → index-CNSJITRX.js} +9 -9
  20. package/dist/admin/{index-C2SrNW6I.mjs → index-lnZBc5n0.mjs} +9 -9
  21. package/dist/admin/index.js +1 -1
  22. package/dist/admin/index.mjs +1 -1
  23. package/dist/admin/{pt-C-yTLhnS.js → pt-B08xnb0K.js} +39 -7
  24. package/dist/admin/{pt-DWDeIDVa.mjs → pt-C41KyEDN.mjs} +39 -7
  25. package/dist/admin/riskData-BVs9GpgD.js +26 -0
  26. package/dist/admin/riskData-CI1gm2yI.mjs +27 -0
  27. package/dist/server/index.js +565 -178
  28. package/dist/server/index.mjs +565 -178
  29. package/package.json +3 -3
  30. package/scripts/geoip-updater.cjs +58 -15
@@ -1473,10 +1473,75 @@ var require_rejection_cache = __commonJS({
1473
1473
  }
1474
1474
  });
1475
1475
 
1476
+ // server/src/utils/risk-data.js
1477
+ var require_risk_data = __commonJS({
1478
+ "server/src/utils/risk-data.js"(exports2, module2) {
1479
+ "use strict";
1480
+ var RISK_SOURCES = Object.freeze(["anonymous-ip", "asn-heuristic"]);
1481
+ var SUSPICIOUS_SCORE_BELOW = 70;
1482
+ var REJECT_SCORE_BELOW = 50;
1483
+ function noRiskData() {
1484
+ return {
1485
+ isVpn: false,
1486
+ isProxy: false,
1487
+ isThreat: false,
1488
+ isAnonymous: false,
1489
+ isTor: false,
1490
+ isHosting: false,
1491
+ securityScore: null,
1492
+ riskLevel: "Unknown",
1493
+ riskSource: null
1494
+ };
1495
+ }
1496
+ function hasRiskData(geoData) {
1497
+ return Boolean(geoData) && RISK_SOURCES.includes(geoData.riskSource);
1498
+ }
1499
+ function calculateSecurityScore({ isVpn, isProxy, isThreat, isAnonymous, isTor, isHosting }) {
1500
+ let score = 100;
1501
+ if (isTor) score -= 50;
1502
+ if (isThreat) score -= 40;
1503
+ if (isVpn) score -= 20;
1504
+ if (isHosting) score -= 20;
1505
+ if (isProxy) score -= 15;
1506
+ if (isAnonymous) score -= 10;
1507
+ return Math.max(0, score);
1508
+ }
1509
+ function getRiskLevel({ isVpn, isProxy, isThreat, isTor, isHosting }) {
1510
+ if (isThreat || isTor) return "High";
1511
+ if (isVpn && isProxy) return "Medium-High";
1512
+ if (isVpn || isProxy || isHosting) return "Medium";
1513
+ return "Low";
1514
+ }
1515
+ function evaluateLoginRisk(settings = {}, geoData = null) {
1516
+ if (!hasRiskData(geoData)) {
1517
+ return { hasRiskData: false, isSuspicious: false, isVpnOrProxy: false };
1518
+ }
1519
+ const scoreEvaluationEnabled = settings.enableSecurityScoring !== false;
1520
+ const lowScore = scoreEvaluationEnabled && typeof geoData.securityScore === "number" && geoData.securityScore < SUSPICIOUS_SCORE_BELOW;
1521
+ const isVpnOrProxy = Boolean(geoData.isVpn || geoData.isProxy);
1522
+ const isSuspicious = Boolean(
1523
+ isVpnOrProxy || geoData.isThreat || geoData.isTor || geoData.isHosting || lowScore
1524
+ );
1525
+ return { hasRiskData: true, isSuspicious, isVpnOrProxy };
1526
+ }
1527
+ module2.exports = {
1528
+ REJECT_SCORE_BELOW,
1529
+ RISK_SOURCES,
1530
+ SUSPICIOUS_SCORE_BELOW,
1531
+ calculateSecurityScore,
1532
+ evaluateLoginRisk,
1533
+ getRiskLevel,
1534
+ hasRiskData,
1535
+ noRiskData
1536
+ };
1537
+ }
1538
+ });
1539
+
1476
1540
  // server/src/utils/geo-firewall.js
1477
1541
  var require_geo_firewall = __commonJS({
1478
1542
  "server/src/utils/geo-firewall.js"(exports2, module2) {
1479
1543
  "use strict";
1544
+ var { REJECT_SCORE_BELOW, hasRiskData } = require_risk_data();
1480
1545
  function normalizeCountryCode(value) {
1481
1546
  if (typeof value !== "string") return null;
1482
1547
  const normalized = value.trim().toUpperCase();
@@ -1496,27 +1561,20 @@ var require_geo_firewall = __commonJS({
1496
1561
  if (status === "private") {
1497
1562
  return { blocked: false, reason: null, status };
1498
1563
  }
1499
- if (status !== "ok") {
1500
- if (getLookupFailureMode(settings) === "block") {
1501
- return {
1502
- blocked: true,
1503
- reason: `geo_lookup_unavailable:${status}`,
1504
- status
1505
- };
1506
- }
1507
- return { blocked: false, reason: null, status };
1508
- }
1509
- if (settings.blockSuspiciousSessions) {
1564
+ if (settings.blockSuspiciousSessions && hasRiskData(geoData)) {
1510
1565
  if (geoData.isThreat) {
1511
1566
  return { blocked: true, reason: "threat_ip", status };
1512
1567
  }
1568
+ if (geoData.isTor) {
1569
+ return { blocked: true, reason: "tor_exit_node", status };
1570
+ }
1513
1571
  if (geoData.isVpn) {
1514
1572
  return { blocked: true, reason: "vpn_detected", status };
1515
1573
  }
1516
1574
  if (geoData.isProxy) {
1517
1575
  return { blocked: true, reason: "proxy_detected", status };
1518
1576
  }
1519
- if (settings.enableSecurityScoring !== false && typeof geoData.securityScore === "number" && geoData.securityScore < 50) {
1577
+ if (settings.enableSecurityScoring !== false && typeof geoData.securityScore === "number" && geoData.securityScore < REJECT_SCORE_BELOW) {
1520
1578
  return {
1521
1579
  blocked: true,
1522
1580
  reason: `low_security_score:${geoData.securityScore}`,
@@ -1524,6 +1582,16 @@ var require_geo_firewall = __commonJS({
1524
1582
  };
1525
1583
  }
1526
1584
  }
1585
+ if (status !== "ok") {
1586
+ if (getLookupFailureMode(settings) === "block") {
1587
+ return {
1588
+ blocked: true,
1589
+ reason: `geo_lookup_unavailable:${status}`,
1590
+ status
1591
+ };
1592
+ }
1593
+ return { blocked: false, reason: null, status };
1594
+ }
1527
1595
  if (settings.enableGeofencing) {
1528
1596
  const countryCode = normalizeCountryCode(geoData.country_code);
1529
1597
  const blockedCountries = normalizeCountryList(settings.blockedCountries);
@@ -1553,6 +1621,93 @@ var require_geo_firewall = __commonJS({
1553
1621
  }
1554
1622
  });
1555
1623
 
1624
+ // server/src/utils/login-alerts.js
1625
+ var require_login_alerts = __commonJS({
1626
+ "server/src/utils/login-alerts.js"(exports2, module2) {
1627
+ "use strict";
1628
+ var { evaluateLoginRisk } = require_risk_data();
1629
+ async function dispatchLoginAlerts({
1630
+ settings,
1631
+ notificationService,
1632
+ user,
1633
+ session,
1634
+ geoData,
1635
+ isNewLocation = false
1636
+ }) {
1637
+ const attempted = { webhookEvent: null, emails: [] };
1638
+ if (!geoData) return attempted;
1639
+ const risk = evaluateLoginRisk(settings, geoData);
1640
+ if (settings.enableEmailAlerts) {
1641
+ if (settings.alertOnVpnProxy && risk.isVpnOrProxy) {
1642
+ attempted.emails.push("vpnProxy");
1643
+ await notificationService.sendVpnProxyAlert({
1644
+ user,
1645
+ session,
1646
+ reason: { isVpn: geoData.isVpn, isProxy: geoData.isProxy },
1647
+ geoData
1648
+ });
1649
+ }
1650
+ if (settings.alertOnSuspiciousLogin && risk.isSuspicious) {
1651
+ attempted.emails.push("suspiciousLogin");
1652
+ await notificationService.sendSuspiciousLoginAlert({
1653
+ user,
1654
+ session,
1655
+ reason: {
1656
+ isVpn: geoData.isVpn,
1657
+ isProxy: geoData.isProxy,
1658
+ isThreat: geoData.isThreat,
1659
+ securityScore: geoData.securityScore
1660
+ },
1661
+ geoData
1662
+ });
1663
+ }
1664
+ if (settings.alertOnNewLocation && isNewLocation) {
1665
+ attempted.emails.push("newLocation");
1666
+ await notificationService.sendNewLocationAlert({ user, session, geoData });
1667
+ }
1668
+ }
1669
+ if (settings.enableWebhooks) {
1670
+ const webhookEvent = risk.isSuspicious ? "login.suspicious" : isNewLocation ? "login.new_location" : "login.success";
1671
+ attempted.webhookEvent = webhookEvent;
1672
+ const targets = [];
1673
+ if (settings.discordWebhookUrl) {
1674
+ targets.push({
1675
+ url: settings.discordWebhookUrl,
1676
+ payload: notificationService.formatDiscordWebhook({
1677
+ event: webhookEvent,
1678
+ session,
1679
+ user,
1680
+ geoData
1681
+ })
1682
+ });
1683
+ }
1684
+ if (settings.slackWebhookUrl) {
1685
+ targets.push({
1686
+ url: settings.slackWebhookUrl,
1687
+ payload: notificationService.formatSlackWebhook({
1688
+ event: webhookEvent,
1689
+ session,
1690
+ user,
1691
+ geoData
1692
+ })
1693
+ });
1694
+ }
1695
+ await Promise.allSettled(
1696
+ targets.map(
1697
+ (target) => notificationService.sendWebhook({
1698
+ event: webhookEvent,
1699
+ data: target.payload,
1700
+ webhookUrl: target.url
1701
+ })
1702
+ )
1703
+ );
1704
+ }
1705
+ return attempted;
1706
+ }
1707
+ module2.exports = { dispatchLoginAlerts };
1708
+ }
1709
+ });
1710
+
1556
1711
  // server/src/utils/session-revocation.js
1557
1712
  var require_session_revocation = __commonJS({
1558
1713
  "server/src/utils/session-revocation.js"(exports2, module2) {
@@ -6380,6 +6535,7 @@ var require_bootstrap = __commonJS({
6380
6535
  var { extractBearerToken } = require_extract_token();
6381
6536
  var { setSessionRejectionReason } = require_rejection_cache();
6382
6537
  var { evaluateGeoFirewall } = require_geo_firewall();
6538
+ var { dispatchLoginAlerts } = require_login_alerts();
6383
6539
  var { REVOCATION_UID } = require_session_revocation();
6384
6540
  var { getNativeSessionManager } = require_native_session_manager();
6385
6541
  var { CONTENT_API_PERMISSIONS_VERSION } = require_content_api_permissions();
@@ -7122,9 +7278,6 @@ var require_bootstrap = __commonJS({
7122
7278
  return;
7123
7279
  }
7124
7280
  const notificationService = strapi2.plugin("magic-sessionmanager").service("notifications");
7125
- const scoreEvaluationEnabled = settings.enableSecurityScoring !== false;
7126
- const lowScore = scoreEvaluationEnabled && typeof geoData.securityScore === "number" && geoData.securityScore < 70;
7127
- const isSuspicious = geoData.isVpn || geoData.isProxy || geoData.isThreat || lowScore;
7128
7281
  let isNewLocation = false;
7129
7282
  if (settings.alertOnNewLocation && (geoData.country_code || geoData.country)) {
7130
7283
  try {
@@ -7167,74 +7320,14 @@ var require_bootstrap = __commonJS({
7167
7320
  log.debug("New-location check failed (non-fatal):", locErr?.name || "Error");
7168
7321
  }
7169
7322
  }
7170
- if (settings.enableEmailAlerts) {
7171
- if (settings.alertOnVpnProxy && (geoData.isVpn || geoData.isProxy)) {
7172
- await notificationService.sendVpnProxyAlert({
7173
- user,
7174
- session: newSession,
7175
- reason: {
7176
- isVpn: geoData.isVpn,
7177
- isProxy: geoData.isProxy
7178
- },
7179
- geoData
7180
- });
7181
- }
7182
- if (settings.alertOnSuspiciousLogin && isSuspicious) {
7183
- await notificationService.sendSuspiciousLoginAlert({
7184
- user,
7185
- session: newSession,
7186
- reason: {
7187
- isVpn: geoData.isVpn,
7188
- isProxy: geoData.isProxy,
7189
- isThreat: geoData.isThreat,
7190
- securityScore: geoData.securityScore
7191
- },
7192
- geoData
7193
- });
7194
- }
7195
- if (settings.alertOnNewLocation && isNewLocation) {
7196
- await notificationService.sendNewLocationAlert({
7197
- user,
7198
- session: newSession,
7199
- geoData
7200
- });
7201
- }
7202
- }
7203
- if (settings.enableWebhooks) {
7204
- const webhookEvent = isSuspicious ? "login.suspicious" : isNewLocation ? "login.new_location" : "login.success";
7205
- const targets = [];
7206
- if (settings.discordWebhookUrl) {
7207
- targets.push({
7208
- url: settings.discordWebhookUrl,
7209
- payload: notificationService.formatDiscordWebhook({
7210
- event: webhookEvent,
7211
- session: newSession,
7212
- user,
7213
- geoData
7214
- })
7215
- });
7216
- }
7217
- if (settings.slackWebhookUrl) {
7218
- targets.push({
7219
- url: settings.slackWebhookUrl,
7220
- payload: notificationService.formatSlackWebhook({
7221
- event: webhookEvent,
7222
- session: newSession,
7223
- user,
7224
- geoData
7225
- })
7226
- });
7227
- }
7228
- await Promise.allSettled(
7229
- targets.map(
7230
- (t) => notificationService.sendWebhook({
7231
- event: webhookEvent,
7232
- data: t.payload,
7233
- webhookUrl: t.url
7234
- })
7235
- )
7236
- );
7237
- }
7323
+ await dispatchLoginAlerts({
7324
+ settings,
7325
+ notificationService,
7326
+ user,
7327
+ session: newSession,
7328
+ geoData,
7329
+ isNewLocation
7330
+ });
7238
7331
  } catch (notifErr) {
7239
7332
  log.warn("Notification failed:", notifErr?.name || "Error");
7240
7333
  }
@@ -8914,14 +9007,15 @@ var require_enhance_session = __commonJS({
8914
9007
  country_flag: geoData.country_flag,
8915
9008
  city: geoData.city,
8916
9009
  region: geoData.region,
8917
- timezone: geoData.timezone
9010
+ timezone: geoData.timezone,
9011
+ ...geoData.riskSource ? { riskSource: geoData.riskSource } : {}
8918
9012
  };
8919
9013
  if (strapi2) {
8920
9014
  strapi2.documents(SESSION_UID).update({
8921
9015
  documentId: session.documentId,
8922
9016
  data: {
8923
9017
  geoLocation,
8924
- securityScore: geoData.securityScore ?? null
9018
+ securityScore: geoData.riskSource ? geoData.securityScore ?? null : null
8925
9019
  }
8926
9020
  }).catch(() => {
8927
9021
  });
@@ -9630,6 +9724,7 @@ var require_session = __commonJS({
9630
9724
  var { sendServerError } = require_http_errors();
9631
9725
  var { getCoordinator } = require_coordination();
9632
9726
  var { clearSessionStatsCache } = require_session_list();
9727
+ var { noRiskData } = require_risk_data();
9633
9728
  var {
9634
9729
  getNativeOnlySummary,
9635
9730
  endNativeOnlySessions,
@@ -9663,11 +9758,7 @@ var require_session = __commonJS({
9663
9758
  timezone: "Unknown",
9664
9759
  latitude: null,
9665
9760
  longitude: null,
9666
- isVpn: false,
9667
- isProxy: false,
9668
- isThreat: false,
9669
- securityScore: 50,
9670
- riskLevel: "Unknown",
9761
+ ...noRiskData(),
9671
9762
  _status: "disabled",
9672
9763
  _source: "disabled"
9673
9764
  };
@@ -10790,7 +10881,10 @@ var require_geoip_updater = __commonJS({
10790
10881
  var SUPPORTED_MMDB_NAMES = new Set(
10791
10882
  [...SUPPORTED_EDITION_IDS].map((editionId) => `${editionId}.mmdb`)
10792
10883
  );
10793
- function resolveDatabaseTarget(value, directory = DEFAULT_GEOIP_DIRECTORY) {
10884
+ var RISK_EDITION_IDS = /* @__PURE__ */ new Set(["GeoIP2-Anonymous-IP", "GeoLite2-ASN"]);
10885
+ var ALL_EDITION_IDS = /* @__PURE__ */ new Set([...SUPPORTED_EDITION_IDS, ...RISK_EDITION_IDS]);
10886
+ var ALL_MMDB_NAMES = new Set([...ALL_EDITION_IDS].map((editionId) => `${editionId}.mmdb`));
10887
+ function resolveDatabaseTarget(value, directory = DEFAULT_GEOIP_DIRECTORY, allowedNames = SUPPORTED_MMDB_NAMES) {
10794
10888
  const root = path.resolve(directory);
10795
10889
  if (value !== void 0 && typeof value !== "string") {
10796
10890
  throw new Error("GeoIP database path must be a string");
@@ -10809,14 +10903,14 @@ var require_geoip_updater = __commonJS({
10809
10903
  }
10810
10904
  filename = requested;
10811
10905
  }
10812
- if (!SUPPORTED_MMDB_NAMES.has(filename)) {
10906
+ if (!allowedNames.has(filename)) {
10813
10907
  throw new Error("GeoIP database path must use a supported MMDB filename");
10814
10908
  }
10815
10909
  return path.join(root, filename);
10816
10910
  }
10817
- async function canonicalizeDatabaseTarget(value, directory = DEFAULT_GEOIP_DIRECTORY) {
10911
+ async function canonicalizeDatabaseTarget(value, directory = DEFAULT_GEOIP_DIRECTORY, allowedNames = SUPPORTED_MMDB_NAMES) {
10818
10912
  const root = path.resolve(directory);
10819
- const target = resolveDatabaseTarget(value, root);
10913
+ const target = resolveDatabaseTarget(value, root, allowedNames);
10820
10914
  await fs.mkdir(root, { recursive: true, mode: 448 });
10821
10915
  const rootStat = await fs.lstat(root);
10822
10916
  const canonicalRoot = await fs.realpath(root);
@@ -10842,8 +10936,8 @@ var require_geoip_updater = __commonJS({
10842
10936
  }
10843
10937
  return canonicalTarget;
10844
10938
  }
10845
- function normalizeEditionId(value, fallback = DEFAULT_EDITION_ID) {
10846
- return SUPPORTED_EDITION_IDS.has(value) ? value : fallback;
10939
+ function normalizeEditionId(value, fallback = DEFAULT_EDITION_ID, allowed = SUPPORTED_EDITION_IDS) {
10940
+ return allowed.has(value) ? value : fallback;
10847
10941
  }
10848
10942
  function inferEditionIdFromPath(filePath) {
10849
10943
  if (typeof filePath !== "string" || filePath.trim() === "") return "";
@@ -10865,10 +10959,25 @@ var require_geoip_updater = __commonJS({
10865
10959
  function resolveConfig(env = process2.env, argv = process2.argv.slice(2), overrides = {}) {
10866
10960
  const force = argv.includes("--force") || overrides.force === true;
10867
10961
  const configuredOutputPath = overrides.outputPath || env.MAGIC_SESSIONMANAGER_GEOIP_DATABASE || env.GEOIP_DATABASE_PATH || "";
10962
+ const requestedEdition = overrides.editionId || env.MAXMIND_EDITION_ID;
10963
+ const databaseDirectory = overrides.databaseDirectory || DEFAULT_GEOIP_DIRECTORY;
10964
+ if (RISK_EDITION_IDS.has(requestedEdition)) {
10965
+ return {
10966
+ accountId: overrides.accountId || env.MAXMIND_ACCOUNT_ID || env.MAXMIND_USER_ID || "",
10967
+ licenseKey: overrides.licenseKey || env.MAXMIND_LICENSE_KEY || "",
10968
+ editionId: requestedEdition,
10969
+ outputPath: resolveDatabaseTarget(
10970
+ `${requestedEdition}.mmdb`,
10971
+ databaseDirectory,
10972
+ ALL_MMDB_NAMES
10973
+ ),
10974
+ mmdbFileName: `${requestedEdition}.mmdb`,
10975
+ force
10976
+ };
10977
+ }
10868
10978
  const editionId = normalizeEditionId(
10869
- overrides.editionId || env.MAXMIND_EDITION_ID || inferEditionIdFromPath(configuredOutputPath) || DEFAULT_EDITION_ID
10979
+ requestedEdition || inferEditionIdFromPath(configuredOutputPath) || DEFAULT_EDITION_ID
10870
10980
  );
10871
- const databaseDirectory = overrides.databaseDirectory || DEFAULT_GEOIP_DIRECTORY;
10872
10981
  const outputPath = resolveDatabaseTarget(
10873
10982
  configuredOutputPath || `${editionId}.mmdb`,
10874
10983
  databaseDirectory
@@ -10946,7 +11055,9 @@ var require_geoip_updater = __commonJS({
10946
11055
  redirect: "follow"
10947
11056
  });
10948
11057
  if (!response.ok) {
10949
- throw new Error(`MaxMind HEAD failed with HTTP ${response.status}`);
11058
+ const error = new Error(`MaxMind HEAD failed with HTTP ${response.status}`);
11059
+ error.httpStatus = response.status;
11060
+ throw error;
10950
11061
  }
10951
11062
  return {
10952
11063
  lastModified: response.headers.get("last-modified") || "",
@@ -10963,7 +11074,9 @@ var require_geoip_updater = __commonJS({
10963
11074
  redirect: "follow"
10964
11075
  });
10965
11076
  if (!response.ok) {
10966
- throw new Error(`MaxMind download failed with HTTP ${response.status}`);
11077
+ const error = new Error(`MaxMind download failed with HTTP ${response.status}`);
11078
+ error.httpStatus = response.status;
11079
+ throw error;
10967
11080
  }
10968
11081
  return Buffer.from(await response.arrayBuffer());
10969
11082
  }
@@ -11001,8 +11114,12 @@ var require_geoip_updater = __commonJS({
11001
11114
  if (!config2.accountId || !config2.licenseKey) {
11002
11115
  throw new Error("MAXMIND_ACCOUNT_ID and MAXMIND_LICENSE_KEY are required");
11003
11116
  }
11004
- const editionId = normalizeEditionId(config2.editionId);
11005
- const outputPath = await canonicalizeDatabaseTarget(config2.outputPath);
11117
+ const editionId = normalizeEditionId(config2.editionId, DEFAULT_EDITION_ID, ALL_EDITION_IDS);
11118
+ const outputPath = await canonicalizeDatabaseTarget(
11119
+ config2.outputPath,
11120
+ DEFAULT_GEOIP_DIRECTORY,
11121
+ ALL_MMDB_NAMES
11122
+ );
11006
11123
  const mmdbFileName = `${editionId}.mmdb`;
11007
11124
  if (path.basename(outputPath) !== mmdbFileName) {
11008
11125
  throw new Error("GeoIP database filename must match the selected edition");
@@ -11054,6 +11171,8 @@ var require_geoip_updater = __commonJS({
11054
11171
  };
11055
11172
  }
11056
11173
  module2.exports = {
11174
+ ALL_MMDB_NAMES,
11175
+ RISK_EDITION_IDS,
11057
11176
  DEFAULT_EDITION_ID,
11058
11177
  DEFAULT_GEOIP_DIRECTORY,
11059
11178
  DEFAULT_MMDB_NAME,
@@ -11603,6 +11722,218 @@ var require_settings = __commonJS({
11603
11722
  }
11604
11723
  });
11605
11724
 
11725
+ // server/src/utils/risk-databases.js
11726
+ var require_risk_databases = __commonJS({
11727
+ "server/src/utils/risk-databases.js"(exports2, module2) {
11728
+ "use strict";
11729
+ var fs = require("node:fs");
11730
+ var path = require("node:path");
11731
+ var {
11732
+ DEFAULT_GEOIP_DIRECTORY,
11733
+ RISK_EDITION_IDS,
11734
+ readMetadata
11735
+ } = require_geoip_updater();
11736
+ var { calculateSecurityScore, getRiskLevel, noRiskData } = require_risk_data();
11737
+ var SAFE_GEOIP_DIRECTORY_LABEL = "data/magic-sessionmanager/geoip";
11738
+ var RISK_DATABASES = Object.freeze({
11739
+ "anonymous-ip": Object.freeze({
11740
+ editionId: "GeoIP2-Anonymous-IP",
11741
+ envVar: "MAGIC_SESSIONMANAGER_ANONYMOUS_IP_DATABASE",
11742
+ method: "anonymousIP"
11743
+ }),
11744
+ asn: Object.freeze({
11745
+ editionId: "GeoLite2-ASN",
11746
+ envVar: "MAGIC_SESSIONMANAGER_ASN_DATABASE",
11747
+ method: "asn"
11748
+ })
11749
+ });
11750
+ var HOSTING_ASNS = Object.freeze(
11751
+ /* @__PURE__ */ new Set([
11752
+ 16509,
11753
+ // Amazon AWS
11754
+ 14618,
11755
+ // Amazon AWS
11756
+ 396982,
11757
+ // Google Cloud
11758
+ 8075,
11759
+ // Microsoft (Azure; also Microsoft's own offices)
11760
+ 14061,
11761
+ // DigitalOcean
11762
+ 24940,
11763
+ // Hetzner Online
11764
+ 213230,
11765
+ // Hetzner Cloud
11766
+ 16276,
11767
+ // OVHcloud
11768
+ 63949,
11769
+ // Akamai Connected Cloud (Linode)
11770
+ 20473,
11771
+ // Vultr (The Constant Company)
11772
+ 51167,
11773
+ // Contabo
11774
+ 31898,
11775
+ // Oracle Cloud
11776
+ 45102,
11777
+ // Alibaba Cloud
11778
+ 12876,
11779
+ // Scaleway
11780
+ 60781,
11781
+ // Leaseweb Netherlands
11782
+ 28753,
11783
+ // Leaseweb Germany
11784
+ 8560,
11785
+ // IONOS
11786
+ 47583,
11787
+ // Hostinger
11788
+ 9009
11789
+ // M247
11790
+ ])
11791
+ );
11792
+ var readerCache = /* @__PURE__ */ new Map();
11793
+ function resolveRiskDatabasePath(kind, env = process.env) {
11794
+ const definition = RISK_DATABASES[kind];
11795
+ const configured = typeof env[definition.envVar] === "string" ? env[definition.envVar].trim() : "";
11796
+ if (configured) {
11797
+ return {
11798
+ path: path.isAbsolute(configured) ? configured : path.resolve(process.cwd(), configured),
11799
+ fromEnvironment: true
11800
+ };
11801
+ }
11802
+ return {
11803
+ path: path.join(DEFAULT_GEOIP_DIRECTORY, `${definition.editionId}.mmdb`),
11804
+ fromEnvironment: false
11805
+ };
11806
+ }
11807
+ async function openRiskReader(databasePath) {
11808
+ if (readerCache.has(databasePath)) return readerCache.get(databasePath);
11809
+ const { Reader } = require("@maxmind/geoip2-node");
11810
+ const readerPromise = Reader.open(databasePath, {
11811
+ watchForUpdates: true,
11812
+ watchForUpdatesNonPersistent: true
11813
+ });
11814
+ readerCache.set(databasePath, readerPromise);
11815
+ try {
11816
+ return await readerPromise;
11817
+ } catch (error) {
11818
+ readerCache.delete(databasePath);
11819
+ throw error;
11820
+ }
11821
+ }
11822
+ function resetRiskReaders() {
11823
+ for (const databasePath of readerCache.keys()) fs.unwatchFile(databasePath);
11824
+ readerCache.clear();
11825
+ }
11826
+ async function readRiskRecord(kind, ip, env = process.env) {
11827
+ const { path: databasePath } = resolveRiskDatabasePath(kind, env);
11828
+ if (!fs.existsSync(databasePath)) return { status: "missing" };
11829
+ try {
11830
+ const reader = await openRiskReader(databasePath);
11831
+ return { status: "ok", record: reader[RISK_DATABASES[kind].method](ip) };
11832
+ } catch (error) {
11833
+ if (error?.name === "AddressNotFoundError") return { status: "absent" };
11834
+ return { status: "error", name: error?.name || "Error" };
11835
+ }
11836
+ }
11837
+ function buildRiskData({ anonymous, asn }) {
11838
+ const asnRecord = asn?.status === "ok" ? asn.record : null;
11839
+ const asnNumber = Number.isInteger(asnRecord?.autonomousSystemNumber) ? asnRecord.autonomousSystemNumber : null;
11840
+ const asnFields = asnRecord ? {
11841
+ asn: asnNumber === null ? null : `AS${asnNumber}`,
11842
+ org: asnRecord.autonomousSystemOrganization || null
11843
+ } : {};
11844
+ let flags;
11845
+ let riskSource;
11846
+ if (anonymous?.status === "ok" || anonymous?.status === "absent") {
11847
+ const record = anonymous.record || {};
11848
+ riskSource = "anonymous-ip";
11849
+ flags = {
11850
+ isAnonymous: record.isAnonymous === true,
11851
+ isVpn: record.isAnonymousVpn === true,
11852
+ isPublicProxy: record.isPublicProxy === true,
11853
+ isResidentialProxy: record.isResidentialProxy === true,
11854
+ isProxy: record.isPublicProxy === true || record.isResidentialProxy === true,
11855
+ isTor: record.isTorExitNode === true,
11856
+ isHosting: record.isHostingProvider === true,
11857
+ // MaxMind's Anonymous IP data has no "threat" category.
11858
+ isThreat: false
11859
+ };
11860
+ } else if (asn?.status === "ok" || asn?.status === "absent") {
11861
+ riskSource = "asn-heuristic";
11862
+ flags = {
11863
+ isAnonymous: false,
11864
+ isVpn: false,
11865
+ isPublicProxy: false,
11866
+ isResidentialProxy: false,
11867
+ isProxy: false,
11868
+ isTor: false,
11869
+ isHosting: asnNumber !== null && HOSTING_ASNS.has(asnNumber),
11870
+ isThreat: false
11871
+ };
11872
+ } else {
11873
+ const failed = anonymous?.status === "error" || asn?.status === "error";
11874
+ return { ...noRiskData(), ...asnFields, _riskStatus: failed ? "error" : "missing" };
11875
+ }
11876
+ return {
11877
+ ...flags,
11878
+ ...asnFields,
11879
+ securityScore: calculateSecurityScore(flags),
11880
+ riskLevel: getRiskLevel(flags),
11881
+ riskSource,
11882
+ _riskStatus: "ok"
11883
+ };
11884
+ }
11885
+ async function lookupRiskData(ip, env = process.env) {
11886
+ const [anonymous, asn] = await Promise.all([
11887
+ readRiskRecord("anonymous-ip", ip, env),
11888
+ readRiskRecord("asn", ip, env)
11889
+ ]);
11890
+ return buildRiskData({ anonymous, asn });
11891
+ }
11892
+ async function isUsableRiskDatabase(kind, databasePath) {
11893
+ try {
11894
+ const reader = await openRiskReader(databasePath);
11895
+ reader[RISK_DATABASES[kind].method]("127.0.0.1");
11896
+ return true;
11897
+ } catch (error) {
11898
+ return error?.name === "AddressNotFoundError";
11899
+ }
11900
+ }
11901
+ async function describeRiskDatabase(kind, env = process.env) {
11902
+ const { editionId } = RISK_DATABASES[kind];
11903
+ const { path: databasePath, fromEnvironment } = resolveRiskDatabasePath(kind, env);
11904
+ const exists = fs.existsSync(databasePath);
11905
+ const usable = exists ? await isUsableRiskDatabase(kind, databasePath) : false;
11906
+ return {
11907
+ editionId,
11908
+ exists,
11909
+ usable,
11910
+ fromEnvironment,
11911
+ // Only the dedicated folder is named; an environment path stays private.
11912
+ file: fromEnvironment ? null : `${SAFE_GEOIP_DIRECTORY_LABEL}/${editionId}.mmdb`,
11913
+ metadata: !fromEnvironment && exists ? await readMetadata(`${databasePath}.metadata.json`) : null
11914
+ };
11915
+ }
11916
+ async function getRiskDataStatus(env = process.env) {
11917
+ const [anonymousIp, asn] = await Promise.all([
11918
+ describeRiskDatabase("anonymous-ip", env),
11919
+ describeRiskDatabase("asn", env)
11920
+ ]);
11921
+ const source = anonymousIp.usable ? "anonymous-ip" : asn.usable ? "asn-heuristic" : null;
11922
+ return { available: source !== null, source, anonymousIp, asn };
11923
+ }
11924
+ module2.exports = {
11925
+ HOSTING_ASNS,
11926
+ RISK_DATABASES,
11927
+ RISK_EDITION_IDS,
11928
+ buildRiskData,
11929
+ getRiskDataStatus,
11930
+ lookupRiskData,
11931
+ resetRiskReaders,
11932
+ resolveRiskDatabasePath
11933
+ };
11934
+ }
11935
+ });
11936
+
11606
11937
  // server/src/controllers/geoip.js
11607
11938
  var require_geoip = __commonJS({
11608
11939
  "server/src/controllers/geoip.js"(exports2, module2) {
@@ -11625,6 +11956,7 @@ var require_geoip = __commonJS({
11625
11956
  var { sendServerError } = require_http_errors();
11626
11957
  var { setPluginStoreValue } = require_plugin_store();
11627
11958
  var { getHostFingerprint } = require_coordination();
11959
+ var { getRiskDataStatus, RISK_DATABASES } = require_risk_databases();
11628
11960
  var CREDENTIALS_KEY = "geoipCredentials";
11629
11961
  var SAFE_GEOIP_DIRECTORY_LABEL = "data/magic-sessionmanager/geoip";
11630
11962
  var DEFAULT_CITY_DATABASE_PATH = resolveDatabaseTarget("GeoLite2-City.mmdb");
@@ -11681,6 +12013,16 @@ var require_geoip = __commonJS({
11681
12013
  force
11682
12014
  });
11683
12015
  }
12016
+ var UPDATABLE_DATABASES = /* @__PURE__ */ new Set(["location", ...Object.keys(RISK_DATABASES)]);
12017
+ function buildRiskUpdaterConfig(database, storedCredentials, force = false) {
12018
+ return resolveConfig(process.env, force ? ["--force"] : [], {
12019
+ accountId: process.env.MAXMIND_ACCOUNT_ID || storedCredentials.accountId || "",
12020
+ licenseKey: process.env.MAXMIND_LICENSE_KEY || storedCredentials.licenseKey || "",
12021
+ editionId: RISK_DATABASES[database].editionId,
12022
+ databaseDirectory: DEFAULT_GEOIP_DIRECTORY,
12023
+ force
12024
+ });
12025
+ }
11684
12026
  function sanitizeCredentialInput(value, maxLength = 256) {
11685
12027
  if (typeof value !== "string") return "";
11686
12028
  return value.replace(/\0/g, "").trim().slice(0, maxLength);
@@ -11719,7 +12061,11 @@ var require_geoip = __commonJS({
11719
12061
  // answered. In multi-instance deployments each instance reports
11720
12062
  // its own file; `instance` is a non-reversible host fingerprint.
11721
12063
  scope: "instance",
11722
- instance: getHostFingerprint()
12064
+ instance: getHostFingerprint(),
12065
+ // VPN, proxy and Tor detection needs a dedicated risk data source.
12066
+ // The location providers (ipapi.co, GeoLite2 City/Country) have
12067
+ // none; the local Anonymous IP or ASN database is reported here.
12068
+ risk: await getRiskDataStatus()
11723
12069
  }
11724
12070
  });
11725
12071
  } catch (error) {
@@ -11774,9 +12120,15 @@ var require_geoip = __commonJS({
11774
12120
  try {
11775
12121
  const body = ctx.request.body || {};
11776
12122
  const force = body.force === true;
12123
+ const database = body.database === void 0 ? "location" : body.database;
12124
+ if (!UPDATABLE_DATABASES.has(database)) {
12125
+ return ctx.badRequest("Unknown GeoIP database", {
12126
+ database: ["Use location, anonymous-ip or asn."]
12127
+ });
12128
+ }
11777
12129
  const settings = await getPluginSettings(strapi2);
11778
12130
  const storedCredentials = await getStoredCredentials(strapi2);
11779
- const config2 = buildUpdaterConfig(settings, storedCredentials, force);
12131
+ const config2 = database === "location" ? buildUpdaterConfig(settings, storedCredentials, force) : buildRiskUpdaterConfig(database, storedCredentials, force);
11780
12132
  if (!config2.accountId || !config2.licenseKey) {
11781
12133
  return ctx.badRequest("MaxMind credentials are required before downloading GeoIP data");
11782
12134
  }
@@ -11788,6 +12140,13 @@ var require_geoip = __commonJS({
11788
12140
  "[magic-sessionmanager/geoip] GeoIP download failed:",
11789
12141
  error?.name || "Error"
11790
12142
  );
12143
+ if (error?.httpStatus === 401 || error?.httpStatus === 403) {
12144
+ return sendServerError(
12145
+ ctx,
12146
+ 502,
12147
+ "MaxMind refused the download. Check the credentials and that your account includes this database."
12148
+ );
12149
+ }
11791
12150
  return sendServerError(ctx, 502, "Error updating GeoIP database");
11792
12151
  }
11793
12152
  invalidateSettingsCache();
@@ -11804,6 +12163,7 @@ var require_geoip = __commonJS({
11804
12163
  }
11805
12164
  },
11806
12165
  __private: {
12166
+ buildRiskUpdaterConfig,
11807
12167
  buildUpdaterConfig,
11808
12168
  getCredentialSource,
11809
12169
  getStoredCredentials,
@@ -12810,9 +13170,12 @@ var require_session2 = __commonJS({
12810
13170
  country_flag: geoData.country_flag,
12811
13171
  city: geoData.city,
12812
13172
  region: geoData.region,
12813
- timezone: geoData.timezone
13173
+ timezone: geoData.timezone,
13174
+ // Marks the stored score as real risk data; without a
13175
+ // risk source the score is null (not a fake 100).
13176
+ ...geoData.riskSource ? { riskSource: geoData.riskSource } : {}
12814
13177
  } : null,
12815
- securityScore: geoData?.securityScore ?? null
13178
+ securityScore: geoData?.riskSource ? geoData.securityScore ?? null : null
12816
13179
  }
12817
13180
  });
12818
13181
  log.info("[SUCCESS] End-user session metadata created");
@@ -13682,7 +14045,12 @@ var require_geolocation = __commonJS({
13682
14045
  var path = require("node:path");
13683
14046
  var { getPluginSettings } = require_settings_loader();
13684
14047
  var { getCoordinator, hashedKey } = require_coordination();
13685
- var { resolveDatabaseTarget } = require_geoip_updater();
14048
+ var {
14049
+ DEFAULT_GEOIP_DIRECTORY,
14050
+ resolveDatabaseTarget
14051
+ } = require_geoip_updater();
14052
+ var { calculateSecurityScore, getRiskLevel, noRiskData } = require_risk_data();
14053
+ var { lookupRiskData } = require_risk_databases();
13686
14054
  var GEO_API_TIMEOUT_MS = 4e3;
13687
14055
  var IPAPI_SUCCESS_CACHE_TTL_MS = 24 * 60 * 60 * 1e3;
13688
14056
  var IPAPI_FAILURE_CACHE_TTL_MS = 5 * 60 * 1e3;
@@ -13712,11 +14080,24 @@ var require_geolocation = __commonJS({
13712
14080
  function uniqueValues(values) {
13713
14081
  return [...new Set(values.filter(Boolean))];
13714
14082
  }
14083
+ function resolveConfiguredCandidates(value) {
14084
+ if (typeof value !== "string" || value.trim() === "") return [];
14085
+ const trimmed = value.trim();
14086
+ if (path.isAbsolute(trimmed)) return [trimmed];
14087
+ const isBareName = trimmed !== "." && trimmed !== ".." && !/[\\/]/.test(trimmed) && !trimmed.includes("\0");
14088
+ if (isBareName) {
14089
+ return uniqueValues([
14090
+ path.join(DEFAULT_GEOIP_DIRECTORY, trimmed),
14091
+ path.resolve(process.cwd(), trimmed)
14092
+ ]);
14093
+ }
14094
+ return [path.resolve(process.cwd(), trimmed)];
14095
+ }
13715
14096
  function resolveDatabaseCandidates(settings = {}) {
13716
- const configured = normalizeDatabasePath(
14097
+ const configured = resolveConfiguredCandidates(
13717
14098
  settings.geoIpDatabasePath || process.env.MAGIC_SESSIONMANAGER_GEOIP_DATABASE || process.env.GEOIP_DATABASE_PATH
13718
14099
  );
13719
- if (configured) return [configured];
14100
+ if (configured.length > 0) return configured;
13720
14101
  return uniqueValues([
13721
14102
  normalizeDatabasePath(process.env.GEOLITE2_CITY_MMDB),
13722
14103
  normalizeDatabasePath(process.env.GEOIP_CITY_DATABASE_PATH),
@@ -13735,7 +14116,11 @@ var require_geolocation = __commonJS({
13735
14116
  return readerCache.get(databasePath);
13736
14117
  }
13737
14118
  const { Reader } = require("@maxmind/geoip2-node");
13738
- const readerPromise = Reader.open(databasePath, { watchForUpdates: true });
14119
+ const readerPromise = Reader.open(databasePath, {
14120
+ watchForUpdates: true,
14121
+ // Reloads a replaced file without keeping the process alive on its own.
14122
+ watchForUpdatesNonPersistent: true
14123
+ });
13739
14124
  readerCache.set(databasePath, readerPromise);
13740
14125
  try {
13741
14126
  return await readerPromise;
@@ -13888,13 +14273,8 @@ var require_geolocation = __commonJS({
13888
14273
  org: null,
13889
14274
  asn: null,
13890
14275
  network: data.traits?.network || null,
13891
- isVpn: false,
13892
- isProxy: false,
13893
- isThreat: false,
13894
- isAnonymous: false,
13895
- isTor: false,
13896
- securityScore: 100,
13897
- riskLevel: "Low",
14276
+ // A location database has no VPN, proxy or Tor data: no risk data here.
14277
+ ...noRiskData(),
13898
14278
  _status: "ok",
13899
14279
  _source: "local-mmdb",
13900
14280
  _databaseType: "country"
@@ -13919,13 +14299,8 @@ var require_geolocation = __commonJS({
13919
14299
  org: null,
13920
14300
  asn: null,
13921
14301
  network: data.traits?.network || null,
13922
- isVpn: false,
13923
- isProxy: false,
13924
- isThreat: false,
13925
- isAnonymous: false,
13926
- isTor: false,
13927
- securityScore: 100,
13928
- riskLevel: "Low",
14302
+ // A location database has no VPN, proxy or Tor data: no risk data here.
14303
+ ...noRiskData(),
13929
14304
  _status: "ok",
13930
14305
  _source: "local-mmdb",
13931
14306
  _databaseType: "city"
@@ -14021,10 +14396,7 @@ var require_geolocation = __commonJS({
14021
14396
  timezone: Intl.DateTimeFormat().resolvedOptions().timeZone,
14022
14397
  latitude: null,
14023
14398
  longitude: null,
14024
- isVpn: false,
14025
- isProxy: false,
14026
- isThreat: false,
14027
- securityScore: 100,
14399
+ ...noRiskData(),
14028
14400
  riskLevel: "None",
14029
14401
  _status: "private",
14030
14402
  _source: "local"
@@ -14039,21 +14411,53 @@ var require_geolocation = __commonJS({
14039
14411
  return this.getFallbackData(lookupIp, "disabled", "disabled");
14040
14412
  }
14041
14413
  if (provider === "local-mmdb") {
14042
- return this.getLocalMmdbIpInfo(lookupIp, settings);
14414
+ return this.withRiskData(await this.getLocalMmdbIpInfo(lookupIp, settings), lookupIp);
14043
14415
  }
14044
14416
  if (provider === "auto") {
14045
14417
  const databasePath = resolveExistingDatabasePath(settings);
14046
14418
  if (databasePath && fs.existsSync(databasePath)) {
14047
14419
  const localResult = await this.getLocalMmdbIpInfo(lookupIp, settings);
14048
14420
  if (localResult?._status === "ok" || settings.geoLookupFailureMode === "block") {
14049
- return localResult;
14421
+ return this.withRiskData(localResult, lookupIp);
14050
14422
  }
14051
14423
  strapi2.log.warn(
14052
14424
  "[magic-sessionmanager/geolocation] Local MMDB lookup failed, falling back to ipapi.co"
14053
14425
  );
14054
14426
  }
14055
14427
  }
14056
- return this.getIpapiIpInfo(lookupIp);
14428
+ return this.withRiskData(await this.getIpapiIpInfo(lookupIp), lookupIp);
14429
+ },
14430
+ /**
14431
+ * Adds risk data (VPN, proxy, Tor, hosting) from the local risk databases
14432
+ * to a location result. Location providers have none; without a risk
14433
+ * database the result keeps noRiskData(). The lookup is local, so no
14434
+ * address leaves the server. The ASN database also fills `asn` and `org`
14435
+ * when the location provider gave none.
14436
+ *
14437
+ * @param {object} result Location lookup result.
14438
+ * @param {string} lookupIp Normalized, validated IP address.
14439
+ * @returns {Promise<object>} Result with risk fields.
14440
+ */
14441
+ async withRiskData(result, lookupIp) {
14442
+ if (!result || typeof result !== "object") return result;
14443
+ try {
14444
+ const { asn, org, ...risk } = await lookupRiskData(lookupIp);
14445
+ if (risk._riskStatus === "error") {
14446
+ strapi2.log.warn("[magic-sessionmanager/geolocation] Risk database lookup failed");
14447
+ }
14448
+ return {
14449
+ ...result,
14450
+ ...risk,
14451
+ ...asn && !result.asn ? { asn } : {},
14452
+ ...org && !result.org ? { org } : {}
14453
+ };
14454
+ } catch (error) {
14455
+ strapi2.log.warn(
14456
+ "[magic-sessionmanager/geolocation] Risk database lookup failed:",
14457
+ error?.name || "Error"
14458
+ );
14459
+ return { ...result, ...noRiskData(), _riskStatus: "error" };
14460
+ }
14057
14461
  },
14058
14462
  /**
14059
14463
  * Reads effective GEOIP provider settings.
@@ -14225,23 +14629,9 @@ var require_geolocation = __commonJS({
14225
14629
  postal: data.postal,
14226
14630
  org: data.org,
14227
14631
  asn: data.asn,
14228
- isVpn: data.threat?.is_vpn || false,
14229
- isProxy: data.threat?.is_proxy || false,
14230
- isThreat: data.threat?.is_threat || false,
14231
- isAnonymous: data.threat?.is_anonymous || false,
14232
- isTor: data.threat?.is_tor || false,
14233
- securityScore: this.calculateSecurityScore({
14234
- isVpn: data.threat?.is_vpn,
14235
- isProxy: data.threat?.is_proxy,
14236
- isThreat: data.threat?.is_threat,
14237
- isAnonymous: data.threat?.is_anonymous,
14238
- isTor: data.threat?.is_tor
14239
- }),
14240
- riskLevel: this.getRiskLevel({
14241
- isVpn: data.threat?.is_vpn,
14242
- isProxy: data.threat?.is_proxy,
14243
- isThreat: data.threat?.is_threat
14244
- }),
14632
+ // ipapi.co documents no VPN, proxy or threat fields
14633
+ // (https://ipapi.co/api/), so its answer carries no risk data.
14634
+ ...noRiskData(),
14245
14635
  _status: "ok",
14246
14636
  _source: "ipapi"
14247
14637
  };
@@ -14274,25 +14664,16 @@ var require_geolocation = __commonJS({
14274
14664
  * @param {object} flags
14275
14665
  * @returns {number}
14276
14666
  */
14277
- calculateSecurityScore({ isVpn, isProxy, isThreat, isAnonymous, isTor }) {
14278
- let score = 100;
14279
- if (isTor) score -= 50;
14280
- if (isThreat) score -= 40;
14281
- if (isVpn) score -= 20;
14282
- if (isProxy) score -= 15;
14283
- if (isAnonymous) score -= 10;
14284
- return Math.max(0, score);
14667
+ calculateSecurityScore(flags) {
14668
+ return calculateSecurityScore(flags || {});
14285
14669
  },
14286
14670
  /**
14287
- * Maps threat indicators to a human-readable risk level.
14671
+ * Maps risk indicators to a human-readable risk level.
14288
14672
  * @param {object} flags
14289
14673
  * @returns {string}
14290
14674
  */
14291
- getRiskLevel({ isVpn, isProxy, isThreat }) {
14292
- if (isThreat) return "High";
14293
- if (isVpn && isProxy) return "Medium-High";
14294
- if (isVpn || isProxy) return "Medium";
14295
- return "Low";
14675
+ getRiskLevel(flags) {
14676
+ return getRiskLevel(flags || {});
14296
14677
  },
14297
14678
  /**
14298
14679
  * Converts a 2-letter ISO country code into a flag emoji.
@@ -14343,11 +14724,7 @@ var require_geolocation = __commonJS({
14343
14724
  timezone: "Unknown",
14344
14725
  latitude: null,
14345
14726
  longitude: null,
14346
- isVpn: false,
14347
- isProxy: false,
14348
- isThreat: false,
14349
- securityScore: 50,
14350
- riskLevel: "Unknown",
14727
+ ...noRiskData(),
14351
14728
  _status: reason,
14352
14729
  _source: source,
14353
14730
  _reason: detail
@@ -14370,6 +14747,21 @@ var require_geolocation = __commonJS({
14370
14747
  var require_notifications = __commonJS({
14371
14748
  "server/src/services/notifications.js"(exports2, module2) {
14372
14749
  "use strict";
14750
+ var { hasRiskData } = require_risk_data();
14751
+ function getRiskWarnings(geoData) {
14752
+ if (!hasRiskData(geoData)) return [];
14753
+ const warnings = [];
14754
+ if (geoData.isVpn) warnings.push("VPN");
14755
+ if (geoData.isProxy) warnings.push("Proxy");
14756
+ if (geoData.isTor) warnings.push("Tor");
14757
+ if (geoData.isHosting) {
14758
+ warnings.push(
14759
+ geoData.riskSource === "asn-heuristic" ? "Hosting (ASN heuristic)" : "Hosting provider"
14760
+ );
14761
+ }
14762
+ if (geoData.isThreat) warnings.push("Threat");
14763
+ return warnings;
14764
+ }
14373
14765
  var ALLOWED_WEBHOOK_HOSTS = ["discord.com", "discordapp.com", "hooks.slack.com"];
14374
14766
  var WEBHOOK_TIMEOUT_MS = 5e3;
14375
14767
  module2.exports = ({ strapi: strapi2 }) => ({
@@ -14515,9 +14907,10 @@ VPN: {{reason.isVpn}}, Proxy: {{reason.isProxy}}`
14515
14907
  result = result.replace(/\{\{reason\.isVpn\}\}/g, data.reason?.isVpn ? "Yes" : "No");
14516
14908
  result = result.replace(/\{\{reason\.isProxy\}\}/g, data.reason?.isProxy ? "Yes" : "No");
14517
14909
  result = result.replace(/\{\{reason\.isThreat\}\}/g, data.reason?.isThreat ? "Yes" : "No");
14910
+ const score = data.reason?.securityScore;
14518
14911
  result = result.replace(
14519
14912
  /\{\{reason\.securityScore\}\}/g,
14520
- esc(String(data.reason?.securityScore || "0"))
14913
+ esc(typeof score === "number" && Number.isFinite(score) ? String(score) : "N/A")
14521
14914
  );
14522
14915
  return result;
14523
14916
  },
@@ -14698,11 +15091,8 @@ ${session.loginTime ? new Date(session.loginTime).toLocaleString() : "-"}`
14698
15091
  text: `*Location*
14699
15092
  ${locationFlag}${geoData.city || "?"}, ${geoData.country || "?"}`
14700
15093
  });
14701
- if (geoData.isVpn || geoData.isProxy || geoData.isThreat) {
14702
- const warnings = [];
14703
- if (geoData.isVpn) warnings.push("VPN");
14704
- if (geoData.isProxy) warnings.push("Proxy");
14705
- if (geoData.isThreat) warnings.push("Threat");
15094
+ const warnings = getRiskWarnings(geoData);
15095
+ if (warnings.length > 0) {
14706
15096
  fields.push({
14707
15097
  type: "mrkdwn",
14708
15098
  text: `*Security*
@@ -14771,11 +15161,8 @@ ${user.username || "N/A"}`, inline: true },
14771
15161
  value: `${geoData.country_flag || ""} ${geoData.city}, ${geoData.country}`,
14772
15162
  inline: true
14773
15163
  });
14774
- if (geoData.isVpn || geoData.isProxy || geoData.isThreat) {
14775
- const warnings = [];
14776
- if (geoData.isVpn) warnings.push("VPN");
14777
- if (geoData.isProxy) warnings.push("Proxy");
14778
- if (geoData.isThreat) warnings.push("Threat");
15164
+ const warnings = getRiskWarnings(geoData);
15165
+ if (warnings.length > 0) {
14779
15166
  embed.fields.push({
14780
15167
  name: "[WARNING] Security",
14781
15168
  value: `${warnings.join(", ")} detected