strapi-plugin-magic-sessionmanager 4.6.3 → 4.6.4

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.
@@ -9816,6 +9816,18 @@ var require_bootstrap = __commonJS({
9816
9816
  if (path.startsWith("/api/magic-link/login") && (method === "GET" || method === "POST")) return true;
9817
9817
  return false;
9818
9818
  }
9819
+ async function getRequestSettings(strapi2, ctx) {
9820
+ let settings = {};
9821
+ try {
9822
+ settings = await getPluginSettings(strapi2);
9823
+ } catch {
9824
+ settings = {};
9825
+ }
9826
+ if (ctx && ctx.state) {
9827
+ ctx.state.__magicSessionSettings = settings;
9828
+ }
9829
+ return settings;
9830
+ }
9819
9831
  module.exports = async ({ strapi: strapi2 }) => {
9820
9832
  const log = createLogger(strapi2);
9821
9833
  log.info("[START] Bootstrap starting...");
@@ -9913,12 +9925,7 @@ var require_bootstrap = __commonJS({
9913
9925
  if (!isLoginPath(ctx.path, ctx.method)) {
9914
9926
  return next();
9915
9927
  }
9916
- let settings = {};
9917
- try {
9918
- settings = await getPluginSettings(strapi2);
9919
- } catch {
9920
- settings = {};
9921
- }
9928
+ const settings = await getRequestSettings(strapi2, ctx);
9922
9929
  const needsGeoCheck = settings.blockSuspiciousSessions || settings.enableGeofencing || settings.enableGeolocation;
9923
9930
  if (!needsGeoCheck) {
9924
9931
  return next();
@@ -10056,13 +10063,8 @@ var require_bootstrap = __commonJS({
10056
10063
  const clearFailures = (ip) => failed.delete(ip);
10057
10064
  strapi2.server.use(async (ctx, next) => {
10058
10065
  if (!isLoginPath(ctx.path, ctx.method)) return next();
10059
- let maxFailed = 0;
10060
- try {
10061
- const settings = await getPluginSettings(strapi2);
10062
- maxFailed = Number(settings.maxFailedLogins) || 0;
10063
- } catch {
10064
- maxFailed = 0;
10065
- }
10066
+ const settings = await getRequestSettings(strapi2, ctx);
10067
+ const maxFailed = Number(settings.maxFailedLogins) || 0;
10066
10068
  if (maxFailed <= 0) return next();
10067
10069
  const ip = getClientIp(ctx);
10068
10070
  if (!ip || ip === "unknown") return next();
@@ -10121,6 +10123,7 @@ var require_bootstrap = __commonJS({
10121
10123
  if (!ctx.body || !ctx.body.jwt || !ctx.body.user) return;
10122
10124
  try {
10123
10125
  const user = ctx.body.user;
10126
+ await getRequestSettings(strapi2, ctx);
10124
10127
  const ip = getClientIp(ctx);
10125
10128
  const headers = ctx.request.headers || ctx.request.header || {};
10126
10129
  const userAgent = headers["user-agent"] || "unknown";
@@ -13266,7 +13269,7 @@ var require_session2 = __commonJS({
13266
13269
  var require_package = __commonJS({
13267
13270
  "package.json"(exports, module) {
13268
13271
  module.exports = {
13269
- version: "4.6.3",
13272
+ version: "4.6.4",
13270
13273
  keywords: [
13271
13274
  "strapi",
13272
13275
  "plugin",
@@ -13605,12 +13608,25 @@ var require_geolocation = __commonJS({
13605
13608
  "server/src/services/geolocation.js"(exports, module) {
13606
13609
  "use strict";
13607
13610
  var fs = __require("node:fs");
13611
+ var net = __require("node:net");
13608
13612
  var path = __require("node:path");
13609
13613
  var { getPluginSettings } = require_settings_loader();
13610
13614
  var GEO_API_TIMEOUT_MS = 4e3;
13615
+ var IPAPI_SUCCESS_CACHE_TTL_MS = 24 * 60 * 60 * 1e3;
13616
+ var IPAPI_FAILURE_CACHE_TTL_MS = 5 * 60 * 1e3;
13617
+ var IPAPI_RATE_LIMIT_BACKOFF_MS = 15 * 60 * 1e3;
13618
+ var IPAPI_RATE_LIMIT_LOG_INTERVAL_MS = 60 * 1e3;
13619
+ var IPAPI_MAX_CONCURRENT_REQUESTS = 4;
13620
+ var IPAPI_MAX_QUEUE_SIZE = 50;
13611
13621
  var DEFAULT_MMDB_PATH = path.resolve(process.cwd(), "data", "GeoLite2-Country.mmdb");
13612
13622
  var VALID_PROVIDERS = /* @__PURE__ */ new Set(["auto", "local-mmdb", "ipapi", "disabled"]);
13613
13623
  var readerCache = /* @__PURE__ */ new Map();
13624
+ var ipapiCache = /* @__PURE__ */ new Map();
13625
+ var ipapiInFlight = /* @__PURE__ */ new Map();
13626
+ var ipapiQueue = [];
13627
+ var ipapiActiveRequests = 0;
13628
+ var ipapiRateLimitedUntil = 0;
13629
+ var ipapiLastRateLimitLogAt = 0;
13614
13630
  function normalizeProvider(value) {
13615
13631
  return VALID_PROVIDERS.has(value) ? value : "auto";
13616
13632
  }
@@ -13634,6 +13650,119 @@ var require_geolocation = __commonJS({
13634
13650
  throw err;
13635
13651
  }
13636
13652
  }
13653
+ function cloneGeoData(data) {
13654
+ return data ? { ...data } : data;
13655
+ }
13656
+ function getCachedIpapiResult(lookupIp) {
13657
+ const cached = ipapiCache.get(lookupIp);
13658
+ if (!cached) return null;
13659
+ if (cached.expiresAt <= Date.now()) {
13660
+ ipapiCache.delete(lookupIp);
13661
+ return null;
13662
+ }
13663
+ return cloneGeoData(cached.data);
13664
+ }
13665
+ function cacheIpapiResult(lookupIp, data, ttlMs) {
13666
+ if (!lookupIp || !data || ttlMs <= 0) return;
13667
+ if (ipapiCache.size > 1e3) {
13668
+ const oldestKey = ipapiCache.keys().next().value;
13669
+ if (oldestKey) ipapiCache.delete(oldestKey);
13670
+ }
13671
+ ipapiCache.set(lookupIp, {
13672
+ data: cloneGeoData(data),
13673
+ expiresAt: Date.now() + ttlMs
13674
+ });
13675
+ }
13676
+ function getRetryAfterMs(response) {
13677
+ const retryAfter = response?.headers?.get?.("retry-after");
13678
+ if (!retryAfter) return null;
13679
+ const seconds = Number.parseInt(retryAfter, 10);
13680
+ if (Number.isFinite(seconds)) {
13681
+ return Math.max(1e3, Math.min(seconds * 1e3, 60 * 60 * 1e3));
13682
+ }
13683
+ const retryDate = Date.parse(retryAfter);
13684
+ if (Number.isFinite(retryDate)) {
13685
+ return Math.max(1e3, Math.min(retryDate - Date.now(), 60 * 60 * 1e3));
13686
+ }
13687
+ return null;
13688
+ }
13689
+ function markIpapiRateLimited(response) {
13690
+ const backoffMs = getRetryAfterMs(response) || IPAPI_RATE_LIMIT_BACKOFF_MS;
13691
+ ipapiRateLimitedUntil = Math.max(ipapiRateLimitedUntil, Date.now() + backoffMs);
13692
+ return backoffMs;
13693
+ }
13694
+ function getIpapiRateLimitRemainingMs() {
13695
+ return Math.max(0, ipapiRateLimitedUntil - Date.now());
13696
+ }
13697
+ function logIpapiRateLimit(strapi2, message) {
13698
+ const now = Date.now();
13699
+ if (now - ipapiLastRateLimitLogAt < IPAPI_RATE_LIMIT_LOG_INTERVAL_MS) return;
13700
+ ipapiLastRateLimitLogAt = now;
13701
+ strapi2.log.warn(message);
13702
+ }
13703
+ async function acquireIpapiSlot() {
13704
+ if (ipapiActiveRequests < IPAPI_MAX_CONCURRENT_REQUESTS) {
13705
+ ipapiActiveRequests++;
13706
+ return releaseIpapiSlot;
13707
+ }
13708
+ if (ipapiQueue.length >= IPAPI_MAX_QUEUE_SIZE) {
13709
+ return null;
13710
+ }
13711
+ return new Promise((resolve) => {
13712
+ ipapiQueue.push(resolve);
13713
+ });
13714
+ }
13715
+ function releaseIpapiSlot() {
13716
+ ipapiActiveRequests = Math.max(0, ipapiActiveRequests - 1);
13717
+ const next = ipapiQueue.shift();
13718
+ if (next) {
13719
+ ipapiActiveRequests++;
13720
+ next(releaseIpapiSlot);
13721
+ }
13722
+ }
13723
+ function normalizeLookupIp(ipAddress) {
13724
+ if (typeof ipAddress !== "string") return "";
13725
+ let normalized = ipAddress.trim();
13726
+ if (!normalized) return "";
13727
+ if (normalized.startsWith("[") && normalized.endsWith("]")) {
13728
+ normalized = normalized.slice(1, -1).trim();
13729
+ }
13730
+ const ipv4Mapped = normalized.match(/^::ffff:(\d{1,3}(?:\.\d{1,3}){3})$/i);
13731
+ if (ipv4Mapped && net.isIP(ipv4Mapped[1]) === 4) {
13732
+ return ipv4Mapped[1];
13733
+ }
13734
+ return normalized;
13735
+ }
13736
+ function parseIpv4(ip) {
13737
+ if (net.isIP(ip) !== 4) return null;
13738
+ const parts = ip.split(".").map((part) => Number(part));
13739
+ if (parts.length !== 4 || parts.some((part) => !Number.isInteger(part) || part < 0 || part > 255)) {
13740
+ return null;
13741
+ }
13742
+ return parts;
13743
+ }
13744
+ function isPrivateIpv4(ip) {
13745
+ const parts = parseIpv4(ip);
13746
+ if (!parts) return false;
13747
+ const [a, b, c] = parts;
13748
+ return a === 0 || a === 10 || a === 127 || a === 100 && b >= 64 && b <= 127 || a === 169 && b === 254 || a === 172 && b >= 16 && b <= 31 || a === 192 && b === 168 || a === 192 && b === 0 && c === 0 || a === 192 && b === 0 && c === 2 || a === 198 && (b === 18 || b === 19) || a === 198 && b === 51 && c === 100 || a === 203 && b === 0 && c === 113 || a >= 224;
13749
+ }
13750
+ function getFirstHextet(ip) {
13751
+ const first = ip.split(":")[0];
13752
+ if (!first) return 0;
13753
+ const parsed = Number.parseInt(first, 16);
13754
+ return Number.isNaN(parsed) ? 0 : parsed;
13755
+ }
13756
+ function isPrivateIpv6(ip) {
13757
+ const lower = ip.toLowerCase();
13758
+ if (lower === "::" || lower === "::1") return true;
13759
+ if (/^(?:0:){7}0$/.test(lower) || /^(?:0:){7}1$/.test(lower)) return true;
13760
+ if (lower.startsWith("::ffff:")) {
13761
+ return isPrivateIpv4(normalizeLookupIp(lower));
13762
+ }
13763
+ const firstHextet = getFirstHextet(lower);
13764
+ return (firstHextet & 65024) === 64512 || (firstHextet & 65472) === 65152;
13765
+ }
13637
13766
  module.exports = ({ strapi: strapi2 }) => ({
13638
13767
  /**
13639
13768
  * Looks up geolocation data for an IP address.
@@ -13653,9 +13782,10 @@ var require_geolocation = __commonJS({
13653
13782
  * @returns {Promise<object>}
13654
13783
  */
13655
13784
  async getIpInfo(ipAddress) {
13656
- if (!ipAddress || this.isPrivateIp(ipAddress)) {
13785
+ const lookupIp = normalizeLookupIp(ipAddress);
13786
+ if (!lookupIp || this.isPrivateIp(lookupIp)) {
13657
13787
  return {
13658
- ip: ipAddress,
13788
+ ip: lookupIp || ipAddress,
13659
13789
  country: "Local Network",
13660
13790
  country_code: "XX",
13661
13791
  country_flag: "",
@@ -13673,25 +13803,28 @@ var require_geolocation = __commonJS({
13673
13803
  _source: "local"
13674
13804
  };
13675
13805
  }
13806
+ if (net.isIP(lookupIp) === 0) {
13807
+ return this.getFallbackData(ipAddress, "error", "validation", "Invalid IP address");
13808
+ }
13676
13809
  const settings = await this.getGeoSettings();
13677
13810
  const provider = normalizeProvider(settings.geoIpProvider);
13678
13811
  if (provider === "disabled") {
13679
- return this.getFallbackData(ipAddress, "disabled", "disabled");
13812
+ return this.getFallbackData(lookupIp, "disabled", "disabled");
13680
13813
  }
13681
13814
  if (provider === "local-mmdb") {
13682
- return this.getLocalMmdbIpInfo(ipAddress, settings);
13815
+ return this.getLocalMmdbIpInfo(lookupIp, settings);
13683
13816
  }
13684
13817
  if (provider === "auto") {
13685
13818
  const databasePath = resolveDatabasePath(settings);
13686
13819
  if (databasePath && fs.existsSync(databasePath)) {
13687
- const localResult = await this.getLocalMmdbIpInfo(ipAddress, settings);
13688
- if (localResult?._status === "ok") {
13820
+ const localResult = await this.getLocalMmdbIpInfo(lookupIp, settings);
13821
+ if (localResult?._status === "ok" || settings.geoLookupFailureMode === "block") {
13689
13822
  return localResult;
13690
13823
  }
13691
13824
  strapi2.log.warn(`[magic-sessionmanager/geolocation] Local MMDB lookup failed (${localResult?._reason || localResult?._status}), falling back to ipapi.co`);
13692
13825
  }
13693
13826
  }
13694
- return this.getIpapiIpInfo(ipAddress);
13827
+ return this.getIpapiIpInfo(lookupIp);
13695
13828
  },
13696
13829
  /**
13697
13830
  * Reads effective GEOIP provider settings.
@@ -13711,6 +13844,10 @@ var require_geolocation = __commonJS({
13711
13844
  * @returns {Promise<object>}
13712
13845
  */
13713
13846
  async getLocalMmdbIpInfo(ipAddress, settings = {}) {
13847
+ const lookupIp = normalizeLookupIp(ipAddress);
13848
+ if (!lookupIp || net.isIP(lookupIp) === 0) {
13849
+ return this.getFallbackData(ipAddress, "error", "validation", "Invalid IP address");
13850
+ }
13714
13851
  const databasePath = resolveDatabasePath(settings);
13715
13852
  if (!databasePath || !fs.existsSync(databasePath)) {
13716
13853
  return this.getFallbackData(
@@ -13722,12 +13859,12 @@ var require_geolocation = __commonJS({
13722
13859
  }
13723
13860
  try {
13724
13861
  const reader = await openLocalReader(databasePath);
13725
- const data = reader.country(ipAddress);
13862
+ const data = reader.country(lookupIp);
13726
13863
  const country = data.country || data.registeredCountry || data.representedCountry || {};
13727
13864
  const countryCode = country.isoCode || data.registeredCountry?.isoCode || "XX";
13728
13865
  const countryNames = country.names || {};
13729
13866
  const result = {
13730
- ip: ipAddress,
13867
+ ip: lookupIp,
13731
13868
  country: countryNames.en || countryNames.de || countryCode || "Unknown",
13732
13869
  country_code: countryCode,
13733
13870
  country_flag: this.getCountryFlag(countryCode),
@@ -13750,11 +13887,11 @@ var require_geolocation = __commonJS({
13750
13887
  _status: "ok",
13751
13888
  _source: "local-mmdb"
13752
13889
  };
13753
- strapi2.log.debug(`[magic-sessionmanager/geolocation] Local MMDB IP ${ipAddress}: ${result.country_code}`);
13890
+ strapi2.log.debug(`[magic-sessionmanager/geolocation] Local MMDB IP ${lookupIp}: ${result.country_code}`);
13754
13891
  return result;
13755
13892
  } catch (error) {
13756
- strapi2.log.warn(`[magic-sessionmanager/geolocation] Local MMDB lookup failed for ${ipAddress}:`, error.message);
13757
- return this.getFallbackData(ipAddress, "error", "local-mmdb", error.message);
13893
+ strapi2.log.warn(`[magic-sessionmanager/geolocation] Local MMDB lookup failed for ${lookupIp}:`, error.message);
13894
+ return this.getFallbackData(lookupIp, "error", "local-mmdb", error.message);
13758
13895
  }
13759
13896
  },
13760
13897
  /**
@@ -13763,65 +13900,135 @@ var require_geolocation = __commonJS({
13763
13900
  * @returns {Promise<object>}
13764
13901
  */
13765
13902
  async getIpapiIpInfo(ipAddress) {
13766
- const controller = new AbortController();
13767
- const timer = setTimeout(() => controller.abort(), GEO_API_TIMEOUT_MS);
13768
- try {
13769
- const response = await fetch(`https://ipapi.co/${encodeURIComponent(ipAddress)}/json/`, {
13770
- method: "GET",
13771
- headers: { "User-Agent": "Strapi-Magic-SessionManager/1.0" },
13772
- signal: controller.signal
13773
- });
13774
- if (!response.ok) {
13775
- strapi2.log.warn(`[magic-sessionmanager/geolocation] API returned HTTP ${response.status}`);
13776
- return this.getFallbackData(ipAddress, response.status === 429 ? "rate_limited" : "error", "ipapi");
13903
+ const lookupIp = normalizeLookupIp(ipAddress);
13904
+ if (!lookupIp || net.isIP(lookupIp) === 0) {
13905
+ return this.getFallbackData(ipAddress, "error", "validation", "Invalid IP address");
13906
+ }
13907
+ const cached = getCachedIpapiResult(lookupIp);
13908
+ if (cached) return cached;
13909
+ const rateLimitRemainingMs = getIpapiRateLimitRemainingMs();
13910
+ if (rateLimitRemainingMs > 0) {
13911
+ logIpapiRateLimit(
13912
+ strapi2,
13913
+ `[magic-sessionmanager/geolocation] ipapi.co is rate-limited; skipping remote lookups for ${Math.ceil(rateLimitRemainingMs / 1e3)}s`
13914
+ );
13915
+ return this.getFallbackData(lookupIp, "rate_limited", "ipapi", "Remote GeoIP provider is backing off after HTTP 429");
13916
+ }
13917
+ if (ipapiInFlight.has(lookupIp)) {
13918
+ return cloneGeoData(await ipapiInFlight.get(lookupIp));
13919
+ }
13920
+ const lookupPromise = (async () => {
13921
+ const releaseSlot = await acquireIpapiSlot();
13922
+ if (!releaseSlot) {
13923
+ const fallback = this.getFallbackData(
13924
+ lookupIp,
13925
+ "rate_limited",
13926
+ "ipapi",
13927
+ "Remote GeoIP provider concurrency limit reached"
13928
+ );
13929
+ cacheIpapiResult(lookupIp, fallback, IPAPI_FAILURE_CACHE_TTL_MS);
13930
+ return fallback;
13931
+ }
13932
+ const queuedRateLimitRemainingMs = getIpapiRateLimitRemainingMs();
13933
+ if (queuedRateLimitRemainingMs > 0) {
13934
+ releaseSlot();
13935
+ logIpapiRateLimit(
13936
+ strapi2,
13937
+ `[magic-sessionmanager/geolocation] ipapi.co is rate-limited; skipping remote lookups for ${Math.ceil(queuedRateLimitRemainingMs / 1e3)}s`
13938
+ );
13939
+ return this.getFallbackData(lookupIp, "rate_limited", "ipapi", "Remote GeoIP provider is backing off after HTTP 429");
13777
13940
  }
13778
- const data = await response.json();
13779
- if (data.error) {
13780
- strapi2.log.warn(`[magic-sessionmanager/geolocation] API Error: ${data.reason}`);
13781
- const reason = /rate/i.test(data.reason || "") ? "rate_limited" : "error";
13782
- return this.getFallbackData(ipAddress, reason, "ipapi", data.reason);
13941
+ const controller = new AbortController();
13942
+ const timer = setTimeout(() => controller.abort(), GEO_API_TIMEOUT_MS);
13943
+ try {
13944
+ const response = await fetch(`https://ipapi.co/${encodeURIComponent(lookupIp)}/json/`, {
13945
+ method: "GET",
13946
+ headers: { "User-Agent": "Strapi-Magic-SessionManager/1.0" },
13947
+ signal: controller.signal
13948
+ });
13949
+ if (!response.ok) {
13950
+ const reason = response.status === 429 ? "rate_limited" : "error";
13951
+ if (response.status === 429) {
13952
+ const backoffMs = markIpapiRateLimited(response);
13953
+ logIpapiRateLimit(
13954
+ strapi2,
13955
+ `[magic-sessionmanager/geolocation] API returned HTTP 429; backing off ipapi.co lookups for ${Math.ceil(backoffMs / 1e3)}s`
13956
+ );
13957
+ } else {
13958
+ strapi2.log.warn(`[magic-sessionmanager/geolocation] API returned HTTP ${response.status}`);
13959
+ }
13960
+ const fallback = this.getFallbackData(lookupIp, reason, "ipapi", `HTTP ${response.status}`);
13961
+ cacheIpapiResult(lookupIp, fallback, IPAPI_FAILURE_CACHE_TTL_MS);
13962
+ return fallback;
13963
+ }
13964
+ const data = await response.json();
13965
+ if (data.error) {
13966
+ const reason = /rate/i.test(data.reason || "") ? "rate_limited" : "error";
13967
+ if (reason === "rate_limited") {
13968
+ const backoffMs = markIpapiRateLimited();
13969
+ logIpapiRateLimit(
13970
+ strapi2,
13971
+ `[magic-sessionmanager/geolocation] API reported rate limit; backing off ipapi.co lookups for ${Math.ceil(backoffMs / 1e3)}s`
13972
+ );
13973
+ } else {
13974
+ strapi2.log.warn(`[magic-sessionmanager/geolocation] API Error: ${data.reason}`);
13975
+ }
13976
+ const fallback = this.getFallbackData(lookupIp, reason, "ipapi", data.reason);
13977
+ cacheIpapiResult(lookupIp, fallback, IPAPI_FAILURE_CACHE_TTL_MS);
13978
+ return fallback;
13979
+ }
13980
+ const result = {
13981
+ ip: data.ip,
13982
+ country: data.country_name,
13983
+ country_code: data.country_code,
13984
+ country_flag: this.getCountryFlag(data.country_code),
13985
+ city: data.city,
13986
+ region: data.region,
13987
+ timezone: data.timezone,
13988
+ latitude: data.latitude,
13989
+ longitude: data.longitude,
13990
+ postal: data.postal,
13991
+ org: data.org,
13992
+ asn: data.asn,
13993
+ isVpn: data.threat?.is_vpn || false,
13994
+ isProxy: data.threat?.is_proxy || false,
13995
+ isThreat: data.threat?.is_threat || false,
13996
+ isAnonymous: data.threat?.is_anonymous || false,
13997
+ isTor: data.threat?.is_tor || false,
13998
+ securityScore: this.calculateSecurityScore({
13999
+ isVpn: data.threat?.is_vpn,
14000
+ isProxy: data.threat?.is_proxy,
14001
+ isThreat: data.threat?.is_threat,
14002
+ isAnonymous: data.threat?.is_anonymous,
14003
+ isTor: data.threat?.is_tor
14004
+ }),
14005
+ riskLevel: this.getRiskLevel({
14006
+ isVpn: data.threat?.is_vpn,
14007
+ isProxy: data.threat?.is_proxy,
14008
+ isThreat: data.threat?.is_threat
14009
+ }),
14010
+ _status: "ok",
14011
+ _source: "ipapi"
14012
+ };
14013
+ strapi2.log.debug(`[magic-sessionmanager/geolocation] IP ${ipAddress}: ${result.city}, ${result.country} (Score: ${result.securityScore})`);
14014
+ cacheIpapiResult(lookupIp, result, IPAPI_SUCCESS_CACHE_TTL_MS);
14015
+ return result;
14016
+ } catch (error) {
14017
+ const status = error?.name === "AbortError" ? "error" : "error";
14018
+ strapi2.log.error(`[magic-sessionmanager/geolocation] Error fetching IP info for ${lookupIp}:`, error.message);
14019
+ const fallback = this.getFallbackData(lookupIp, status, "ipapi", error.message);
14020
+ cacheIpapiResult(lookupIp, fallback, IPAPI_FAILURE_CACHE_TTL_MS);
14021
+ return fallback;
14022
+ } finally {
14023
+ clearTimeout(timer);
14024
+ releaseSlot();
13783
14025
  }
13784
- const result = {
13785
- ip: data.ip,
13786
- country: data.country_name,
13787
- country_code: data.country_code,
13788
- country_flag: this.getCountryFlag(data.country_code),
13789
- city: data.city,
13790
- region: data.region,
13791
- timezone: data.timezone,
13792
- latitude: data.latitude,
13793
- longitude: data.longitude,
13794
- postal: data.postal,
13795
- org: data.org,
13796
- asn: data.asn,
13797
- isVpn: data.threat?.is_vpn || false,
13798
- isProxy: data.threat?.is_proxy || false,
13799
- isThreat: data.threat?.is_threat || false,
13800
- isAnonymous: data.threat?.is_anonymous || false,
13801
- isTor: data.threat?.is_tor || false,
13802
- securityScore: this.calculateSecurityScore({
13803
- isVpn: data.threat?.is_vpn,
13804
- isProxy: data.threat?.is_proxy,
13805
- isThreat: data.threat?.is_threat,
13806
- isAnonymous: data.threat?.is_anonymous,
13807
- isTor: data.threat?.is_tor
13808
- }),
13809
- riskLevel: this.getRiskLevel({
13810
- isVpn: data.threat?.is_vpn,
13811
- isProxy: data.threat?.is_proxy,
13812
- isThreat: data.threat?.is_threat
13813
- }),
13814
- _status: "ok",
13815
- _source: "ipapi"
13816
- };
13817
- strapi2.log.debug(`[magic-sessionmanager/geolocation] IP ${ipAddress}: ${result.city}, ${result.country} (Score: ${result.securityScore})`);
13818
- return result;
13819
- } catch (error) {
13820
- const status = error?.name === "AbortError" ? "error" : "error";
13821
- strapi2.log.error(`[magic-sessionmanager/geolocation] Error fetching IP info for ${ipAddress}:`, error.message);
13822
- return this.getFallbackData(ipAddress, status, "ipapi", error.message);
14026
+ })();
14027
+ ipapiInFlight.set(lookupIp, lookupPromise);
14028
+ try {
14029
+ return cloneGeoData(await lookupPromise);
13823
14030
  } finally {
13824
- clearTimeout(timer);
14031
+ ipapiInFlight.delete(lookupIp);
13825
14032
  }
13826
14033
  },
13827
14034
  /**
@@ -13868,17 +14075,12 @@ var require_geolocation = __commonJS({
13868
14075
  * @returns {boolean}
13869
14076
  */
13870
14077
  isPrivateIp(ip) {
13871
- if (!ip || ip === "unknown") return true;
13872
- if (ip === "127.0.0.1" || ip === "localhost" || ip === "::1") return true;
13873
- if (ip.startsWith("192.168.")) return true;
13874
- if (ip.startsWith("10.")) return true;
13875
- if (ip.startsWith("172.")) {
13876
- const second = parseInt(ip.split(".")[1], 10);
13877
- if (second >= 16 && second <= 31) return true;
13878
- }
13879
- if (ip.startsWith("169.254.")) return true;
13880
- if (ip.startsWith("fc00:") || ip.startsWith("fd00:")) return true;
13881
- if (ip.startsWith("fe80:")) return true;
14078
+ const normalized = normalizeLookupIp(ip);
14079
+ const lower = normalized.toLowerCase();
14080
+ if (!normalized || lower === "unknown" || lower === "localhost") return true;
14081
+ const version = net.isIP(normalized);
14082
+ if (version === 4) return isPrivateIpv4(normalized);
14083
+ if (version === 6) return isPrivateIpv6(normalized);
13882
14084
  return false;
13883
14085
  },
13884
14086
  /**
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "4.6.3",
2
+ "version": "4.6.4",
3
3
  "keywords": [
4
4
  "strapi",
5
5
  "plugin",