strapi-plugin-magic-sessionmanager 4.22.0 → 4.22.1
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 +49 -0
- package/README.md +46 -36
- package/dist/admin/{Analytics-DeDLGiCe.js → Analytics-B7BAjApz.js} +1 -1
- package/dist/admin/{Analytics-WbCUmkQQ.mjs → Analytics-CIHgaURb.mjs} +1 -1
- package/dist/admin/{App-C4bihk2K.mjs → App-CPE-CQGz.mjs} +2 -2
- package/dist/admin/{App-Bkv-W0Sv.js → App-DJkJC06E.js} +2 -2
- package/dist/admin/{OnlineUsersWidget-CSvNe2rC.js → OnlineUsersWidget-CcjNfzzf.js} +1 -1
- package/dist/admin/{OnlineUsersWidget-q0Z6nbbO.mjs → OnlineUsersWidget-Dou2hxGY.mjs} +1 -1
- package/dist/admin/{Settings-xokFI5LO.js → Settings--eEiHv_a.js} +62 -39
- package/dist/admin/{Settings-avD0DbXP.mjs → Settings-h_exWUiI.mjs} +62 -39
- package/dist/admin/{dashboardModel-D4389iIV.js → dashboardModel-DNT_l-Bk.js} +1 -1
- package/dist/admin/{dashboardModel-BBNRgcEr.mjs → dashboardModel-fApbKGay.mjs} +1 -1
- package/dist/admin/{de-BQlEdBMr.mjs → de-Wz5Emtrb.mjs} +6 -3
- package/dist/admin/{de-HcJ19LKI.js → de-oBmcAcXj.js} +6 -3
- package/dist/admin/{en-DI-98CPM.js → en-B1TN5F62.js} +6 -3
- package/dist/admin/{en-DzuXWL1W.mjs → en-B_1Ka64U.mjs} +6 -3
- package/dist/admin/{es-Cm0Eklav.js → es-Bb515J0p.js} +6 -3
- package/dist/admin/{es-BfyED9YI.mjs → es-CVgw4zsj.mjs} +6 -3
- package/dist/admin/{fr-CzFNGWq0.mjs → fr-0AgMxTFc.mjs} +6 -3
- package/dist/admin/{fr-C3nzszsI.js → fr-yDdwunmg.js} +6 -3
- package/dist/admin/{index-6zc5D8eb.mjs → index-DVQ7tdTC.mjs} +30 -13
- package/dist/admin/{index-Dk5Jqe5U.js → index-qtN2dOm4.js} +30 -13
- package/dist/admin/index.js +1 -1
- package/dist/admin/index.mjs +1 -1
- package/dist/admin/{pt-BPZ6chPT.js → pt-BAB07LY-.js} +6 -3
- package/dist/admin/{pt-DmyQnGI_.mjs → pt-DtM74ffN.mjs} +6 -3
- package/dist/server/index.js +928 -376
- package/dist/server/index.mjs +928 -376
- package/package.json +4 -3
package/dist/server/index.js
CHANGED
|
@@ -1471,10 +1471,249 @@ var require_policy_settings = __commonJS({
|
|
|
1471
1471
|
}
|
|
1472
1472
|
});
|
|
1473
1473
|
|
|
1474
|
+
// server/src/utils/webhook-delivery.js
|
|
1475
|
+
var require_webhook_delivery = __commonJS({
|
|
1476
|
+
"server/src/utils/webhook-delivery.js"(exports2, module2) {
|
|
1477
|
+
"use strict";
|
|
1478
|
+
var crypto = require("node:crypto");
|
|
1479
|
+
var dns = require("node:dns");
|
|
1480
|
+
var https = require("node:https");
|
|
1481
|
+
var net = require("node:net");
|
|
1482
|
+
var SIGNATURE_HEADER = "X-Magic-Sessionmanager-Signature";
|
|
1483
|
+
var EVENT_HEADER = "X-Magic-Sessionmanager-Event";
|
|
1484
|
+
var DELIVERY_HEADER = "X-Magic-Sessionmanager-Delivery";
|
|
1485
|
+
var USER_AGENT = "Strapi-Magic-SessionManager-Webhook/2.0";
|
|
1486
|
+
var TIMEOUT_MS = 5e3;
|
|
1487
|
+
var DEADLINE_MS = 1e4;
|
|
1488
|
+
var MAX_RESPONSE_BYTES = 64 * 1024;
|
|
1489
|
+
var RETRY_DELAYS_MS = Object.freeze([0, 2e3, 1e4]);
|
|
1490
|
+
var BLOCKED = (() => {
|
|
1491
|
+
const list = new net.BlockList();
|
|
1492
|
+
for (const [address, prefix] of [
|
|
1493
|
+
["0.0.0.0", 8],
|
|
1494
|
+
["10.0.0.0", 8],
|
|
1495
|
+
["100.64.0.0", 10],
|
|
1496
|
+
["127.0.0.0", 8],
|
|
1497
|
+
["169.254.0.0", 16],
|
|
1498
|
+
["172.16.0.0", 12],
|
|
1499
|
+
["192.0.0.0", 24],
|
|
1500
|
+
["192.0.2.0", 24],
|
|
1501
|
+
["192.88.99.0", 24],
|
|
1502
|
+
["192.168.0.0", 16],
|
|
1503
|
+
["198.18.0.0", 15],
|
|
1504
|
+
["198.51.100.0", 24],
|
|
1505
|
+
["203.0.113.0", 24],
|
|
1506
|
+
["224.0.0.0", 4],
|
|
1507
|
+
["240.0.0.0", 4]
|
|
1508
|
+
]) {
|
|
1509
|
+
list.addSubnet(address, prefix, "ipv4");
|
|
1510
|
+
}
|
|
1511
|
+
for (const [address, prefix] of [
|
|
1512
|
+
// IPv4-compatible (::a.b.c.d, deprecated) and IPv4-translated
|
|
1513
|
+
// (::ffff:0:a.b.c.d, RFC 2765) forms, which include the unspecified and
|
|
1514
|
+
// loopback addresses (security review 2, hardening 1).
|
|
1515
|
+
["::", 96],
|
|
1516
|
+
["::ffff:0:0:0", 96],
|
|
1517
|
+
// IPv4-mapped addresses (::ffff:0:0/96) are not listed: BlockList
|
|
1518
|
+
// checks them against the IPv4 rules above, and a listed /96 would
|
|
1519
|
+
// match every IPv4 address.
|
|
1520
|
+
["64:ff9b::", 96],
|
|
1521
|
+
["64:ff9b:1::", 48],
|
|
1522
|
+
["100::", 64],
|
|
1523
|
+
["2001::", 23],
|
|
1524
|
+
["2001:db8::", 32],
|
|
1525
|
+
["2002::", 16],
|
|
1526
|
+
["fc00::", 7],
|
|
1527
|
+
["fe80::", 10],
|
|
1528
|
+
["fec0::", 10],
|
|
1529
|
+
["ff00::", 8]
|
|
1530
|
+
]) {
|
|
1531
|
+
list.addSubnet(address, prefix, "ipv6");
|
|
1532
|
+
}
|
|
1533
|
+
return list;
|
|
1534
|
+
})();
|
|
1535
|
+
function isBlockedAddress(address) {
|
|
1536
|
+
let value = String(address || "").trim();
|
|
1537
|
+
if (value.toLowerCase().startsWith("::ffff:") && net.isIPv4(value.slice(7))) {
|
|
1538
|
+
value = value.slice(7);
|
|
1539
|
+
}
|
|
1540
|
+
const version = net.isIP(value);
|
|
1541
|
+
if (version === 0) return true;
|
|
1542
|
+
return BLOCKED.check(value, version === 4 ? "ipv4" : "ipv6");
|
|
1543
|
+
}
|
|
1544
|
+
function signPayload(secret, body, timestamp = Math.floor(Date.now() / 1e3)) {
|
|
1545
|
+
const digest = crypto.createHmac("sha256", secret).update(`${timestamp}.${body}`).digest("hex");
|
|
1546
|
+
return `t=${timestamp},v1=${digest}`;
|
|
1547
|
+
}
|
|
1548
|
+
function verifySignature(secret, body, header, { toleranceSeconds = 300, now = Date.now() } = {}) {
|
|
1549
|
+
const match = /^t=(\d{1,12}),v1=([a-f0-9]{64})$/.exec(String(header || ""));
|
|
1550
|
+
if (!match) return false;
|
|
1551
|
+
const timestamp = Number(match[1]);
|
|
1552
|
+
if (Math.abs(now / 1e3 - timestamp) > toleranceSeconds) return false;
|
|
1553
|
+
const expected = crypto.createHmac("sha256", secret).update(`${timestamp}.${body}`).digest();
|
|
1554
|
+
const given = Buffer.from(match[2], "hex");
|
|
1555
|
+
return given.length === expected.length && crypto.timingSafeEqual(given, expected);
|
|
1556
|
+
}
|
|
1557
|
+
var DeliveryError = class extends Error {
|
|
1558
|
+
/**
|
|
1559
|
+
* @param {string} code Stable code.
|
|
1560
|
+
* @param {boolean} retryable Whether another attempt may succeed.
|
|
1561
|
+
* @param {number|null} [status] HTTP status, when there was one.
|
|
1562
|
+
*/
|
|
1563
|
+
constructor(code, retryable, status = null) {
|
|
1564
|
+
super(code);
|
|
1565
|
+
this.name = "DeliveryError";
|
|
1566
|
+
this.code = code;
|
|
1567
|
+
this.retryable = retryable;
|
|
1568
|
+
this.status = status;
|
|
1569
|
+
}
|
|
1570
|
+
};
|
|
1571
|
+
var resolveAll = (hostname) => dns.promises.lookup(hostname, { all: true, verbatim: true });
|
|
1572
|
+
function httpsPost({ url, address, headers, body, timeoutMs, deadlineMs = DEADLINE_MS }) {
|
|
1573
|
+
return new Promise((resolve, reject) => {
|
|
1574
|
+
const request = https.request(
|
|
1575
|
+
{
|
|
1576
|
+
protocol: "https:",
|
|
1577
|
+
hostname: url.hostname,
|
|
1578
|
+
port: url.port || 443,
|
|
1579
|
+
path: `${url.pathname}${url.search}`,
|
|
1580
|
+
method: "POST",
|
|
1581
|
+
headers: { ...headers, "Content-Length": Buffer.byteLength(body) },
|
|
1582
|
+
servername: net.isIP(url.hostname) ? void 0 : url.hostname,
|
|
1583
|
+
timeout: timeoutMs,
|
|
1584
|
+
signal: AbortSignal.timeout(deadlineMs),
|
|
1585
|
+
// Pinned to the address that passed the check: no second lookup.
|
|
1586
|
+
lookup: (_hostname, options, callback) => {
|
|
1587
|
+
if (options && options.all) callback(null, [address]);
|
|
1588
|
+
else callback(null, address.address, address.family);
|
|
1589
|
+
}
|
|
1590
|
+
},
|
|
1591
|
+
(response) => {
|
|
1592
|
+
let received = 0;
|
|
1593
|
+
response.on("data", (chunk) => {
|
|
1594
|
+
received += chunk.length;
|
|
1595
|
+
if (received > MAX_RESPONSE_BYTES) response.destroy();
|
|
1596
|
+
});
|
|
1597
|
+
response.on("end", () => resolve(response.statusCode || 0));
|
|
1598
|
+
response.on("close", () => resolve(response.statusCode || 0));
|
|
1599
|
+
response.on("error", () => resolve(response.statusCode || 0));
|
|
1600
|
+
}
|
|
1601
|
+
);
|
|
1602
|
+
request.on("timeout", () => request.destroy(new DeliveryError("timeout", true)));
|
|
1603
|
+
request.on(
|
|
1604
|
+
"error",
|
|
1605
|
+
(err) => reject(
|
|
1606
|
+
err instanceof DeliveryError ? err : err?.name === "AbortError" ? new DeliveryError("timeout", true) : new DeliveryError("network_error", true)
|
|
1607
|
+
)
|
|
1608
|
+
);
|
|
1609
|
+
request.end(body);
|
|
1610
|
+
});
|
|
1611
|
+
}
|
|
1612
|
+
async function deliverOnce({
|
|
1613
|
+
url,
|
|
1614
|
+
body,
|
|
1615
|
+
headers,
|
|
1616
|
+
resolve = resolveAll,
|
|
1617
|
+
post = httpsPost,
|
|
1618
|
+
timeoutMs = TIMEOUT_MS,
|
|
1619
|
+
deadlineMs = DEADLINE_MS
|
|
1620
|
+
}) {
|
|
1621
|
+
let parsed;
|
|
1622
|
+
try {
|
|
1623
|
+
parsed = new URL(url);
|
|
1624
|
+
} catch {
|
|
1625
|
+
throw new DeliveryError("invalid_url", false);
|
|
1626
|
+
}
|
|
1627
|
+
if (parsed.protocol !== "https:" || parsed.username || parsed.password) {
|
|
1628
|
+
throw new DeliveryError("invalid_url", false);
|
|
1629
|
+
}
|
|
1630
|
+
const host = parsed.hostname.replace(/^\[|\]$/g, "");
|
|
1631
|
+
let addresses;
|
|
1632
|
+
if (net.isIP(host)) {
|
|
1633
|
+
addresses = [{ address: host, family: net.isIP(host) }];
|
|
1634
|
+
} else {
|
|
1635
|
+
try {
|
|
1636
|
+
addresses = await resolve(host);
|
|
1637
|
+
} catch {
|
|
1638
|
+
throw new DeliveryError("dns_failed", true);
|
|
1639
|
+
}
|
|
1640
|
+
}
|
|
1641
|
+
if (!Array.isArray(addresses) || addresses.length === 0)
|
|
1642
|
+
throw new DeliveryError("dns_failed", true);
|
|
1643
|
+
if (addresses.some((entry) => isBlockedAddress(entry.address))) {
|
|
1644
|
+
throw new DeliveryError("address_not_allowed", false);
|
|
1645
|
+
}
|
|
1646
|
+
const status = await post({
|
|
1647
|
+
url: parsed,
|
|
1648
|
+
address: addresses[0],
|
|
1649
|
+
headers,
|
|
1650
|
+
body,
|
|
1651
|
+
timeoutMs,
|
|
1652
|
+
deadlineMs
|
|
1653
|
+
});
|
|
1654
|
+
if (status >= 200 && status < 300) return { status };
|
|
1655
|
+
if (status >= 300 && status < 400)
|
|
1656
|
+
throw new DeliveryError("redirect_not_followed", false, status);
|
|
1657
|
+
throw new DeliveryError(`http_${status}`, status === 429 || status >= 500, status);
|
|
1658
|
+
}
|
|
1659
|
+
function buildSignedRequest({ event, data, secret, id = crypto.randomUUID(), now = /* @__PURE__ */ new Date() }) {
|
|
1660
|
+
const body = JSON.stringify({ id, event, createdAt: now.toISOString(), data });
|
|
1661
|
+
return {
|
|
1662
|
+
id,
|
|
1663
|
+
body,
|
|
1664
|
+
headers: {
|
|
1665
|
+
"Content-Type": "application/json",
|
|
1666
|
+
"User-Agent": USER_AGENT,
|
|
1667
|
+
[EVENT_HEADER]: event,
|
|
1668
|
+
[DELIVERY_HEADER]: id,
|
|
1669
|
+
[SIGNATURE_HEADER]: signPayload(secret, body, Math.floor(now.getTime() / 1e3))
|
|
1670
|
+
}
|
|
1671
|
+
};
|
|
1672
|
+
}
|
|
1673
|
+
async function deliverWithRetries({
|
|
1674
|
+
delays = RETRY_DELAYS_MS,
|
|
1675
|
+
sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms).unref?.()),
|
|
1676
|
+
...request
|
|
1677
|
+
}) {
|
|
1678
|
+
let attempts = 0;
|
|
1679
|
+
let last = { ok: false, status: null, code: "not_sent" };
|
|
1680
|
+
for (const delay of delays) {
|
|
1681
|
+
if (delay > 0) await sleep(delay);
|
|
1682
|
+
attempts += 1;
|
|
1683
|
+
try {
|
|
1684
|
+
const { status } = await deliverOnce(request);
|
|
1685
|
+
return { ok: true, status, code: null, attempts };
|
|
1686
|
+
} catch (err) {
|
|
1687
|
+
const error = err instanceof DeliveryError ? err : new DeliveryError("network_error", true);
|
|
1688
|
+
last = { ok: false, status: error.status, code: error.code };
|
|
1689
|
+
if (!error.retryable) break;
|
|
1690
|
+
}
|
|
1691
|
+
}
|
|
1692
|
+
return { ...last, attempts };
|
|
1693
|
+
}
|
|
1694
|
+
module2.exports = {
|
|
1695
|
+
DEADLINE_MS,
|
|
1696
|
+
DELIVERY_HEADER,
|
|
1697
|
+
DeliveryError,
|
|
1698
|
+
EVENT_HEADER,
|
|
1699
|
+
RETRY_DELAYS_MS,
|
|
1700
|
+
SIGNATURE_HEADER,
|
|
1701
|
+
buildSignedRequest,
|
|
1702
|
+
deliverOnce,
|
|
1703
|
+
deliverWithRetries,
|
|
1704
|
+
isBlockedAddress,
|
|
1705
|
+
signPayload,
|
|
1706
|
+
verifySignature
|
|
1707
|
+
};
|
|
1708
|
+
}
|
|
1709
|
+
});
|
|
1710
|
+
|
|
1474
1711
|
// server/src/utils/detection-settings.js
|
|
1475
1712
|
var require_detection_settings = __commonJS({
|
|
1476
1713
|
"server/src/utils/detection-settings.js"(exports2, module2) {
|
|
1477
1714
|
"use strict";
|
|
1715
|
+
var net = require("node:net");
|
|
1716
|
+
var { isBlockedAddress } = require_webhook_delivery();
|
|
1478
1717
|
var WEBHOOK_EVENTS = Object.freeze([
|
|
1479
1718
|
"login.success",
|
|
1480
1719
|
"login.suspicious",
|
|
@@ -1559,6 +1798,8 @@ var require_detection_settings = __commonJS({
|
|
|
1559
1798
|
if (!host || host === "localhost" || host.endsWith(".localhost") || host.endsWith(".local")) {
|
|
1560
1799
|
return null;
|
|
1561
1800
|
}
|
|
1801
|
+
const literal = host.replace(/^\[|\]$/g, "");
|
|
1802
|
+
if (net.isIP(literal) && isBlockedAddress(literal)) return null;
|
|
1562
1803
|
return parsed.toString();
|
|
1563
1804
|
}
|
|
1564
1805
|
function normalizeEventList(value) {
|
|
@@ -1929,6 +2170,89 @@ var require_impersonation_rules = __commonJS({
|
|
|
1929
2170
|
}
|
|
1930
2171
|
});
|
|
1931
2172
|
|
|
2173
|
+
// server/src/utils/trusted-proxies.js
|
|
2174
|
+
var require_trusted_proxies = __commonJS({
|
|
2175
|
+
"server/src/utils/trusted-proxies.js"(exports2, module2) {
|
|
2176
|
+
"use strict";
|
|
2177
|
+
var { parseTrustedAddress } = require_policy_settings();
|
|
2178
|
+
var MAX_TRUSTED_PROXIES = 50;
|
|
2179
|
+
function normalizeTrustedProxies(value) {
|
|
2180
|
+
if (!Array.isArray(value)) return [];
|
|
2181
|
+
const out = [];
|
|
2182
|
+
for (const entry of value.slice(0, MAX_TRUSTED_PROXIES)) {
|
|
2183
|
+
const parsed = parseTrustedAddress(entry);
|
|
2184
|
+
if (parsed && !out.includes(parsed.text)) out.push(parsed.text);
|
|
2185
|
+
}
|
|
2186
|
+
return out;
|
|
2187
|
+
}
|
|
2188
|
+
function isLegacyTrustAll(value) {
|
|
2189
|
+
return value === true;
|
|
2190
|
+
}
|
|
2191
|
+
function validateTrustedProxies(value) {
|
|
2192
|
+
if (typeof value === "boolean") return { value: [], error: null, legacyTrue: value };
|
|
2193
|
+
if (!Array.isArray(value) || value.length > MAX_TRUSTED_PROXIES) {
|
|
2194
|
+
return {
|
|
2195
|
+
value: null,
|
|
2196
|
+
legacyTrue: false,
|
|
2197
|
+
error: {
|
|
2198
|
+
path: ["trustedProxies"],
|
|
2199
|
+
message: `trustedProxies must be a list of at most ${MAX_TRUSTED_PROXIES} IP addresses or CIDR ranges`
|
|
2200
|
+
}
|
|
2201
|
+
};
|
|
2202
|
+
}
|
|
2203
|
+
const parsed = value.map(parseTrustedAddress);
|
|
2204
|
+
const invalid = parsed.findIndex((entry) => entry === null);
|
|
2205
|
+
if (invalid !== -1) {
|
|
2206
|
+
return {
|
|
2207
|
+
value: null,
|
|
2208
|
+
legacyTrue: false,
|
|
2209
|
+
error: {
|
|
2210
|
+
path: ["trustedProxies", invalid],
|
|
2211
|
+
message: "Each trusted proxy must be an IP address or a CIDR range such as 10.0.0.0/8"
|
|
2212
|
+
}
|
|
2213
|
+
};
|
|
2214
|
+
}
|
|
2215
|
+
return {
|
|
2216
|
+
value: [...new Set(parsed.map((entry) => (
|
|
2217
|
+
/** @type {any} */
|
|
2218
|
+
entry.text
|
|
2219
|
+
)))],
|
|
2220
|
+
error: null,
|
|
2221
|
+
legacyTrue: false
|
|
2222
|
+
};
|
|
2223
|
+
}
|
|
2224
|
+
var LEGACY_WARNING = "[CONFIG] trustedProxies: true no longer makes the plugin read CF-Connecting-IP, True-Client-IP, X-Real-IP or the left-most X-Forwarded-For entry (a client can set them). The client IP now comes from Strapi's server.proxy settings (koa, ipHeader, maxIpsCount). To trust specific proxies instead, set trustedProxies to a list of their IP addresses or CIDR ranges.";
|
|
2225
|
+
async function migrateLegacyProxyTrust(strapi2, log) {
|
|
2226
|
+
const { withPluginStoreKey } = require_plugin_store();
|
|
2227
|
+
const { notifySettingsChanged } = require_settings_loader();
|
|
2228
|
+
const config2 = isLegacyTrustAll(
|
|
2229
|
+
strapi2.config.get("plugin::magic-sessionmanager")?.trustedProxies
|
|
2230
|
+
);
|
|
2231
|
+
const store = strapi2.store({ type: "plugin", name: "magic-sessionmanager" });
|
|
2232
|
+
let stored = isLegacyTrustAll((await store.get({ key: "settings" }))?.trustedProxies);
|
|
2233
|
+
if (stored) {
|
|
2234
|
+
stored = await withPluginStoreKey(strapi2, "settings", async (scoped) => {
|
|
2235
|
+
const value = await scoped.get({ key: "settings" });
|
|
2236
|
+
if (!value || !isLegacyTrustAll(value.trustedProxies)) return false;
|
|
2237
|
+
await scoped.set({ key: "settings", value: { ...value, trustedProxies: [] } });
|
|
2238
|
+
return true;
|
|
2239
|
+
});
|
|
2240
|
+
if (stored) await notifySettingsChanged(strapi2);
|
|
2241
|
+
}
|
|
2242
|
+
if (stored || config2) log.warn(LEGACY_WARNING);
|
|
2243
|
+
return { stored, config: config2 };
|
|
2244
|
+
}
|
|
2245
|
+
module2.exports = {
|
|
2246
|
+
LEGACY_WARNING,
|
|
2247
|
+
MAX_TRUSTED_PROXIES,
|
|
2248
|
+
isLegacyTrustAll,
|
|
2249
|
+
migrateLegacyProxyTrust,
|
|
2250
|
+
normalizeTrustedProxies,
|
|
2251
|
+
validateTrustedProxies
|
|
2252
|
+
};
|
|
2253
|
+
}
|
|
2254
|
+
});
|
|
2255
|
+
|
|
1932
2256
|
// server/src/utils/settings-loader.js
|
|
1933
2257
|
var require_settings_loader = __commonJS({
|
|
1934
2258
|
"server/src/utils/settings-loader.js"(exports2, module2) {
|
|
@@ -1937,6 +2261,7 @@ var require_settings_loader = __commonJS({
|
|
|
1937
2261
|
var { normalizePolicySettings } = require_policy_settings();
|
|
1938
2262
|
var { normalizeDetectionSettings } = require_detection_settings();
|
|
1939
2263
|
var { normalizeImpersonationSettings } = require_impersonation_rules();
|
|
2264
|
+
var { normalizeTrustedProxies } = require_trusted_proxies();
|
|
1940
2265
|
var PLUGIN_ID = "magic-sessionmanager";
|
|
1941
2266
|
var SETTINGS_KEY = "settings";
|
|
1942
2267
|
var CACHE_TTL_MS = 30 * 1e3;
|
|
@@ -2066,7 +2391,8 @@ var require_settings_loader = __commonJS({
|
|
|
2066
2391
|
out.securityLogRetentionDays = toIntInRange(stored.securityLogRetentionDays, 90, 7, 730);
|
|
2067
2392
|
}
|
|
2068
2393
|
if (stored.trustedProxies !== void 0) {
|
|
2069
|
-
|
|
2394
|
+
const proxies = normalizeTrustedProxies(stored.trustedProxies);
|
|
2395
|
+
if (proxies.length > 0) out.trustedProxies = proxies;
|
|
2070
2396
|
}
|
|
2071
2397
|
Object.assign(out, normalizePolicySettings(stored));
|
|
2072
2398
|
Object.assign(out, normalizeDetectionSettings(stored));
|
|
@@ -2185,6 +2511,8 @@ var require_security_log_model = __commonJS({
|
|
|
2185
2511
|
SETTINGS_UPDATED: "settings.updated",
|
|
2186
2512
|
LOG_RETENTION_PURGED: "security-log.retention.purged",
|
|
2187
2513
|
LOG_READ: "security-log.read",
|
|
2514
|
+
// 4.22.1: SESSION_ENCRYPTION_KEY shorter than 32 bytes, once per key.
|
|
2515
|
+
CONFIG_WEAK_KEY: "config.encryption-key.weak",
|
|
2188
2516
|
// App users (Users & Permissions), 4.17.
|
|
2189
2517
|
USER_SIGN_IN_FAILED: "user.sign-in.failed",
|
|
2190
2518
|
USER_SIGN_IN_REFUSED: "user.sign-in.refused",
|
|
@@ -2248,7 +2576,8 @@ var require_security_log_model = __commonJS({
|
|
|
2248
2576
|
var ADMIN_LOG_EVENTS = Object.freeze([
|
|
2249
2577
|
SECURITY_EVENTS.SETTINGS_UPDATED,
|
|
2250
2578
|
SECURITY_EVENTS.LOG_READ,
|
|
2251
|
-
SECURITY_EVENTS.LOG_RETENTION_PURGED
|
|
2579
|
+
SECURITY_EVENTS.LOG_RETENTION_PURGED,
|
|
2580
|
+
SECURITY_EVENTS.CONFIG_WEAK_KEY
|
|
2252
2581
|
]);
|
|
2253
2582
|
var SIGN_IN_FILTERS = Object.freeze({
|
|
2254
2583
|
all: [...ADMIN_SIGN_IN_EVENTS, ...ADMIN_LOG_EVENTS],
|
|
@@ -2657,6 +2986,176 @@ var require_security_log_hardening = __commonJS({
|
|
|
2657
2986
|
}
|
|
2658
2987
|
});
|
|
2659
2988
|
|
|
2989
|
+
// server/src/utils/graphql-impersonation-guard.js
|
|
2990
|
+
var require_graphql_impersonation_guard = __commonJS({
|
|
2991
|
+
"server/src/utils/graphql-impersonation-guard.js"(exports2, module2) {
|
|
2992
|
+
"use strict";
|
|
2993
|
+
var { errors } = require("@strapi/utils");
|
|
2994
|
+
var MARK = /* @__PURE__ */ Symbol.for("magic-sessionmanager.graphql-impersonation-guard");
|
|
2995
|
+
var MESSAGE = "Not allowed while impersonating";
|
|
2996
|
+
var REASON = "impersonation-mutation";
|
|
2997
|
+
function impersonationRefusal() {
|
|
2998
|
+
const error = new errors.ForbiddenError(MESSAGE, { reason: REASON });
|
|
2999
|
+
Object.defineProperty(error, "extensions", {
|
|
3000
|
+
value: {
|
|
3001
|
+
code: "FORBIDDEN",
|
|
3002
|
+
http: { status: 403 },
|
|
3003
|
+
error: { name: "ForbiddenError", message: MESSAGE, details: { reason: REASON } }
|
|
3004
|
+
},
|
|
3005
|
+
enumerable: false
|
|
3006
|
+
});
|
|
3007
|
+
return error;
|
|
3008
|
+
}
|
|
3009
|
+
function impersonationOf(contextValue) {
|
|
3010
|
+
const mark = contextValue?.koaContext?.state?.magicImpersonation ?? contextValue?.state?.magicImpersonation;
|
|
3011
|
+
return mark && typeof mark === "object" && typeof mark.id === "string" ? mark : null;
|
|
3012
|
+
}
|
|
3013
|
+
function createImpersonationApolloPlugin(strapi2) {
|
|
3014
|
+
return {
|
|
3015
|
+
[MARK]: true,
|
|
3016
|
+
async requestDidStart() {
|
|
3017
|
+
return {
|
|
3018
|
+
/**
|
|
3019
|
+
* @param {any} requestContext Apollo request context.
|
|
3020
|
+
* @returns {Promise<void>}
|
|
3021
|
+
* @throws {Error} ForbiddenError (HTTP 403, code FORBIDDEN) for a mutation while impersonating.
|
|
3022
|
+
*/
|
|
3023
|
+
async didResolveOperation(requestContext) {
|
|
3024
|
+
if (requestContext?.operation?.operation !== "mutation") return;
|
|
3025
|
+
const impersonation = impersonationOf(requestContext.contextValue);
|
|
3026
|
+
if (!impersonation) return;
|
|
3027
|
+
try {
|
|
3028
|
+
strapi2.plugin("magic-sessionmanager").service("impersonation").recordRefusedCall(impersonation, "mutation");
|
|
3029
|
+
} catch {
|
|
3030
|
+
}
|
|
3031
|
+
throw impersonationRefusal();
|
|
3032
|
+
}
|
|
3033
|
+
};
|
|
3034
|
+
}
|
|
3035
|
+
};
|
|
3036
|
+
}
|
|
3037
|
+
function installGraphqlImpersonationGuard(strapi2, log) {
|
|
3038
|
+
let graphql;
|
|
3039
|
+
try {
|
|
3040
|
+
graphql = strapi2.plugin("graphql") || null;
|
|
3041
|
+
} catch {
|
|
3042
|
+
graphql = null;
|
|
3043
|
+
}
|
|
3044
|
+
if (!graphql) return false;
|
|
3045
|
+
if (typeof strapi2.config?.get !== "function" || typeof strapi2.config?.set !== "function") {
|
|
3046
|
+
return false;
|
|
3047
|
+
}
|
|
3048
|
+
try {
|
|
3049
|
+
const key = "plugin::graphql.apolloServer";
|
|
3050
|
+
const current = strapi2.config.get(key);
|
|
3051
|
+
const server = current && typeof current === "object" ? current : {};
|
|
3052
|
+
const plugins = Array.isArray(server.plugins) ? server.plugins : [];
|
|
3053
|
+
if (plugins.some((plugin) => plugin && plugin[MARK])) return true;
|
|
3054
|
+
strapi2.config.set(key, {
|
|
3055
|
+
...server,
|
|
3056
|
+
plugins: [...plugins, createImpersonationApolloPlugin(strapi2)]
|
|
3057
|
+
});
|
|
3058
|
+
} catch (err) {
|
|
3059
|
+
log?.warn?.("[IMPERSONATION] GraphQL guard could not be installed:", err?.name || "Error");
|
|
3060
|
+
return false;
|
|
3061
|
+
}
|
|
3062
|
+
log?.info?.("[IMPERSONATION] GraphQL mutations are refused while impersonating");
|
|
3063
|
+
return true;
|
|
3064
|
+
}
|
|
3065
|
+
module2.exports = {
|
|
3066
|
+
createImpersonationApolloPlugin,
|
|
3067
|
+
impersonationRefusal,
|
|
3068
|
+
installGraphqlImpersonationGuard
|
|
3069
|
+
};
|
|
3070
|
+
}
|
|
3071
|
+
});
|
|
3072
|
+
|
|
3073
|
+
// server/src/utils/auth-controller-guard.js
|
|
3074
|
+
var require_auth_controller_guard = __commonJS({
|
|
3075
|
+
"server/src/utils/auth-controller-guard.js"(exports2, module2) {
|
|
3076
|
+
"use strict";
|
|
3077
|
+
var WRAPPED = /* @__PURE__ */ Symbol.for("magic-sessionmanager.auth-controller.wrapped");
|
|
3078
|
+
var GUARDED_ACTIONS = Object.freeze({
|
|
3079
|
+
callback: "callback",
|
|
3080
|
+
register: "newSession",
|
|
3081
|
+
resetPassword: "newSession",
|
|
3082
|
+
emailConfirmation: "newSession"
|
|
3083
|
+
});
|
|
3084
|
+
var handlersByStrapi = /* @__PURE__ */ new WeakMap();
|
|
3085
|
+
function installAuthControllerGuard(strapi2, log) {
|
|
3086
|
+
let controller;
|
|
3087
|
+
try {
|
|
3088
|
+
controller = strapi2.plugin("users-permissions")?.controller("auth");
|
|
3089
|
+
} catch {
|
|
3090
|
+
controller = null;
|
|
3091
|
+
}
|
|
3092
|
+
if (!controller || typeof controller !== "object") {
|
|
3093
|
+
log?.warn?.(
|
|
3094
|
+
"[AUTH] Users & Permissions auth controller not found; sign-in checks use paths only"
|
|
3095
|
+
);
|
|
3096
|
+
return [];
|
|
3097
|
+
}
|
|
3098
|
+
const wrapped = [];
|
|
3099
|
+
for (const [action, kind] of Object.entries(GUARDED_ACTIONS)) {
|
|
3100
|
+
const original = controller[action];
|
|
3101
|
+
if (typeof original !== "function") continue;
|
|
3102
|
+
if (original[WRAPPED]) {
|
|
3103
|
+
wrapped.push(action);
|
|
3104
|
+
continue;
|
|
3105
|
+
}
|
|
3106
|
+
const guarded = async function magicSessionAuthGuard(ctx, ...rest) {
|
|
3107
|
+
const run = () => original.call(this, ctx, ...rest);
|
|
3108
|
+
const handlers = handlersByStrapi.get(strapi2);
|
|
3109
|
+
if (!handlers || typeof handlers[kind] !== "function") return run();
|
|
3110
|
+
return handlers[kind](ctx, run);
|
|
3111
|
+
};
|
|
3112
|
+
Object.defineProperty(guarded, WRAPPED, { value: original });
|
|
3113
|
+
controller[action] = guarded;
|
|
3114
|
+
wrapped.push(action);
|
|
3115
|
+
}
|
|
3116
|
+
return wrapped;
|
|
3117
|
+
}
|
|
3118
|
+
function setAuthControllerHandlers(strapi2, handlers) {
|
|
3119
|
+
if (handlers) handlersByStrapi.set(strapi2, handlers);
|
|
3120
|
+
else handlersByStrapi.delete(strapi2);
|
|
3121
|
+
}
|
|
3122
|
+
function uninstallAuthControllerGuard(strapi2) {
|
|
3123
|
+
setAuthControllerHandlers(strapi2, null);
|
|
3124
|
+
let controller;
|
|
3125
|
+
try {
|
|
3126
|
+
controller = strapi2.plugin("users-permissions")?.controller("auth");
|
|
3127
|
+
} catch {
|
|
3128
|
+
return;
|
|
3129
|
+
}
|
|
3130
|
+
if (!controller) return;
|
|
3131
|
+
for (const action of Object.keys(GUARDED_ACTIONS)) {
|
|
3132
|
+
const original = controller[action]?.[WRAPPED];
|
|
3133
|
+
if (typeof original === "function") controller[action] = original;
|
|
3134
|
+
}
|
|
3135
|
+
}
|
|
3136
|
+
var INVALID_CREDENTIALS_MESSAGE = "Invalid identifier or password";
|
|
3137
|
+
function classifyCallbackOutcome(thrown, ctx) {
|
|
3138
|
+
if (thrown) {
|
|
3139
|
+
const error = (
|
|
3140
|
+
/** @type {any} */
|
|
3141
|
+
thrown
|
|
3142
|
+
);
|
|
3143
|
+
return error?.name === "ValidationError" && error?.message === INVALID_CREDENTIALS_MESSAGE ? "failure" : "neutral";
|
|
3144
|
+
}
|
|
3145
|
+
const body = ctx?.body;
|
|
3146
|
+
return body && typeof body === "object" && body.jwt ? "success" : "neutral";
|
|
3147
|
+
}
|
|
3148
|
+
module2.exports = {
|
|
3149
|
+
GUARDED_ACTIONS,
|
|
3150
|
+
INVALID_CREDENTIALS_MESSAGE,
|
|
3151
|
+
classifyCallbackOutcome,
|
|
3152
|
+
installAuthControllerGuard,
|
|
3153
|
+
setAuthControllerHandlers,
|
|
3154
|
+
uninstallAuthControllerGuard
|
|
3155
|
+
};
|
|
3156
|
+
}
|
|
3157
|
+
});
|
|
3158
|
+
|
|
2660
3159
|
// server/src/register.js
|
|
2661
3160
|
var require_register = __commonJS({
|
|
2662
3161
|
"server/src/register.js"(exports2, module2) {
|
|
@@ -2666,6 +3165,8 @@ var require_register = __commonJS({
|
|
|
2666
3165
|
var { isCallerRevocationScope } = require_block_revocation_scope();
|
|
2667
3166
|
var { checkStrapiVersion } = require_strapi_version();
|
|
2668
3167
|
var { disableGraphqlShadowCrud } = require_security_log_hardening();
|
|
3168
|
+
var { installGraphqlImpersonationGuard } = require_graphql_impersonation_guard();
|
|
3169
|
+
var { installAuthControllerGuard } = require_auth_controller_guard();
|
|
2669
3170
|
var USER_UID = "plugin::users-permissions.user";
|
|
2670
3171
|
module2.exports = async ({ strapi: strapi2 }) => {
|
|
2671
3172
|
const log = createLogger(strapi2);
|
|
@@ -2764,6 +3265,8 @@ var require_register = __commonJS({
|
|
|
2764
3265
|
}
|
|
2765
3266
|
]);
|
|
2766
3267
|
disableGraphqlShadowCrud(strapi2, log);
|
|
3268
|
+
installGraphqlImpersonationGuard(strapi2, log);
|
|
3269
|
+
installAuthControllerGuard(strapi2, log);
|
|
2767
3270
|
try {
|
|
2768
3271
|
strapi2.db.lifecycles.subscribe(createContentApiPermissionsLifecycle(strapi2));
|
|
2769
3272
|
} catch (err) {
|
|
@@ -2839,42 +3342,69 @@ var require_register = __commonJS({
|
|
|
2839
3342
|
var require_getClientIp = __commonJS({
|
|
2840
3343
|
"server/src/utils/getClientIp.js"(exports2, module2) {
|
|
2841
3344
|
"use strict";
|
|
2842
|
-
|
|
2843
|
-
|
|
2844
|
-
|
|
2845
|
-
|
|
2846
|
-
|
|
3345
|
+
var net = require("node:net");
|
|
3346
|
+
var { isTrustedAddress } = require_policy_settings();
|
|
3347
|
+
var { normalizeTrustedProxies } = require_trusted_proxies();
|
|
3348
|
+
var MAX_FORWARDED_LENGTH = 2048;
|
|
3349
|
+
var MAX_FORWARDED_HOPS = 20;
|
|
3350
|
+
var cleanIp = (ip) => {
|
|
3351
|
+
if (!ip) return "unknown";
|
|
3352
|
+
let value = String(ip).trim();
|
|
3353
|
+
if (value.startsWith("[")) {
|
|
3354
|
+
const bracketEnd = value.indexOf("]");
|
|
3355
|
+
if (bracketEnd !== -1) {
|
|
3356
|
+
value = value.substring(1, bracketEnd);
|
|
3357
|
+
}
|
|
3358
|
+
}
|
|
3359
|
+
if (value.toLowerCase().startsWith("::ffff:") && net.isIPv4(value.substring(7))) {
|
|
3360
|
+
value = value.substring(7);
|
|
2847
3361
|
}
|
|
3362
|
+
if (value.includes(".") && value.includes(":") && value.indexOf(":") === value.lastIndexOf(":")) {
|
|
3363
|
+
value = value.split(":")[0];
|
|
3364
|
+
}
|
|
3365
|
+
return value || "unknown";
|
|
3366
|
+
};
|
|
3367
|
+
function trustedProxyList(ctx) {
|
|
3368
|
+
const fromSettings = ctx?.state?.__magicSessionSettings?.trustedProxies;
|
|
3369
|
+
if (fromSettings !== void 0) return normalizeTrustedProxies(fromSettings);
|
|
2848
3370
|
try {
|
|
2849
|
-
const config2 = ctx?.
|
|
2850
|
-
|
|
2851
|
-
if (trusted === true) return true;
|
|
2852
|
-
if (Array.isArray(trusted) && trusted.length > 0) return true;
|
|
3371
|
+
const config2 = ctx?.app?.context?.strapi?.config?.get?.("plugin::magic-sessionmanager");
|
|
3372
|
+
return normalizeTrustedProxies(config2?.trustedProxies);
|
|
2853
3373
|
} catch {
|
|
3374
|
+
return [];
|
|
2854
3375
|
}
|
|
2855
|
-
|
|
3376
|
+
}
|
|
3377
|
+
function socketAddress(ctx) {
|
|
3378
|
+
const raw = ctx?.req?.socket?.remoteAddress ?? ctx?.request?.socket?.remoteAddress;
|
|
3379
|
+
const cleaned = cleanIp(raw);
|
|
3380
|
+
return cleaned !== "unknown" && net.isIP(cleaned) ? cleaned : null;
|
|
3381
|
+
}
|
|
3382
|
+
function rightMostUntrustedHop(ctx, proxies) {
|
|
3383
|
+
const headers = ctx?.request?.headers || ctx?.request?.header || {};
|
|
3384
|
+
let header = headers["x-forwarded-for"];
|
|
3385
|
+
if (Array.isArray(header)) header = header.join(",");
|
|
3386
|
+
if (typeof header !== "string" || !header) return null;
|
|
3387
|
+
const hops = header.slice(0, MAX_FORWARDED_LENGTH).split(",").map((hop) => cleanIp(hop)).slice(-MAX_FORWARDED_HOPS);
|
|
3388
|
+
let lastValid = null;
|
|
3389
|
+
for (let index = hops.length - 1; index >= 0; index--) {
|
|
3390
|
+
const hop = hops[index];
|
|
3391
|
+
if (!net.isIP(hop)) return lastValid;
|
|
3392
|
+
if (!isTrustedAddress(proxies, hop)) return hop;
|
|
3393
|
+
lastValid = hop;
|
|
3394
|
+
}
|
|
3395
|
+
return lastValid;
|
|
2856
3396
|
}
|
|
2857
3397
|
var getClientIp = (ctx) => {
|
|
2858
3398
|
try {
|
|
2859
|
-
const
|
|
2860
|
-
|
|
2861
|
-
|
|
2862
|
-
if (
|
|
2863
|
-
|
|
2864
|
-
|
|
2865
|
-
if (
|
|
2866
|
-
|
|
2867
|
-
|
|
2868
|
-
if (clientIp) return cleanIp(clientIp);
|
|
2869
|
-
}
|
|
2870
|
-
if (headers["x-client-ip"]) return cleanIp(headers["x-client-ip"]);
|
|
2871
|
-
if (headers["x-cluster-client-ip"]) return cleanIp(headers["x-cluster-client-ip"]);
|
|
2872
|
-
if (headers["forwarded"]) {
|
|
2873
|
-
const match = headers["forwarded"].match(/for=([^;,\s]+)/);
|
|
2874
|
-
if (match && match[1]) return cleanIp(match[1].replace(/"/g, ""));
|
|
2875
|
-
}
|
|
2876
|
-
}
|
|
2877
|
-
if (ctx.request.ip) return cleanIp(ctx.request.ip);
|
|
3399
|
+
const proxies = trustedProxyList(ctx);
|
|
3400
|
+
if (proxies.length > 0) {
|
|
3401
|
+
const peer = socketAddress(ctx);
|
|
3402
|
+
if (peer && isTrustedAddress(proxies, peer)) {
|
|
3403
|
+
return rightMostUntrustedHop(ctx, proxies) || peer;
|
|
3404
|
+
}
|
|
3405
|
+
if (peer) return peer;
|
|
3406
|
+
}
|
|
3407
|
+
if (ctx?.request?.ip) return cleanIp(ctx.request.ip);
|
|
2878
3408
|
return "unknown";
|
|
2879
3409
|
} catch (error) {
|
|
2880
3410
|
if (ctx?.app?.context?.strapi?.log?.debug) {
|
|
@@ -2886,24 +3416,8 @@ var require_getClientIp = __commonJS({
|
|
|
2886
3416
|
return "unknown";
|
|
2887
3417
|
}
|
|
2888
3418
|
};
|
|
2889
|
-
var cleanIp = (ip) => {
|
|
2890
|
-
if (!ip) return "unknown";
|
|
2891
|
-
ip = String(ip).trim();
|
|
2892
|
-
if (ip.startsWith("[")) {
|
|
2893
|
-
const bracketEnd = ip.indexOf("]");
|
|
2894
|
-
if (bracketEnd !== -1) {
|
|
2895
|
-
ip = ip.substring(1, bracketEnd);
|
|
2896
|
-
}
|
|
2897
|
-
}
|
|
2898
|
-
if (ip.startsWith("::ffff:")) {
|
|
2899
|
-
ip = ip.substring(7);
|
|
2900
|
-
}
|
|
2901
|
-
if (ip.includes(".") && ip.includes(":") && ip.indexOf(":") === ip.lastIndexOf(":")) {
|
|
2902
|
-
ip = ip.split(":")[0];
|
|
2903
|
-
}
|
|
2904
|
-
return ip || "unknown";
|
|
2905
|
-
};
|
|
2906
3419
|
module2.exports = getClientIp;
|
|
3420
|
+
module2.exports.cleanIp = cleanIp;
|
|
2907
3421
|
}
|
|
2908
3422
|
});
|
|
2909
3423
|
|
|
@@ -2916,10 +3430,22 @@ var require_encryption = __commonJS({
|
|
|
2916
3430
|
var IV_LENGTH = 16;
|
|
2917
3431
|
var AUTH_TAG_LENGTH = 16;
|
|
2918
3432
|
var warnedMissingKey = false;
|
|
3433
|
+
var warnedShortKey = false;
|
|
3434
|
+
var MIN_KEY_BYTES = 32;
|
|
3435
|
+
function isEncryptionKeyShort() {
|
|
3436
|
+
const envKey = process.env.SESSION_ENCRYPTION_KEY;
|
|
3437
|
+
return typeof envKey === "string" && envKey.length > 0 ? Buffer.byteLength(envKey, "utf8") < MIN_KEY_BYTES : false;
|
|
3438
|
+
}
|
|
2919
3439
|
var isProduction = () => process.env.NODE_ENV === "production";
|
|
2920
3440
|
function getEncryptionKey() {
|
|
2921
3441
|
const envKey = process.env.SESSION_ENCRYPTION_KEY;
|
|
2922
3442
|
if (envKey && envKey.length > 0) {
|
|
3443
|
+
if (!warnedShortKey && isEncryptionKeyShort()) {
|
|
3444
|
+
warnedShortKey = true;
|
|
3445
|
+
console.warn(
|
|
3446
|
+
`[magic-sessionmanager] SESSION_ENCRYPTION_KEY is shorter than ${MIN_KEY_BYTES} bytes. It still works, but the next major version will refuse to start with it. Use 32 random bytes (64 hex characters).`
|
|
3447
|
+
);
|
|
3448
|
+
}
|
|
2923
3449
|
return crypto.createHash("sha256").update(envKey).digest();
|
|
2924
3450
|
}
|
|
2925
3451
|
if (isProduction()) {
|
|
@@ -3003,6 +3529,8 @@ var require_encryption = __commonJS({
|
|
|
3003
3529
|
);
|
|
3004
3530
|
}
|
|
3005
3531
|
module2.exports = {
|
|
3532
|
+
MIN_KEY_BYTES,
|
|
3533
|
+
isEncryptionKeyShort,
|
|
3006
3534
|
derivePurposeKey,
|
|
3007
3535
|
getEncryptionKeyCheck,
|
|
3008
3536
|
encryptToken,
|
|
@@ -3552,7 +4080,6 @@ var require_auth_routes = __commonJS({
|
|
|
3552
4080
|
"POST /api/magic-link/login-totp"
|
|
3553
4081
|
]);
|
|
3554
4082
|
var FAILED_LOGIN_ROUTES = /* @__PURE__ */ new Set([
|
|
3555
|
-
"POST /api/auth/local",
|
|
3556
4083
|
"POST /api/magic-link/login-totp",
|
|
3557
4084
|
"POST /api/magic-link/otp/verify",
|
|
3558
4085
|
"POST /api/magic-link/verify-mfa-totp"
|
|
@@ -3595,18 +4122,24 @@ var require_auth_routes = __commonJS({
|
|
|
3595
4122
|
if (!trimmed) return DEFAULT_API_PREFIX;
|
|
3596
4123
|
return trimmed.startsWith("/") ? trimmed : `/${trimmed}`;
|
|
3597
4124
|
}
|
|
4125
|
+
function normalizeRequestPath(path) {
|
|
4126
|
+
const value = path.toLowerCase().replace(/\/{2,}/g, "/");
|
|
4127
|
+
return value.length > 1 ? value.replace(/\/+$/, "") || "/" : value;
|
|
4128
|
+
}
|
|
3598
4129
|
function toCanonicalApiPath(path, prefix) {
|
|
3599
4130
|
if (typeof path !== "string") return null;
|
|
3600
|
-
const
|
|
3601
|
-
|
|
3602
|
-
if (
|
|
3603
|
-
if (
|
|
3604
|
-
|
|
4131
|
+
const normalizedPath = normalizeRequestPath(path);
|
|
4132
|
+
const normalized = normalizeApiPrefix(prefix).toLowerCase();
|
|
4133
|
+
if (normalized === DEFAULT_API_PREFIX) return normalizedPath;
|
|
4134
|
+
if (normalizedPath === normalized) return DEFAULT_API_PREFIX;
|
|
4135
|
+
if (normalizedPath.startsWith(`${normalized}/`)) {
|
|
4136
|
+
return `${DEFAULT_API_PREFIX}${normalizedPath.slice(normalized.length)}`;
|
|
3605
4137
|
}
|
|
3606
4138
|
return null;
|
|
3607
4139
|
}
|
|
3608
4140
|
module2.exports = {
|
|
3609
4141
|
normalizeApiPrefix,
|
|
4142
|
+
normalizeRequestPath,
|
|
3610
4143
|
toCanonicalApiPath,
|
|
3611
4144
|
classifyJwtIssuingRequest,
|
|
3612
4145
|
isFailedLoginTrackedPath,
|
|
@@ -4266,6 +4799,15 @@ var require_admin_request_info = __commonJS({
|
|
|
4266
4799
|
}
|
|
4267
4800
|
return null;
|
|
4268
4801
|
}
|
|
4802
|
+
function ipBucket(ip) {
|
|
4803
|
+
const value = normalizeIp(typeof ip === "string" ? ip : "");
|
|
4804
|
+
if (!value) return null;
|
|
4805
|
+
if (net.isIPv4(value)) return value;
|
|
4806
|
+
if (net.isIPv6(value)) {
|
|
4807
|
+
return `${ipv6Groups(value).slice(0, 4).map((group) => group.toString(16)).join(":")}::/64`;
|
|
4808
|
+
}
|
|
4809
|
+
return null;
|
|
4810
|
+
}
|
|
4269
4811
|
function getRequestUserAgent(ctx) {
|
|
4270
4812
|
const value = ctx?.request?.headers?.["user-agent"];
|
|
4271
4813
|
if (typeof value !== "string" || !value.trim()) return null;
|
|
@@ -4292,6 +4834,7 @@ var require_admin_request_info = __commonJS({
|
|
|
4292
4834
|
module2.exports = {
|
|
4293
4835
|
MAX_USER_AGENT_LENGTH,
|
|
4294
4836
|
anonymizeIp,
|
|
4837
|
+
ipBucket,
|
|
4295
4838
|
describeUserAgent,
|
|
4296
4839
|
getRequestIp,
|
|
4297
4840
|
getSocketIp,
|
|
@@ -4592,6 +5135,7 @@ var require_login_lockout = __commonJS({
|
|
|
4592
5135
|
"use strict";
|
|
4593
5136
|
var { hashedKey } = require_coordination();
|
|
4594
5137
|
var { isTrustedAddress } = require_policy_settings();
|
|
5138
|
+
var { ipBucket } = require_admin_request_info();
|
|
4595
5139
|
var LOCK_PREFIX = "lock:";
|
|
4596
5140
|
var KEY_PATTERN = /^(lf|la):[a-f0-9]{48}$/;
|
|
4597
5141
|
var MAX_LISTED_LOCKS = 200;
|
|
@@ -4601,7 +5145,7 @@ var require_login_lockout = __commonJS({
|
|
|
4601
5145
|
if (!value || value.length > 254) return null;
|
|
4602
5146
|
return value;
|
|
4603
5147
|
}
|
|
4604
|
-
var ipKey = (ip) => hashedKey("lf", ip);
|
|
5148
|
+
var ipKey = (ip) => hashedKey("lf", ipBucket(ip) || ip);
|
|
4605
5149
|
var accountKey = (identifier) => hashedKey("la", identifier);
|
|
4606
5150
|
function createLoginLockout(coordinator, { now = () => Date.now() } = {}) {
|
|
4607
5151
|
const remainingSeconds = async (key) => {
|
|
@@ -4621,15 +5165,18 @@ var require_login_lockout = __commonJS({
|
|
|
4621
5165
|
* Checks the locks and counts the attempt before the password check.
|
|
4622
5166
|
*
|
|
4623
5167
|
* @param {{ip: string|null, identifier: string|null, policy: LockoutPolicy,
|
|
4624
|
-
* accountMax: number}} input Client IP, normalised
|
|
4625
|
-
* account threshold for this account's role
|
|
5168
|
+
* accountMax: number, accountExempt?: boolean}} input Client IP, normalised
|
|
5169
|
+
* identifier, policy, the account threshold for this account's role, and
|
|
5170
|
+
* whether the request comes from a device the account is known to use.
|
|
4626
5171
|
* @returns {Promise<{outcome: 'allow'|'locked'|'busy', retryAfter: number,
|
|
4627
5172
|
* lockedKind: 'ip'|'account'|null, reservation: Reservation}>} Decision.
|
|
4628
5173
|
* @sideeffect Increments the shared counters.
|
|
4629
5174
|
*/
|
|
4630
|
-
async reserve({ ip, identifier, policy, accountMax }) {
|
|
4631
|
-
const
|
|
4632
|
-
const
|
|
5175
|
+
async reserve({ ip, identifier, policy, accountMax, accountExempt = false }) {
|
|
5176
|
+
const knownIp = typeof ip === "string" && !!ip && ip !== "unknown";
|
|
5177
|
+
const trusted = knownIp && isTrustedAddress(policy.trusted, ip);
|
|
5178
|
+
const countIp = policy.ipMax > 0 && knownIp && !trusted;
|
|
5179
|
+
const countAccount = accountMax > 0 && typeof identifier === "string" && !!identifier && !trusted && accountExempt !== true;
|
|
4633
5180
|
const reservation = {
|
|
4634
5181
|
ipKey: countIp ? ipKey(
|
|
4635
5182
|
/** @type {string} */
|
|
@@ -4682,10 +5229,8 @@ var require_login_lockout = __commonJS({
|
|
|
4682
5229
|
*/
|
|
4683
5230
|
async settle(reservation, result, { policy, accountMax, display = {} }) {
|
|
4684
5231
|
if (result === "success") {
|
|
4685
|
-
|
|
4686
|
-
|
|
4687
|
-
await coordinator.clear(key);
|
|
4688
|
-
}
|
|
5232
|
+
if (reservation.ipKey) await coordinator.release(reservation.ipKey);
|
|
5233
|
+
if (reservation.accountKey) await coordinator.clear(reservation.accountKey);
|
|
4689
5234
|
return [];
|
|
4690
5235
|
}
|
|
4691
5236
|
if (result !== "failure") {
|
|
@@ -5149,6 +5694,15 @@ var require_sign_in_signals = __commonJS({
|
|
|
5149
5694
|
});
|
|
5150
5695
|
return Array.isArray(rows) ? rows : [];
|
|
5151
5696
|
}
|
|
5697
|
+
async function isRecognizedDevice(strapi2, userDocumentId, { userAgent, deviceId }) {
|
|
5698
|
+
if (typeof userDocumentId !== "string" || !userDocumentId) return false;
|
|
5699
|
+
if (typeof deviceId !== "string" || !deviceId) return false;
|
|
5700
|
+
const deviceKey = deviceKeyOf(userAgent || "", deviceId);
|
|
5701
|
+
const count = await strapi2.documents(SESSION_UID).count({
|
|
5702
|
+
filters: { user: { documentId: userDocumentId }, deviceKey }
|
|
5703
|
+
});
|
|
5704
|
+
return Number(count) > 0;
|
|
5705
|
+
}
|
|
5152
5706
|
function isNewDevice(previous, { deviceKey, userAgent }) {
|
|
5153
5707
|
if (previous.length === 0) return false;
|
|
5154
5708
|
if (previous.some((row) => row.deviceKey && row.deviceKey === deviceKey)) return false;
|
|
@@ -5177,7 +5731,7 @@ var require_sign_in_signals = __commonJS({
|
|
|
5177
5731
|
const token = await issueNotMeToken(getCoordinator(strapi2), { sessionId, userId });
|
|
5178
5732
|
if (!token) return null;
|
|
5179
5733
|
const prefix = normalizeApiPrefix(strapi2.config.get("api.rest.prefix", "/api"));
|
|
5180
|
-
return `${base}${prefix}/magic-sessionmanager/not-me
|
|
5734
|
+
return `${base}${prefix}/magic-sessionmanager/not-me#token=${encodeURIComponent(token)}`;
|
|
5181
5735
|
}
|
|
5182
5736
|
async function runSignInSignals({
|
|
5183
5737
|
strapi: strapi2,
|
|
@@ -5266,6 +5820,7 @@ var require_sign_in_signals = __commonJS({
|
|
|
5266
5820
|
return outcome;
|
|
5267
5821
|
}
|
|
5268
5822
|
module2.exports = {
|
|
5823
|
+
isRecognizedDevice,
|
|
5269
5824
|
notMeUrl,
|
|
5270
5825
|
runSignInSignals,
|
|
5271
5826
|
deviceFamilies,
|
|
@@ -5370,7 +5925,11 @@ var require_impersonation_guard = __commonJS({
|
|
|
5370
5925
|
`impersonation-${restricted}`
|
|
5371
5926
|
);
|
|
5372
5927
|
}
|
|
5373
|
-
ctx.state.magicImpersonation = {
|
|
5928
|
+
ctx.state.magicImpersonation = {
|
|
5929
|
+
id: impersonation.id,
|
|
5930
|
+
actorId: impersonation.actorId,
|
|
5931
|
+
targetId: impersonation.targetId || null
|
|
5932
|
+
};
|
|
5374
5933
|
try {
|
|
5375
5934
|
await next();
|
|
5376
5935
|
} finally {
|
|
@@ -9464,7 +10023,13 @@ var require_bootstrap = __commonJS({
|
|
|
9464
10023
|
"server/src/bootstrap.js"(exports2, module2) {
|
|
9465
10024
|
"use strict";
|
|
9466
10025
|
var getClientIp = require_getClientIp();
|
|
9467
|
-
var {
|
|
10026
|
+
var {
|
|
10027
|
+
MIN_KEY_BYTES,
|
|
10028
|
+
encryptToken,
|
|
10029
|
+
getEncryptionKeyCheck,
|
|
10030
|
+
hashToken,
|
|
10031
|
+
isEncryptionKeyShort
|
|
10032
|
+
} = require_encryption();
|
|
9468
10033
|
var { createLogger } = require_logger();
|
|
9469
10034
|
var { resolveUserDocumentId } = require_resolve_user();
|
|
9470
10035
|
var { getPluginSettings, getSessionCreationGraceMs } = require_settings_loader();
|
|
@@ -9475,7 +10040,12 @@ var require_bootstrap = __commonJS({
|
|
|
9475
10040
|
var { REVOCATION_UID } = require_session_revocation();
|
|
9476
10041
|
var { getNativeSessionManager } = require_native_session_manager();
|
|
9477
10042
|
var { CONTENT_API_PERMISSIONS_VERSION } = require_content_api_permissions();
|
|
9478
|
-
var {
|
|
10043
|
+
var {
|
|
10044
|
+
getCoordinator,
|
|
10045
|
+
hashedKey,
|
|
10046
|
+
initCoordination,
|
|
10047
|
+
LockTimeoutError
|
|
10048
|
+
} = require_coordination();
|
|
9479
10049
|
var { removeLegacyLicenseData, withPluginStoreKey } = require_plugin_store();
|
|
9480
10050
|
var {
|
|
9481
10051
|
normalizeApiPrefix,
|
|
@@ -9524,8 +10094,20 @@ var require_bootstrap = __commonJS({
|
|
|
9524
10094
|
} = require_sign_in_policies();
|
|
9525
10095
|
var { SECURITY_EVENTS, USER_SIGN_IN_EVENTS } = require_security_log_model();
|
|
9526
10096
|
var { applyUpgradeDefaults } = require_upgrade_defaults();
|
|
9527
|
-
var {
|
|
10097
|
+
var {
|
|
10098
|
+
deviceKeyOf,
|
|
10099
|
+
isRecognizedDevice,
|
|
10100
|
+
requestDeviceId,
|
|
10101
|
+
runSignInSignals
|
|
10102
|
+
} = require_sign_in_signals();
|
|
9528
10103
|
var { anonymizeIp, normalizeIp } = require_admin_request_info();
|
|
10104
|
+
var { migrateLegacyProxyTrust } = require_trusted_proxies();
|
|
10105
|
+
var { errors: utilsErrors } = require("@strapi/utils");
|
|
10106
|
+
var {
|
|
10107
|
+
classifyCallbackOutcome,
|
|
10108
|
+
setAuthControllerHandlers
|
|
10109
|
+
} = require_auth_controller_guard();
|
|
10110
|
+
var { normalizePath } = require_impersonation_rules();
|
|
9529
10111
|
var SESSION_UID = "plugin::magic-sessionmanager.session";
|
|
9530
10112
|
var RETENTION_INTERVAL_MS = 24 * 60 * 60 * 1e3;
|
|
9531
10113
|
var JOB_LEASES = Object.freeze({
|
|
@@ -9568,6 +10150,12 @@ var require_bootstrap = __commonJS({
|
|
|
9568
10150
|
try {
|
|
9569
10151
|
const coordinator = await initCoordination(strapi2, log);
|
|
9570
10152
|
await checkEncryptionKeyConsistency(strapi2, log);
|
|
10153
|
+
await warnShortEncryptionKey(strapi2, log);
|
|
10154
|
+
try {
|
|
10155
|
+
await migrateLegacyProxyTrust(strapi2, log);
|
|
10156
|
+
} catch (err) {
|
|
10157
|
+
log.warn("[CONFIG] trustedProxies could not be migrated:", err?.name || "Error");
|
|
10158
|
+
}
|
|
9571
10159
|
try {
|
|
9572
10160
|
await applyUpgradeDefaults(strapi2, log);
|
|
9573
10161
|
} catch (err) {
|
|
@@ -9681,8 +10269,9 @@ var require_bootstrap = __commonJS({
|
|
|
9681
10269
|
impersonationSweep.unref?.();
|
|
9682
10270
|
strapi2.sessionManagerIntervals.impersonationSweep = impersonationSweep;
|
|
9683
10271
|
strapi2.plugin("magic-sessionmanager").service("impersonation").checkHandoffSetup();
|
|
9684
|
-
mountPreLoginGeoGuard({ strapi: strapi2, log });
|
|
9685
|
-
mountFailedLoginLockout({ strapi: strapi2, log });
|
|
10272
|
+
const geoCheck = mountPreLoginGeoGuard({ strapi: strapi2, log });
|
|
10273
|
+
const lockoutGuard = mountFailedLoginLockout({ strapi: strapi2, log });
|
|
10274
|
+
connectAuthControllerGuard({ strapi: strapi2, geoCheck, lockoutGuard });
|
|
9686
10275
|
mountLogoutRoute({ strapi: strapi2, log, sessionService });
|
|
9687
10276
|
mountLoginInterceptor({ strapi: strapi2, log, sessionService });
|
|
9688
10277
|
mountRefreshTokenInterceptor({ strapi: strapi2, log, sessionService });
|
|
@@ -9740,6 +10329,28 @@ var require_bootstrap = __commonJS({
|
|
|
9740
10329
|
log.debug("[CONFIG] Encryption key consistency check skipped:", err?.name || "Error");
|
|
9741
10330
|
}
|
|
9742
10331
|
}
|
|
10332
|
+
async function warnShortEncryptionKey(strapi2, log) {
|
|
10333
|
+
if (!isEncryptionKeyShort()) return false;
|
|
10334
|
+
log.error(
|
|
10335
|
+
`[SECURITY] SESSION_ENCRYPTION_KEY is shorter than ${MIN_KEY_BYTES} bytes, so stored tokens and secrets are only as safe as that short key. It still works in this version; the next major version will refuse to start with it. Generate a new key with: node -e "console.log(require('crypto').randomBytes(32).toString('hex'))" (changing it signs users out and needs the webhook secret entered again).`
|
|
10336
|
+
);
|
|
10337
|
+
try {
|
|
10338
|
+
const coordinator = getCoordinator(strapi2);
|
|
10339
|
+
const check = getEncryptionKeyCheck();
|
|
10340
|
+
const marker = "instance:weak-encryption-key-recorded";
|
|
10341
|
+
if (await coordinator.cacheGet(marker) === check) return true;
|
|
10342
|
+
const recorded = strapi2.plugin("magic-sessionmanager").service("security-log").record({
|
|
10343
|
+
event: SECURITY_EVENTS.CONFIG_WEAK_KEY,
|
|
10344
|
+
actorType: "system",
|
|
10345
|
+
targetType: "config",
|
|
10346
|
+
meta: { minBytes: MIN_KEY_BYTES }
|
|
10347
|
+
});
|
|
10348
|
+
if (recorded !== false) await coordinator.cacheSet(marker, check, Infinity);
|
|
10349
|
+
} catch (err) {
|
|
10350
|
+
log.debug("[SECURITY] Weak key event not recorded:", err?.name || "Error");
|
|
10351
|
+
}
|
|
10352
|
+
return true;
|
|
10353
|
+
}
|
|
9743
10354
|
function mountPreLoginGeoGuard({ strapi: strapi2, log }) {
|
|
9744
10355
|
const shouldRecordRefusal = createRefusalDedup();
|
|
9745
10356
|
const shouldRecordUnknownAccount = createRefusalDedup({ windowMs: 5 * 60 * 1e3 });
|
|
@@ -9762,19 +10373,14 @@ var require_bootstrap = __commonJS({
|
|
|
9762
10373
|
meta: { reason }
|
|
9763
10374
|
});
|
|
9764
10375
|
};
|
|
9765
|
-
|
|
9766
|
-
if (
|
|
9767
|
-
|
|
9768
|
-
}
|
|
10376
|
+
const check = async (ctx) => {
|
|
10377
|
+
if (ctx.state?.__magicSessionGeoChecked) return null;
|
|
10378
|
+
if (ctx.state) ctx.state.__magicSessionGeoChecked = true;
|
|
9769
10379
|
const settings = await getRequestSettings(strapi2, ctx);
|
|
9770
10380
|
const needsGeoCheck = settings.blockSuspiciousSessions || settings.enableGeofencing || settings.enableGeolocation;
|
|
9771
|
-
if (!needsGeoCheck)
|
|
9772
|
-
return next();
|
|
9773
|
-
}
|
|
10381
|
+
if (!needsGeoCheck) return null;
|
|
9774
10382
|
const ip = getClientIp(ctx);
|
|
9775
|
-
if (!ip || ip === "unknown")
|
|
9776
|
-
return next();
|
|
9777
|
-
}
|
|
10383
|
+
if (!ip || ip === "unknown") return null;
|
|
9778
10384
|
try {
|
|
9779
10385
|
const geolocationService = strapi2.plugin("magic-sessionmanager").service("geolocation");
|
|
9780
10386
|
const geoData = await geolocationService.getIpInfo(ip);
|
|
@@ -9782,16 +10388,11 @@ var require_bootstrap = __commonJS({
|
|
|
9782
10388
|
if (decision.blocked) {
|
|
9783
10389
|
log.warn(`[PRE-BLOCKED] Login rejected (${decision.reason})`);
|
|
9784
10390
|
await recordRefusal(ctx, settings, ip, decision.reason);
|
|
9785
|
-
ctx.status = 403;
|
|
9786
|
-
ctx.body = {
|
|
9787
|
-
error: {
|
|
9788
|
-
status: 403,
|
|
9789
|
-
name: "ForbiddenError",
|
|
9790
|
-
message: decision.reason?.startsWith("geo_lookup_unavailable:") ? "Login temporarily unavailable. Please contact support." : "Login blocked for security reasons. Please contact support."
|
|
9791
|
-
}
|
|
9792
|
-
};
|
|
9793
10391
|
ctx.state.__magicSessionGeoData = geoData;
|
|
9794
|
-
return
|
|
10392
|
+
return {
|
|
10393
|
+
status: 403,
|
|
10394
|
+
message: decision.reason?.startsWith("geo_lookup_unavailable:") ? "Login temporarily unavailable. Please contact support." : "Login blocked for security reasons. Please contact support."
|
|
10395
|
+
};
|
|
9795
10396
|
}
|
|
9796
10397
|
if (decision.status === "ok") {
|
|
9797
10398
|
ctx.state.__magicSessionGeoData = geoData;
|
|
@@ -9801,21 +10402,31 @@ var require_bootstrap = __commonJS({
|
|
|
9801
10402
|
if (failureDecision.blocked) {
|
|
9802
10403
|
log.warn("[PRE-BLOCKED] Login rejected because GeoIP lookup failed");
|
|
9803
10404
|
await recordRefusal(ctx, settings, ip, "geo_lookup_unavailable:error");
|
|
9804
|
-
|
|
9805
|
-
|
|
9806
|
-
|
|
9807
|
-
status: 403,
|
|
9808
|
-
name: "ForbiddenError",
|
|
9809
|
-
message: "Login temporarily unavailable. Please contact support."
|
|
9810
|
-
}
|
|
10405
|
+
return {
|
|
10406
|
+
status: 403,
|
|
10407
|
+
message: "Login temporarily unavailable. Please contact support."
|
|
9811
10408
|
};
|
|
9812
|
-
return;
|
|
9813
10409
|
}
|
|
9814
10410
|
log.debug("Pre-login geo guard error (allowing by configured policy):", err?.name || "Error");
|
|
9815
10411
|
}
|
|
10412
|
+
return null;
|
|
10413
|
+
};
|
|
10414
|
+
strapi2.server.use(async (ctx, next) => {
|
|
10415
|
+
if (!shouldRunPreAuthGeoGuard(apiPathOf(strapi2, ctx), ctx.method)) {
|
|
10416
|
+
return next();
|
|
10417
|
+
}
|
|
10418
|
+
const refusal = await check(ctx);
|
|
10419
|
+
if (refusal) {
|
|
10420
|
+
ctx.status = refusal.status;
|
|
10421
|
+
ctx.body = {
|
|
10422
|
+
error: { status: refusal.status, name: "ForbiddenError", message: refusal.message }
|
|
10423
|
+
};
|
|
10424
|
+
return;
|
|
10425
|
+
}
|
|
9816
10426
|
await next();
|
|
9817
10427
|
});
|
|
9818
10428
|
log.info("[SUCCESS] Pre-login geo guard mounted");
|
|
10429
|
+
return check;
|
|
9819
10430
|
}
|
|
9820
10431
|
function mountLogoutRoute({ strapi: strapi2, log, sessionService }) {
|
|
9821
10432
|
const logoutPath = `${normalizeApiPrefix(strapi2.config.get("api.rest.prefix", "/api"))}/auth/logout`;
|
|
@@ -10001,16 +10612,16 @@ var require_bootstrap = __commonJS({
|
|
|
10001
10612
|
}
|
|
10002
10613
|
function mountFailedLoginLockout({ strapi: strapi2, log }) {
|
|
10003
10614
|
const lockout = createLoginLockout(getCoordinator(strapi2));
|
|
10615
|
+
const coordinator = getCoordinator(strapi2);
|
|
10004
10616
|
const shouldRecordRefusal = createRefusalDedup();
|
|
10005
10617
|
const shouldRecordUnknownAccount = createRefusalDedup({ windowMs: 5 * 60 * 1e3 });
|
|
10006
10618
|
const underAddressCap = createAddressCap();
|
|
10007
10619
|
const unknownAccountKey = (ip) => `unknown|${anonymizeIp(normalizeIp(ip || "")) || "none"}`;
|
|
10008
|
-
|
|
10009
|
-
if (!isFailedLoginTrackedPath(apiPathOf(strapi2, ctx), ctx.method)) return next();
|
|
10620
|
+
const guard = async (ctx, run, classify, refuse) => {
|
|
10010
10621
|
const settings = await getRequestSettings(strapi2, ctx);
|
|
10011
10622
|
const policy = resolveLockoutPolicy(settings);
|
|
10012
10623
|
const accountPossible = policy.accountMax > 0 || policy.accountMaxByRole;
|
|
10013
|
-
if (policy.ipMax <= 0 && !accountPossible && !policy.record) return
|
|
10624
|
+
if (policy.ipMax <= 0 && !accountPossible && !policy.record) return run();
|
|
10014
10625
|
const rawIp = getClientIp(ctx);
|
|
10015
10626
|
const ip = rawIp && rawIp !== "unknown" ? rawIp : null;
|
|
10016
10627
|
const identifier = readSignInIdentifier(ctx);
|
|
@@ -10031,6 +10642,15 @@ var require_bootstrap = __commonJS({
|
|
|
10031
10642
|
};
|
|
10032
10643
|
if (policy.accountMaxByRole) await loadAccount();
|
|
10033
10644
|
const accountMax = accountThresholdFor(settings, account?.role || null);
|
|
10645
|
+
let accountExempt = false;
|
|
10646
|
+
const deviceId = requestDeviceId(ctx);
|
|
10647
|
+
if (accountMax > 0 && identifier && deviceId) {
|
|
10648
|
+
await loadAccount();
|
|
10649
|
+
accountExempt = await isRecognizedDevice(strapi2, account?.documentId || null, {
|
|
10650
|
+
userAgent,
|
|
10651
|
+
deviceId
|
|
10652
|
+
}).catch(() => false);
|
|
10653
|
+
}
|
|
10034
10654
|
const event = (name, meta) => {
|
|
10035
10655
|
const signInFamily = USER_SIGN_IN_EVENTS.includes(name);
|
|
10036
10656
|
if (signInFamily && !policy.record) return false;
|
|
@@ -10058,7 +10678,7 @@ var require_bootstrap = __commonJS({
|
|
|
10058
10678
|
};
|
|
10059
10679
|
let decision;
|
|
10060
10680
|
try {
|
|
10061
|
-
decision = await lockout.reserve({ ip, identifier, policy, accountMax });
|
|
10681
|
+
decision = await lockout.reserve({ ip, identifier, policy, accountMax, accountExempt });
|
|
10062
10682
|
} catch (err) {
|
|
10063
10683
|
log.debug("[LOCKOUT] Counter update failed:", err?.name || "Error");
|
|
10064
10684
|
decision = {
|
|
@@ -10069,47 +10689,38 @@ var require_bootstrap = __commonJS({
|
|
|
10069
10689
|
};
|
|
10070
10690
|
}
|
|
10071
10691
|
if (decision.outcome === "locked") {
|
|
10072
|
-
ctx.set("Retry-After", String(decision.retryAfter));
|
|
10073
10692
|
log.warn(
|
|
10074
10693
|
`[LOCKOUT] Rejected sign-in from a locked client (${decision.retryAfter}s remaining)`
|
|
10075
10694
|
);
|
|
10076
10695
|
if (policy.record) await loadAccount();
|
|
10077
10696
|
refusedOnce("lockout", { lock: decision.lockedKind });
|
|
10078
|
-
ctx
|
|
10079
|
-
|
|
10080
|
-
|
|
10081
|
-
|
|
10082
|
-
|
|
10083
|
-
|
|
10084
|
-
details: { retryAfter: decision.retryAfter }
|
|
10085
|
-
}
|
|
10086
|
-
};
|
|
10087
|
-
return;
|
|
10697
|
+
return refuse(ctx, {
|
|
10698
|
+
status: 429,
|
|
10699
|
+
name: "TooManyRequestsError",
|
|
10700
|
+
message: "Too many failed login attempts. Please try again later.",
|
|
10701
|
+
retryAfter: decision.retryAfter
|
|
10702
|
+
});
|
|
10088
10703
|
}
|
|
10089
10704
|
if (decision.outcome === "busy") {
|
|
10090
10705
|
if (policy.record) await loadAccount();
|
|
10091
10706
|
refusedOnce("too-many-attempts", {});
|
|
10092
|
-
ctx
|
|
10093
|
-
|
|
10094
|
-
|
|
10095
|
-
|
|
10096
|
-
|
|
10097
|
-
|
|
10098
|
-
message: "Too many login attempts at once. Please try again.",
|
|
10099
|
-
details: { retryAfter: 1 }
|
|
10100
|
-
}
|
|
10101
|
-
};
|
|
10102
|
-
return;
|
|
10707
|
+
return refuse(ctx, {
|
|
10708
|
+
status: 429,
|
|
10709
|
+
name: "TooManyRequestsError",
|
|
10710
|
+
message: "Too many login attempts at once. Please try again.",
|
|
10711
|
+
retryAfter: 1
|
|
10712
|
+
});
|
|
10103
10713
|
}
|
|
10104
10714
|
let thrown = null;
|
|
10715
|
+
let returned;
|
|
10105
10716
|
try {
|
|
10106
|
-
await
|
|
10717
|
+
returned = await run();
|
|
10107
10718
|
} catch (err) {
|
|
10108
10719
|
thrown = err;
|
|
10109
10720
|
}
|
|
10110
|
-
const
|
|
10111
|
-
const result = !thrown && status === 200 && ctx.body && ctx.body.jwt ? "success" : status >= 400 && status < 500 && status !== 429 ? "failure" : "neutral";
|
|
10721
|
+
const result = classify(thrown, ctx);
|
|
10112
10722
|
if (result === "failure") {
|
|
10723
|
+
const status = thrown ? statusOfThrownError(thrown) : ctx.status;
|
|
10113
10724
|
if (policy.record || decision.reservation.accountKey) await loadAccount();
|
|
10114
10725
|
if (account) {
|
|
10115
10726
|
event(SECURITY_EVENTS.USER_SIGN_IN_FAILED, { status });
|
|
@@ -10137,21 +10748,93 @@ var require_bootstrap = __commonJS({
|
|
|
10137
10748
|
minutes
|
|
10138
10749
|
});
|
|
10139
10750
|
if (lock.kind === "account" && policy.notifyUser && account?.email) {
|
|
10140
|
-
const
|
|
10141
|
-
|
|
10142
|
-
|
|
10143
|
-
|
|
10144
|
-
|
|
10145
|
-
|
|
10146
|
-
|
|
10751
|
+
const mailWindowMs = Math.max(policy.windowMs, policy.durationMs);
|
|
10752
|
+
const sent = await coordinator.hit(hashedKey("lm", lock.id), mailWindowMs).then((entry) => Number(entry?.hits) || 0).catch(() => 1);
|
|
10753
|
+
if (sent === 1) {
|
|
10754
|
+
const notifications = strapi2.plugin("magic-sessionmanager").service("notifications");
|
|
10755
|
+
notifications.sendAccountLockedEmail({
|
|
10756
|
+
user: account,
|
|
10757
|
+
minutes,
|
|
10758
|
+
until: lock.until
|
|
10759
|
+
}).catch(() => {
|
|
10760
|
+
});
|
|
10761
|
+
}
|
|
10147
10762
|
}
|
|
10148
10763
|
}
|
|
10149
10764
|
} catch (err) {
|
|
10150
10765
|
log.debug("[LOCKOUT] Counter update failed:", err?.name || "Error");
|
|
10151
10766
|
}
|
|
10152
|
-
if (thrown) throw thrown;
|
|
10153
|
-
|
|
10154
|
-
|
|
10767
|
+
if (thrown) throw thrown;
|
|
10768
|
+
return returned;
|
|
10769
|
+
};
|
|
10770
|
+
strapi2.server.use(async (ctx, next) => {
|
|
10771
|
+
if (!isFailedLoginTrackedPath(apiPathOf(strapi2, ctx), ctx.method)) return next();
|
|
10772
|
+
return guard(ctx, next, classifyRouteOutcome, refuseOverHttp);
|
|
10773
|
+
});
|
|
10774
|
+
log.info("[SUCCESS] Failed-login lockout middleware mounted");
|
|
10775
|
+
return guard;
|
|
10776
|
+
}
|
|
10777
|
+
function classifyRouteOutcome(thrown, ctx) {
|
|
10778
|
+
const status = thrown ? statusOfThrownError(thrown) : ctx.status;
|
|
10779
|
+
if (!thrown && status === 200 && ctx.body && ctx.body.jwt) return "success";
|
|
10780
|
+
return status === 400 || status === 401 ? "failure" : "neutral";
|
|
10781
|
+
}
|
|
10782
|
+
function refuseOverHttp(ctx, refusal) {
|
|
10783
|
+
ctx.set("Retry-After", String(refusal.retryAfter));
|
|
10784
|
+
ctx.status = refusal.status;
|
|
10785
|
+
ctx.body = {
|
|
10786
|
+
error: {
|
|
10787
|
+
status: refusal.status,
|
|
10788
|
+
name: refusal.name,
|
|
10789
|
+
message: refusal.message,
|
|
10790
|
+
details: { retryAfter: refusal.retryAfter }
|
|
10791
|
+
}
|
|
10792
|
+
};
|
|
10793
|
+
}
|
|
10794
|
+
function isGraphqlRequest(strapi2, ctx) {
|
|
10795
|
+
let endpoint = "/graphql";
|
|
10796
|
+
try {
|
|
10797
|
+
endpoint = strapi2.plugin("graphql")?.config?.("endpoint") || endpoint;
|
|
10798
|
+
} catch {
|
|
10799
|
+
}
|
|
10800
|
+
const original = String(ctx.originalUrl || ctx.url || "").split("?")[0];
|
|
10801
|
+
return normalizePath(original) === normalizePath(endpoint);
|
|
10802
|
+
}
|
|
10803
|
+
function createAuthControllerHandlers({ strapi: strapi2, geoCheck, lockoutGuard }) {
|
|
10804
|
+
const refuse = (ctx, refusal) => {
|
|
10805
|
+
if (refusal.retryAfter) ctx.set("Retry-After", String(refusal.retryAfter));
|
|
10806
|
+
if (isGraphqlRequest(strapi2, ctx)) {
|
|
10807
|
+
const details = refusal.retryAfter ? { retryAfter: refusal.retryAfter } : {};
|
|
10808
|
+
throw refusal.status === 429 ? new utilsErrors.RateLimitError(refusal.message, details) : new utilsErrors.ForbiddenError(refusal.message, details);
|
|
10809
|
+
}
|
|
10810
|
+
if (refusal.status === 429) return refuseOverHttp(ctx, refusal);
|
|
10811
|
+
ctx.status = refusal.status;
|
|
10812
|
+
ctx.body = {
|
|
10813
|
+
error: { status: refusal.status, name: refusal.name, message: refusal.message }
|
|
10814
|
+
};
|
|
10815
|
+
return void 0;
|
|
10816
|
+
};
|
|
10817
|
+
const geoFirst = async (ctx) => {
|
|
10818
|
+
const refusal = await geoCheck(ctx);
|
|
10819
|
+
if (!refusal) return false;
|
|
10820
|
+
refuse(ctx, { ...refusal, name: "ForbiddenError", retryAfter: 0 });
|
|
10821
|
+
return true;
|
|
10822
|
+
};
|
|
10823
|
+
return {
|
|
10824
|
+
async callback(ctx, run) {
|
|
10825
|
+
if (await geoFirst(ctx)) return void 0;
|
|
10826
|
+
const provider = ctx.params?.provider || "local";
|
|
10827
|
+
if (provider !== "local") return run();
|
|
10828
|
+
return lockoutGuard(ctx, run, classifyCallbackOutcome, refuse);
|
|
10829
|
+
},
|
|
10830
|
+
async newSession(ctx, run) {
|
|
10831
|
+
if (await geoFirst(ctx)) return void 0;
|
|
10832
|
+
return run();
|
|
10833
|
+
}
|
|
10834
|
+
};
|
|
10835
|
+
}
|
|
10836
|
+
function connectAuthControllerGuard(deps) {
|
|
10837
|
+
setAuthControllerHandlers(deps.strapi, createAuthControllerHandlers(deps));
|
|
10155
10838
|
}
|
|
10156
10839
|
function statusOfThrownError(err) {
|
|
10157
10840
|
const status = Number(err?.status ?? err?.statusCode);
|
|
@@ -11361,6 +12044,8 @@ var require_bootstrap = __commonJS({
|
|
|
11361
12044
|
}
|
|
11362
12045
|
}
|
|
11363
12046
|
module2.exports.__private = {
|
|
12047
|
+
warnShortEncryptionKey,
|
|
12048
|
+
createAuthControllerHandlers,
|
|
11364
12049
|
registerSessionAwareAuthStrategy,
|
|
11365
12050
|
mountFailedLoginLockout,
|
|
11366
12051
|
ensureSessionLookupIndexes,
|
|
@@ -11380,6 +12065,7 @@ var require_destroy = __commonJS({
|
|
|
11380
12065
|
"server/src/destroy.js"(exports2, module2) {
|
|
11381
12066
|
"use strict";
|
|
11382
12067
|
var { createLogger } = require_logger();
|
|
12068
|
+
var { uninstallAuthControllerGuard } = require_auth_controller_guard();
|
|
11383
12069
|
module2.exports = async ({ strapi: strapi2 }) => {
|
|
11384
12070
|
const log = createLogger(strapi2);
|
|
11385
12071
|
if (strapi2.sessionManagerIntervals) {
|
|
@@ -11413,6 +12099,11 @@ var require_destroy = __commonJS({
|
|
|
11413
12099
|
}
|
|
11414
12100
|
strapi2.sessionManagerAdminActivityUninstall = null;
|
|
11415
12101
|
}
|
|
12102
|
+
try {
|
|
12103
|
+
uninstallAuthControllerGuard(strapi2);
|
|
12104
|
+
} catch (err) {
|
|
12105
|
+
log.warn("Failed to restore the Users & Permissions auth controller:", err?.name || "Error");
|
|
12106
|
+
}
|
|
11416
12107
|
try {
|
|
11417
12108
|
strapi2.plugin("magic-sessionmanager")?.service("webhooks")?.stop?.();
|
|
11418
12109
|
} catch (err) {
|
|
@@ -14886,7 +15577,13 @@ var require_settings_access = __commonJS({
|
|
|
14886
15577
|
// Signed webhook, event selection, impossible travel and shortened IPs.
|
|
14887
15578
|
...PROTECTED_DETECTION_KEYS,
|
|
14888
15579
|
// Impersonation switch (4.20): whether admins can act as app users.
|
|
14889
|
-
...IMPERSONATION_KEYS
|
|
15580
|
+
...IMPERSONATION_KEYS,
|
|
15581
|
+
// Security review 2 (4.22.1): which proxies may name the client address
|
|
15582
|
+
// (H2), the IP lockout threshold (H2) and the alert email texts, which go
|
|
15583
|
+
// to app users from the site's own address (hardening 6).
|
|
15584
|
+
"trustedProxies",
|
|
15585
|
+
"maxFailedLogins",
|
|
15586
|
+
"emailTemplates"
|
|
14890
15587
|
]);
|
|
14891
15588
|
var WEBHOOK_SECRETS = Object.freeze([
|
|
14892
15589
|
{ key: "discordWebhookUrl", has: "hasDiscordWebhook", hint: "discordWebhookHint" },
|
|
@@ -14996,6 +15693,7 @@ var require_settings = __commonJS({
|
|
|
14996
15693
|
validateImpersonationSettings
|
|
14997
15694
|
} = require_impersonation_rules();
|
|
14998
15695
|
var { encryptToken } = require_encryption();
|
|
15696
|
+
var { normalizeTrustedProxies, validateTrustedProxies } = require_trusted_proxies();
|
|
14999
15697
|
var WEBHOOK_SECRET_PATTERN = /^[\x21-\x7e]{32,256}$/;
|
|
15000
15698
|
var path = require("node:path");
|
|
15001
15699
|
var ALLOWED_WEBHOOK_DOMAINS = {
|
|
@@ -15171,7 +15869,9 @@ var require_settings = __commonJS({
|
|
|
15171
15869
|
discordWebhookUrl: "",
|
|
15172
15870
|
slackWebhookUrl: "",
|
|
15173
15871
|
strictSessionEnforcement: false,
|
|
15174
|
-
|
|
15872
|
+
// A list of proxy addresses or CIDR ranges since 4.22.1; the legacy
|
|
15873
|
+
// boolean is read as an empty list (Strapi's server.proxy settings decide).
|
|
15874
|
+
trustedProxies: [],
|
|
15175
15875
|
emailTemplates: DEFAULT_EMAIL_TEMPLATES,
|
|
15176
15876
|
...SECURITY_LOG_DEFAULTS,
|
|
15177
15877
|
...POLICY_DEFAULTS,
|
|
@@ -15192,7 +15892,8 @@ var require_settings = __commonJS({
|
|
|
15192
15892
|
...DEFAULT_EMAIL_TEMPLATES,
|
|
15193
15893
|
...storedTemplates
|
|
15194
15894
|
},
|
|
15195
|
-
geoIpDatabasePath: getSafeGeoIpFilename(safeStored.geoIpDatabasePath)
|
|
15895
|
+
geoIpDatabasePath: getSafeGeoIpFilename(safeStored.geoIpDatabasePath),
|
|
15896
|
+
trustedProxies: normalizeTrustedProxies(safeStored.trustedProxies)
|
|
15196
15897
|
};
|
|
15197
15898
|
}
|
|
15198
15899
|
var INTEGER_SETTING_RANGES = {
|
|
@@ -15217,8 +15918,7 @@ var require_settings = __commonJS({
|
|
|
15217
15918
|
"alertOnNewLocation",
|
|
15218
15919
|
"alertOnVpnProxy",
|
|
15219
15920
|
"enableWebhooks",
|
|
15220
|
-
"strictSessionEnforcement"
|
|
15221
|
-
"trustedProxies"
|
|
15921
|
+
"strictSessionEnforcement"
|
|
15222
15922
|
];
|
|
15223
15923
|
var GEO_IP_PROVIDER_VALUES = ["auto", "local-mmdb", "ipapi", "disabled"];
|
|
15224
15924
|
var GEO_LOOKUP_FAILURE_MODE_VALUES = ["auto", "allow", "block"];
|
|
@@ -15292,6 +15992,11 @@ var require_settings = __commonJS({
|
|
|
15292
15992
|
next[key] = body[key];
|
|
15293
15993
|
}
|
|
15294
15994
|
}
|
|
15995
|
+
if (has("trustedProxies")) {
|
|
15996
|
+
const proxies = validateTrustedProxies(body.trustedProxies);
|
|
15997
|
+
if (proxies.error) errors.push(proxies.error);
|
|
15998
|
+
else next.trustedProxies = proxies.value;
|
|
15999
|
+
}
|
|
15295
16000
|
for (const key of ["allowedCountries", "blockedCountries"]) {
|
|
15296
16001
|
if (!has(key)) continue;
|
|
15297
16002
|
const list = body[key];
|
|
@@ -15410,6 +16115,15 @@ var require_settings = __commonJS({
|
|
|
15410
16115
|
next.genericWebhookSecret = encryptToken(secret);
|
|
15411
16116
|
}
|
|
15412
16117
|
}
|
|
16118
|
+
const urlChanges = typeof next.genericWebhookUrl === "string" && next.genericWebhookUrl !== "" && next.genericWebhookUrl !== (current.genericWebhookUrl || "");
|
|
16119
|
+
const secretStored = typeof current.genericWebhookSecret === "string" && current.genericWebhookSecret !== "";
|
|
16120
|
+
const secretGiven = typeof next.genericWebhookSecret === "string" && next.genericWebhookSecret !== "";
|
|
16121
|
+
if (urlChanges && secretStored && !secretGiven) {
|
|
16122
|
+
errors.push({
|
|
16123
|
+
path: ["genericWebhookSecret"],
|
|
16124
|
+
message: "Enter the webhook secret again when you change the webhook URL"
|
|
16125
|
+
});
|
|
16126
|
+
}
|
|
15413
16127
|
if (errors.length > 0) return { errors };
|
|
15414
16128
|
const settings = {};
|
|
15415
16129
|
for (const key of Object.keys(DEFAULT_SETTINGS)) {
|
|
@@ -17122,10 +17836,43 @@ var require_lockouts = __commonJS({
|
|
|
17122
17836
|
}
|
|
17123
17837
|
});
|
|
17124
17838
|
|
|
17839
|
+
// server/src/utils/user-export.js
|
|
17840
|
+
var require_user_export = __commonJS({
|
|
17841
|
+
"server/src/utils/user-export.js"(exports2, module2) {
|
|
17842
|
+
"use strict";
|
|
17843
|
+
var { SECURITY_EVENTS } = require_security_log_model();
|
|
17844
|
+
var IMPERSONATION_TEXT = Object.freeze({
|
|
17845
|
+
[SECURITY_EVENTS.IMPERSONATION_STARTED]: "An administrator opened your account",
|
|
17846
|
+
[SECURITY_EVENTS.IMPERSONATION_ENDED]: "The administrator access to your account ended",
|
|
17847
|
+
[SECURITY_EVENTS.IMPERSONATION_EXPIRED]: "The administrator access to your account ended",
|
|
17848
|
+
[SECURITY_EVENTS.IMPERSONATION_REFUSED]: "An administrator access to your account was refused"
|
|
17849
|
+
});
|
|
17850
|
+
function toUserExportEvent(row) {
|
|
17851
|
+
const { id: _id, ...rest } = row || {};
|
|
17852
|
+
const text = IMPERSONATION_TEXT[rest.event];
|
|
17853
|
+
if (!text) return rest;
|
|
17854
|
+
const minutes = Number(rest.meta?.durationMinutes);
|
|
17855
|
+
return {
|
|
17856
|
+
event: rest.event,
|
|
17857
|
+
createdAt: rest.createdAt,
|
|
17858
|
+
ip: null,
|
|
17859
|
+
userAgent: null,
|
|
17860
|
+
geo: null,
|
|
17861
|
+
meta: {
|
|
17862
|
+
description: text,
|
|
17863
|
+
...Number.isInteger(minutes) && minutes > 0 ? { durationMinutes: minutes } : {}
|
|
17864
|
+
}
|
|
17865
|
+
};
|
|
17866
|
+
}
|
|
17867
|
+
module2.exports = { IMPERSONATION_TEXT, toUserExportEvent };
|
|
17868
|
+
}
|
|
17869
|
+
});
|
|
17870
|
+
|
|
17125
17871
|
// server/src/controllers/self-service.js
|
|
17126
17872
|
var require_self_service = __commonJS({
|
|
17127
17873
|
"server/src/controllers/self-service.js"(exports2, module2) {
|
|
17128
17874
|
"use strict";
|
|
17875
|
+
var crypto = require("node:crypto");
|
|
17129
17876
|
var { getCoordinator } = require_coordination();
|
|
17130
17877
|
var { consumeNotMeToken, readNotMeToken } = require_not_me_link();
|
|
17131
17878
|
var { recordUserEvent } = require_sign_in_policies();
|
|
@@ -17133,6 +17880,7 @@ var require_self_service = __commonJS({
|
|
|
17133
17880
|
var { SECURITY_EVENTS } = require_security_log_model();
|
|
17134
17881
|
var { sendServerError } = require_http_errors();
|
|
17135
17882
|
var { createLogger } = require_logger();
|
|
17883
|
+
var { toUserExportEvent } = require_user_export();
|
|
17136
17884
|
var SESSION_UID = "plugin::magic-sessionmanager.session";
|
|
17137
17885
|
var EVENT_UID = "plugin::magic-sessionmanager.security-event";
|
|
17138
17886
|
var USER_UID = "plugin::users-permissions.user";
|
|
@@ -17199,19 +17947,21 @@ var require_self_service = __commonJS({
|
|
|
17199
17947
|
return "en";
|
|
17200
17948
|
}
|
|
17201
17949
|
var escapeHtml = (value) => String(value ?? "").replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """).replace(/'/g, "'");
|
|
17202
|
-
function
|
|
17950
|
+
var FRAGMENT_SCRIPT = `(function(){var m=/[#&]token=([A-Za-z0-9_.%-]+)/.exec(location.hash);if(!m)return;var t=decodeURIComponent(m[1]);var f=document.querySelectorAll('input[name="token"]');for(var i=0;i<f.length;i++)f[i].value=t;if(history.replaceState)history.replaceState(null,'',location.pathname);})();`;
|
|
17951
|
+
var FRAGMENT_SCRIPT_HASH = `sha256-${crypto.createHash("sha256").update(FRAGMENT_SCRIPT).digest("base64")}`;
|
|
17952
|
+
function sendPage(ctx, status, lang, title, body, { withScript = false } = {}) {
|
|
17203
17953
|
ctx.status = status;
|
|
17204
17954
|
ctx.set("Content-Type", "text/html; charset=utf-8");
|
|
17205
17955
|
ctx.set(
|
|
17206
17956
|
"Content-Security-Policy",
|
|
17207
|
-
|
|
17957
|
+
`default-src 'none'; style-src 'unsafe-inline'; ${withScript ? `script-src '${FRAGMENT_SCRIPT_HASH}'; ` : ""}form-action 'self'; frame-ancestors 'none'; base-uri 'none'`
|
|
17208
17958
|
);
|
|
17209
17959
|
ctx.set("Referrer-Policy", "no-referrer");
|
|
17210
17960
|
ctx.set("Cache-Control", "no-store");
|
|
17211
17961
|
ctx.set("X-Robots-Tag", "noindex");
|
|
17212
17962
|
ctx.body = `<!doctype html><html lang="${lang}"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1"><title>${escapeHtml(title)}</title>
|
|
17213
17963
|
<style>body{font-family:system-ui,sans-serif;max-width:36rem;margin:3rem auto;padding:0 1rem;line-height:1.5;color:#212134;background:#fff}button{font:inherit;padding:.6rem 1rem;margin:.25rem .5rem .25rem 0;border-radius:4px;border:1px solid #4945ff;background:#4945ff;color:#fff;cursor:pointer}button.secondary{background:#fff;color:#4945ff}@media (prefers-color-scheme:dark){body{background:#181826;color:#eaeaef}button.secondary{background:#181826}}</style></head>
|
|
17214
|
-
<body><main><h1>${escapeHtml(title)}</h1>${body}</main
|
|
17964
|
+
<body><main><h1>${escapeHtml(title)}</h1>${body}</main>${withScript ? `<script>${FRAGMENT_SCRIPT}</script>` : ""}</body></html>`;
|
|
17215
17965
|
}
|
|
17216
17966
|
module2.exports = ({ strapi: strapi2 }) => {
|
|
17217
17967
|
const log = createLogger(strapi2);
|
|
@@ -17219,17 +17969,20 @@ var require_self_service = __commonJS({
|
|
|
17219
17969
|
/**
|
|
17220
17970
|
* Confirmation page of the "This wasn't me" link. Uses nothing.
|
|
17221
17971
|
*
|
|
17222
|
-
* @route GET /api/magic-sessionmanager/not-me
|
|
17972
|
+
* @route GET /api/magic-sessionmanager/not-me (token in `#token=`; `?token=` before 4.22.1)
|
|
17223
17973
|
* @auth none (public on purpose: the link is opened from an email; the
|
|
17224
17974
|
* signed token is checked, and nothing changes until the POST)
|
|
17225
17975
|
* @param {any} ctx Koa context.
|
|
17226
|
-
* @returns {Promise<void>} 200 page with two buttons, or 410 when
|
|
17976
|
+
* @returns {Promise<void>} 200 page with two buttons, or 410 when a `?token=` link is
|
|
17977
|
+
* invalid. Without `?token=` the page is served with the hashed script that copies the
|
|
17978
|
+
* fragment token into the forms; the POST checks it.
|
|
17227
17979
|
*/
|
|
17228
17980
|
async notMePage(ctx) {
|
|
17229
17981
|
const lang = pageLanguage(ctx);
|
|
17230
17982
|
const text = PAGE_TEXT[lang];
|
|
17231
|
-
const
|
|
17232
|
-
|
|
17983
|
+
const hasQueryToken = typeof ctx.query?.token === "string" && ctx.query.token !== "";
|
|
17984
|
+
const token = hasQueryToken ? ctx.query.token : "";
|
|
17985
|
+
if (hasQueryToken && !readNotMeToken(token)) {
|
|
17233
17986
|
return sendPage(ctx, 410, lang, text.title, `<p>${escapeHtml(text.invalid)}</p>`);
|
|
17234
17987
|
}
|
|
17235
17988
|
const form = (scope, label, className) => `<form method="post" style="display:inline"><input type="hidden" name="token" value="${escapeHtml(token)}"><input type="hidden" name="scope" value="${scope}"><button type="submit"${className ? ` class="${className}"` : ""}>${escapeHtml(label)}</button></form>`;
|
|
@@ -17238,7 +17991,8 @@ var require_self_service = __commonJS({
|
|
|
17238
17991
|
200,
|
|
17239
17992
|
lang,
|
|
17240
17993
|
text.title,
|
|
17241
|
-
`<p>${escapeHtml(text.body)}</p>${form("session", text.one, "")}${form("all", text.all, "secondary")}
|
|
17994
|
+
`<p>${escapeHtml(text.body)}</p>${form("session", text.one, "")}${form("all", text.all, "secondary")}`,
|
|
17995
|
+
{ withScript: !hasQueryToken }
|
|
17242
17996
|
);
|
|
17243
17997
|
},
|
|
17244
17998
|
/**
|
|
@@ -17391,7 +18145,9 @@ var require_self_service = __commonJS({
|
|
|
17391
18145
|
exportedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
17392
18146
|
user: user ? { documentId: user.documentId, username: user.username, email: user.email } : { documentId: userDocumentId },
|
|
17393
18147
|
sessions,
|
|
17394
|
-
|
|
18148
|
+
// Impersonation events show a fixed text and the duration only
|
|
18149
|
+
// (security review 2, L3): the admin's reason stays internal.
|
|
18150
|
+
securityEvents: (Array.isArray(events) ? events : []).map(toUserExportEvent)
|
|
17395
18151
|
};
|
|
17396
18152
|
} catch (err) {
|
|
17397
18153
|
log.error("[my-data] Export failed:", err?.name || "Error");
|
|
@@ -17951,7 +18707,8 @@ var require_impersonation = __commonJS({
|
|
|
17951
18707
|
* Caller (with roles), target id and request body.
|
|
17952
18708
|
* @returns {Promise<object>} Impersonation DTO plus the preview.
|
|
17953
18709
|
* @throws {ImpersonationError} 400 invalid body or id; 403 feature off, self, Super Admin
|
|
17954
|
-
* or not a subset of the caller's permissions; 404
|
|
18710
|
+
* (callers with `admin::users.read`) or not a subset of the caller's permissions; 404
|
|
18711
|
+
* unknown admin, or a Super Admin for callers without `admin::users.read`.
|
|
17955
18712
|
* @sideeffect Creates an impersonation row; queues `impersonation.started` or `.refused`.
|
|
17956
18713
|
*/
|
|
17957
18714
|
async previewAdmin({ actor, adminId, body, canReadAdmins }) {
|
|
@@ -17981,6 +18738,15 @@ var require_impersonation = __commonJS({
|
|
|
17981
18738
|
]);
|
|
17982
18739
|
if (!target) throw new ImpersonationError(404, "Admin not found");
|
|
17983
18740
|
const refusal = await previewRefusal(strapi2, caller || actor, target);
|
|
18741
|
+
if (refusal?.reason === "super-admin" && !canReadAdmins) {
|
|
18742
|
+
service.recordRefused({
|
|
18743
|
+
actorId,
|
|
18744
|
+
targetType: "admin",
|
|
18745
|
+
targetId: adminId,
|
|
18746
|
+
reason: "super-admin"
|
|
18747
|
+
});
|
|
18748
|
+
throw new ImpersonationError(404, "Admin not found");
|
|
18749
|
+
}
|
|
17984
18750
|
if (refusal) {
|
|
17985
18751
|
const messages = {
|
|
17986
18752
|
self: "You cannot view yourself as another admin",
|
|
@@ -18390,7 +19156,10 @@ var require_impersonation = __commonJS({
|
|
|
18390
19156
|
};
|
|
18391
19157
|
},
|
|
18392
19158
|
/**
|
|
18393
|
-
* Loads one impersonation for the request guard (
|
|
19159
|
+
* Loads one impersonation for the request guard. Only a finished (or
|
|
19160
|
+
* unknown) impersonation is cached for 5 seconds; an active one is read
|
|
19161
|
+
* on every request, so ending it on one process takes effect on every
|
|
19162
|
+
* other process at once (security review 2, hardening 4).
|
|
18394
19163
|
*
|
|
18395
19164
|
* @param {string} documentId Impersonation id.
|
|
18396
19165
|
* @returns {Promise<{id: string, actorId: string, targetId: string|null, state: string,
|
|
@@ -18410,7 +19179,9 @@ var require_impersonation = __commonJS({
|
|
|
18410
19179
|
state: row.state,
|
|
18411
19180
|
expiresAt: new Date(row.expiresAt).getTime()
|
|
18412
19181
|
} : null;
|
|
18413
|
-
|
|
19182
|
+
if (!value || value.state !== "active") {
|
|
19183
|
+
remember(recordCache, documentId, { value, at: Date.now() });
|
|
19184
|
+
}
|
|
18414
19185
|
return value;
|
|
18415
19186
|
},
|
|
18416
19187
|
/**
|
|
@@ -22947,227 +23718,6 @@ var require_security_log = __commonJS({
|
|
|
22947
23718
|
}
|
|
22948
23719
|
});
|
|
22949
23720
|
|
|
22950
|
-
// server/src/utils/webhook-delivery.js
|
|
22951
|
-
var require_webhook_delivery = __commonJS({
|
|
22952
|
-
"server/src/utils/webhook-delivery.js"(exports2, module2) {
|
|
22953
|
-
"use strict";
|
|
22954
|
-
var crypto = require("node:crypto");
|
|
22955
|
-
var dns = require("node:dns");
|
|
22956
|
-
var https = require("node:https");
|
|
22957
|
-
var net = require("node:net");
|
|
22958
|
-
var SIGNATURE_HEADER = "X-Magic-Sessionmanager-Signature";
|
|
22959
|
-
var EVENT_HEADER = "X-Magic-Sessionmanager-Event";
|
|
22960
|
-
var DELIVERY_HEADER = "X-Magic-Sessionmanager-Delivery";
|
|
22961
|
-
var USER_AGENT = "Strapi-Magic-SessionManager-Webhook/2.0";
|
|
22962
|
-
var TIMEOUT_MS = 5e3;
|
|
22963
|
-
var MAX_RESPONSE_BYTES = 64 * 1024;
|
|
22964
|
-
var RETRY_DELAYS_MS = Object.freeze([0, 2e3, 1e4]);
|
|
22965
|
-
var BLOCKED = (() => {
|
|
22966
|
-
const list = new net.BlockList();
|
|
22967
|
-
for (const [address, prefix] of [
|
|
22968
|
-
["0.0.0.0", 8],
|
|
22969
|
-
["10.0.0.0", 8],
|
|
22970
|
-
["100.64.0.0", 10],
|
|
22971
|
-
["127.0.0.0", 8],
|
|
22972
|
-
["169.254.0.0", 16],
|
|
22973
|
-
["172.16.0.0", 12],
|
|
22974
|
-
["192.0.0.0", 24],
|
|
22975
|
-
["192.0.2.0", 24],
|
|
22976
|
-
["192.88.99.0", 24],
|
|
22977
|
-
["192.168.0.0", 16],
|
|
22978
|
-
["198.18.0.0", 15],
|
|
22979
|
-
["198.51.100.0", 24],
|
|
22980
|
-
["203.0.113.0", 24],
|
|
22981
|
-
["224.0.0.0", 4],
|
|
22982
|
-
["240.0.0.0", 4]
|
|
22983
|
-
]) {
|
|
22984
|
-
list.addSubnet(address, prefix, "ipv4");
|
|
22985
|
-
}
|
|
22986
|
-
for (const [address, prefix] of [
|
|
22987
|
-
["::", 128],
|
|
22988
|
-
["::1", 128],
|
|
22989
|
-
// IPv4-mapped addresses (::ffff:0:0/96) are not listed: BlockList
|
|
22990
|
-
// checks them against the IPv4 rules above, and a listed /96 would
|
|
22991
|
-
// match every IPv4 address.
|
|
22992
|
-
["64:ff9b::", 96],
|
|
22993
|
-
["64:ff9b:1::", 48],
|
|
22994
|
-
["100::", 64],
|
|
22995
|
-
["2001::", 23],
|
|
22996
|
-
["2001:db8::", 32],
|
|
22997
|
-
["2002::", 16],
|
|
22998
|
-
["fc00::", 7],
|
|
22999
|
-
["fe80::", 10],
|
|
23000
|
-
["fec0::", 10],
|
|
23001
|
-
["ff00::", 8]
|
|
23002
|
-
]) {
|
|
23003
|
-
list.addSubnet(address, prefix, "ipv6");
|
|
23004
|
-
}
|
|
23005
|
-
return list;
|
|
23006
|
-
})();
|
|
23007
|
-
function isBlockedAddress(address) {
|
|
23008
|
-
let value = String(address || "").trim();
|
|
23009
|
-
if (value.toLowerCase().startsWith("::ffff:") && net.isIPv4(value.slice(7))) {
|
|
23010
|
-
value = value.slice(7);
|
|
23011
|
-
}
|
|
23012
|
-
const version = net.isIP(value);
|
|
23013
|
-
if (version === 0) return true;
|
|
23014
|
-
return BLOCKED.check(value, version === 4 ? "ipv4" : "ipv6");
|
|
23015
|
-
}
|
|
23016
|
-
function signPayload(secret, body, timestamp = Math.floor(Date.now() / 1e3)) {
|
|
23017
|
-
const digest = crypto.createHmac("sha256", secret).update(`${timestamp}.${body}`).digest("hex");
|
|
23018
|
-
return `t=${timestamp},v1=${digest}`;
|
|
23019
|
-
}
|
|
23020
|
-
function verifySignature(secret, body, header, { toleranceSeconds = 300, now = Date.now() } = {}) {
|
|
23021
|
-
const match = /^t=(\d{1,12}),v1=([a-f0-9]{64})$/.exec(String(header || ""));
|
|
23022
|
-
if (!match) return false;
|
|
23023
|
-
const timestamp = Number(match[1]);
|
|
23024
|
-
if (Math.abs(now / 1e3 - timestamp) > toleranceSeconds) return false;
|
|
23025
|
-
const expected = crypto.createHmac("sha256", secret).update(`${timestamp}.${body}`).digest();
|
|
23026
|
-
const given = Buffer.from(match[2], "hex");
|
|
23027
|
-
return given.length === expected.length && crypto.timingSafeEqual(given, expected);
|
|
23028
|
-
}
|
|
23029
|
-
var DeliveryError = class extends Error {
|
|
23030
|
-
/**
|
|
23031
|
-
* @param {string} code Stable code.
|
|
23032
|
-
* @param {boolean} retryable Whether another attempt may succeed.
|
|
23033
|
-
* @param {number|null} [status] HTTP status, when there was one.
|
|
23034
|
-
*/
|
|
23035
|
-
constructor(code, retryable, status = null) {
|
|
23036
|
-
super(code);
|
|
23037
|
-
this.name = "DeliveryError";
|
|
23038
|
-
this.code = code;
|
|
23039
|
-
this.retryable = retryable;
|
|
23040
|
-
this.status = status;
|
|
23041
|
-
}
|
|
23042
|
-
};
|
|
23043
|
-
var resolveAll = (hostname) => dns.promises.lookup(hostname, { all: true, verbatim: true });
|
|
23044
|
-
function httpsPost({ url, address, headers, body, timeoutMs }) {
|
|
23045
|
-
return new Promise((resolve, reject) => {
|
|
23046
|
-
const request = https.request(
|
|
23047
|
-
{
|
|
23048
|
-
protocol: "https:",
|
|
23049
|
-
hostname: url.hostname,
|
|
23050
|
-
port: url.port || 443,
|
|
23051
|
-
path: `${url.pathname}${url.search}`,
|
|
23052
|
-
method: "POST",
|
|
23053
|
-
headers: { ...headers, "Content-Length": Buffer.byteLength(body) },
|
|
23054
|
-
servername: net.isIP(url.hostname) ? void 0 : url.hostname,
|
|
23055
|
-
timeout: timeoutMs,
|
|
23056
|
-
// Pinned to the address that passed the check: no second lookup.
|
|
23057
|
-
lookup: (_hostname, options, callback) => {
|
|
23058
|
-
if (options && options.all) callback(null, [address]);
|
|
23059
|
-
else callback(null, address.address, address.family);
|
|
23060
|
-
}
|
|
23061
|
-
},
|
|
23062
|
-
(response) => {
|
|
23063
|
-
let received = 0;
|
|
23064
|
-
response.on("data", (chunk) => {
|
|
23065
|
-
received += chunk.length;
|
|
23066
|
-
if (received > MAX_RESPONSE_BYTES) response.destroy();
|
|
23067
|
-
});
|
|
23068
|
-
response.on("end", () => resolve(response.statusCode || 0));
|
|
23069
|
-
response.on("close", () => resolve(response.statusCode || 0));
|
|
23070
|
-
response.on("error", () => resolve(response.statusCode || 0));
|
|
23071
|
-
}
|
|
23072
|
-
);
|
|
23073
|
-
request.on("timeout", () => request.destroy(new DeliveryError("timeout", true)));
|
|
23074
|
-
request.on(
|
|
23075
|
-
"error",
|
|
23076
|
-
(err) => reject(err instanceof DeliveryError ? err : new DeliveryError("network_error", true))
|
|
23077
|
-
);
|
|
23078
|
-
request.end(body);
|
|
23079
|
-
});
|
|
23080
|
-
}
|
|
23081
|
-
async function deliverOnce({
|
|
23082
|
-
url,
|
|
23083
|
-
body,
|
|
23084
|
-
headers,
|
|
23085
|
-
resolve = resolveAll,
|
|
23086
|
-
post = httpsPost,
|
|
23087
|
-
timeoutMs = TIMEOUT_MS
|
|
23088
|
-
}) {
|
|
23089
|
-
let parsed;
|
|
23090
|
-
try {
|
|
23091
|
-
parsed = new URL(url);
|
|
23092
|
-
} catch {
|
|
23093
|
-
throw new DeliveryError("invalid_url", false);
|
|
23094
|
-
}
|
|
23095
|
-
if (parsed.protocol !== "https:" || parsed.username || parsed.password) {
|
|
23096
|
-
throw new DeliveryError("invalid_url", false);
|
|
23097
|
-
}
|
|
23098
|
-
const host = parsed.hostname.replace(/^\[|\]$/g, "");
|
|
23099
|
-
let addresses;
|
|
23100
|
-
if (net.isIP(host)) {
|
|
23101
|
-
addresses = [{ address: host, family: net.isIP(host) }];
|
|
23102
|
-
} else {
|
|
23103
|
-
try {
|
|
23104
|
-
addresses = await resolve(host);
|
|
23105
|
-
} catch {
|
|
23106
|
-
throw new DeliveryError("dns_failed", true);
|
|
23107
|
-
}
|
|
23108
|
-
}
|
|
23109
|
-
if (!Array.isArray(addresses) || addresses.length === 0)
|
|
23110
|
-
throw new DeliveryError("dns_failed", true);
|
|
23111
|
-
if (addresses.some((entry) => isBlockedAddress(entry.address))) {
|
|
23112
|
-
throw new DeliveryError("address_not_allowed", false);
|
|
23113
|
-
}
|
|
23114
|
-
const status = await post({ url: parsed, address: addresses[0], headers, body, timeoutMs });
|
|
23115
|
-
if (status >= 200 && status < 300) return { status };
|
|
23116
|
-
if (status >= 300 && status < 400)
|
|
23117
|
-
throw new DeliveryError("redirect_not_followed", false, status);
|
|
23118
|
-
throw new DeliveryError(`http_${status}`, status === 429 || status >= 500, status);
|
|
23119
|
-
}
|
|
23120
|
-
function buildSignedRequest({ event, data, secret, id = crypto.randomUUID(), now = /* @__PURE__ */ new Date() }) {
|
|
23121
|
-
const body = JSON.stringify({ id, event, createdAt: now.toISOString(), data });
|
|
23122
|
-
return {
|
|
23123
|
-
id,
|
|
23124
|
-
body,
|
|
23125
|
-
headers: {
|
|
23126
|
-
"Content-Type": "application/json",
|
|
23127
|
-
"User-Agent": USER_AGENT,
|
|
23128
|
-
[EVENT_HEADER]: event,
|
|
23129
|
-
[DELIVERY_HEADER]: id,
|
|
23130
|
-
[SIGNATURE_HEADER]: signPayload(secret, body, Math.floor(now.getTime() / 1e3))
|
|
23131
|
-
}
|
|
23132
|
-
};
|
|
23133
|
-
}
|
|
23134
|
-
async function deliverWithRetries({
|
|
23135
|
-
delays = RETRY_DELAYS_MS,
|
|
23136
|
-
sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms).unref?.()),
|
|
23137
|
-
...request
|
|
23138
|
-
}) {
|
|
23139
|
-
let attempts = 0;
|
|
23140
|
-
let last = { ok: false, status: null, code: "not_sent" };
|
|
23141
|
-
for (const delay of delays) {
|
|
23142
|
-
if (delay > 0) await sleep(delay);
|
|
23143
|
-
attempts += 1;
|
|
23144
|
-
try {
|
|
23145
|
-
const { status } = await deliverOnce(request);
|
|
23146
|
-
return { ok: true, status, code: null, attempts };
|
|
23147
|
-
} catch (err) {
|
|
23148
|
-
const error = err instanceof DeliveryError ? err : new DeliveryError("network_error", true);
|
|
23149
|
-
last = { ok: false, status: error.status, code: error.code };
|
|
23150
|
-
if (!error.retryable) break;
|
|
23151
|
-
}
|
|
23152
|
-
}
|
|
23153
|
-
return { ...last, attempts };
|
|
23154
|
-
}
|
|
23155
|
-
module2.exports = {
|
|
23156
|
-
DELIVERY_HEADER,
|
|
23157
|
-
DeliveryError,
|
|
23158
|
-
EVENT_HEADER,
|
|
23159
|
-
RETRY_DELAYS_MS,
|
|
23160
|
-
SIGNATURE_HEADER,
|
|
23161
|
-
buildSignedRequest,
|
|
23162
|
-
deliverOnce,
|
|
23163
|
-
deliverWithRetries,
|
|
23164
|
-
isBlockedAddress,
|
|
23165
|
-
signPayload,
|
|
23166
|
-
verifySignature
|
|
23167
|
-
};
|
|
23168
|
-
}
|
|
23169
|
-
});
|
|
23170
|
-
|
|
23171
23721
|
// server/src/services/webhooks.js
|
|
23172
23722
|
var require_webhooks2 = __commonJS({
|
|
23173
23723
|
"server/src/services/webhooks.js"(exports2, module2) {
|
|
@@ -23446,12 +23996,14 @@ var require_rate_limit = __commonJS({
|
|
|
23446
23996
|
"use strict";
|
|
23447
23997
|
var { getPluginSettings } = require_settings_loader();
|
|
23448
23998
|
var { getCoordinator, hashedKey, __resetMemoryForTests } = require_coordination();
|
|
23999
|
+
var { ipBucket } = require_admin_request_info();
|
|
23449
24000
|
var callerKey = (ctx) => {
|
|
23450
24001
|
const userId = ctx.state?.user?.id;
|
|
23451
24002
|
if (userId) return `u:${userId}`;
|
|
23452
24003
|
const tokenId = ctx.state?.auth?.credentials?.id ?? ctx.state?.auth?.credentials?.token ?? null;
|
|
23453
24004
|
if (tokenId) return `t:${String(tokenId).slice(-16)}`;
|
|
23454
|
-
|
|
24005
|
+
const ip = ctx.request.ip || ctx.ip || "";
|
|
24006
|
+
return `ip:${ipBucket(ip) || ip || "unknown"}`;
|
|
23455
24007
|
};
|
|
23456
24008
|
var routeKey = (ctx) => {
|
|
23457
24009
|
const route = ctx.state?.route;
|