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.mjs
CHANGED
|
@@ -1477,10 +1477,249 @@ var require_policy_settings = __commonJS({
|
|
|
1477
1477
|
}
|
|
1478
1478
|
});
|
|
1479
1479
|
|
|
1480
|
+
// server/src/utils/webhook-delivery.js
|
|
1481
|
+
var require_webhook_delivery = __commonJS({
|
|
1482
|
+
"server/src/utils/webhook-delivery.js"(exports, module) {
|
|
1483
|
+
"use strict";
|
|
1484
|
+
var crypto = __require("node:crypto");
|
|
1485
|
+
var dns = __require("node:dns");
|
|
1486
|
+
var https = __require("node:https");
|
|
1487
|
+
var net = __require("node:net");
|
|
1488
|
+
var SIGNATURE_HEADER = "X-Magic-Sessionmanager-Signature";
|
|
1489
|
+
var EVENT_HEADER = "X-Magic-Sessionmanager-Event";
|
|
1490
|
+
var DELIVERY_HEADER = "X-Magic-Sessionmanager-Delivery";
|
|
1491
|
+
var USER_AGENT = "Strapi-Magic-SessionManager-Webhook/2.0";
|
|
1492
|
+
var TIMEOUT_MS = 5e3;
|
|
1493
|
+
var DEADLINE_MS = 1e4;
|
|
1494
|
+
var MAX_RESPONSE_BYTES = 64 * 1024;
|
|
1495
|
+
var RETRY_DELAYS_MS = Object.freeze([0, 2e3, 1e4]);
|
|
1496
|
+
var BLOCKED = (() => {
|
|
1497
|
+
const list = new net.BlockList();
|
|
1498
|
+
for (const [address, prefix] of [
|
|
1499
|
+
["0.0.0.0", 8],
|
|
1500
|
+
["10.0.0.0", 8],
|
|
1501
|
+
["100.64.0.0", 10],
|
|
1502
|
+
["127.0.0.0", 8],
|
|
1503
|
+
["169.254.0.0", 16],
|
|
1504
|
+
["172.16.0.0", 12],
|
|
1505
|
+
["192.0.0.0", 24],
|
|
1506
|
+
["192.0.2.0", 24],
|
|
1507
|
+
["192.88.99.0", 24],
|
|
1508
|
+
["192.168.0.0", 16],
|
|
1509
|
+
["198.18.0.0", 15],
|
|
1510
|
+
["198.51.100.0", 24],
|
|
1511
|
+
["203.0.113.0", 24],
|
|
1512
|
+
["224.0.0.0", 4],
|
|
1513
|
+
["240.0.0.0", 4]
|
|
1514
|
+
]) {
|
|
1515
|
+
list.addSubnet(address, prefix, "ipv4");
|
|
1516
|
+
}
|
|
1517
|
+
for (const [address, prefix] of [
|
|
1518
|
+
// IPv4-compatible (::a.b.c.d, deprecated) and IPv4-translated
|
|
1519
|
+
// (::ffff:0:a.b.c.d, RFC 2765) forms, which include the unspecified and
|
|
1520
|
+
// loopback addresses (security review 2, hardening 1).
|
|
1521
|
+
["::", 96],
|
|
1522
|
+
["::ffff:0:0:0", 96],
|
|
1523
|
+
// IPv4-mapped addresses (::ffff:0:0/96) are not listed: BlockList
|
|
1524
|
+
// checks them against the IPv4 rules above, and a listed /96 would
|
|
1525
|
+
// match every IPv4 address.
|
|
1526
|
+
["64:ff9b::", 96],
|
|
1527
|
+
["64:ff9b:1::", 48],
|
|
1528
|
+
["100::", 64],
|
|
1529
|
+
["2001::", 23],
|
|
1530
|
+
["2001:db8::", 32],
|
|
1531
|
+
["2002::", 16],
|
|
1532
|
+
["fc00::", 7],
|
|
1533
|
+
["fe80::", 10],
|
|
1534
|
+
["fec0::", 10],
|
|
1535
|
+
["ff00::", 8]
|
|
1536
|
+
]) {
|
|
1537
|
+
list.addSubnet(address, prefix, "ipv6");
|
|
1538
|
+
}
|
|
1539
|
+
return list;
|
|
1540
|
+
})();
|
|
1541
|
+
function isBlockedAddress(address) {
|
|
1542
|
+
let value = String(address || "").trim();
|
|
1543
|
+
if (value.toLowerCase().startsWith("::ffff:") && net.isIPv4(value.slice(7))) {
|
|
1544
|
+
value = value.slice(7);
|
|
1545
|
+
}
|
|
1546
|
+
const version = net.isIP(value);
|
|
1547
|
+
if (version === 0) return true;
|
|
1548
|
+
return BLOCKED.check(value, version === 4 ? "ipv4" : "ipv6");
|
|
1549
|
+
}
|
|
1550
|
+
function signPayload(secret, body, timestamp = Math.floor(Date.now() / 1e3)) {
|
|
1551
|
+
const digest = crypto.createHmac("sha256", secret).update(`${timestamp}.${body}`).digest("hex");
|
|
1552
|
+
return `t=${timestamp},v1=${digest}`;
|
|
1553
|
+
}
|
|
1554
|
+
function verifySignature(secret, body, header, { toleranceSeconds = 300, now = Date.now() } = {}) {
|
|
1555
|
+
const match = /^t=(\d{1,12}),v1=([a-f0-9]{64})$/.exec(String(header || ""));
|
|
1556
|
+
if (!match) return false;
|
|
1557
|
+
const timestamp = Number(match[1]);
|
|
1558
|
+
if (Math.abs(now / 1e3 - timestamp) > toleranceSeconds) return false;
|
|
1559
|
+
const expected = crypto.createHmac("sha256", secret).update(`${timestamp}.${body}`).digest();
|
|
1560
|
+
const given = Buffer.from(match[2], "hex");
|
|
1561
|
+
return given.length === expected.length && crypto.timingSafeEqual(given, expected);
|
|
1562
|
+
}
|
|
1563
|
+
var DeliveryError = class extends Error {
|
|
1564
|
+
/**
|
|
1565
|
+
* @param {string} code Stable code.
|
|
1566
|
+
* @param {boolean} retryable Whether another attempt may succeed.
|
|
1567
|
+
* @param {number|null} [status] HTTP status, when there was one.
|
|
1568
|
+
*/
|
|
1569
|
+
constructor(code, retryable, status = null) {
|
|
1570
|
+
super(code);
|
|
1571
|
+
this.name = "DeliveryError";
|
|
1572
|
+
this.code = code;
|
|
1573
|
+
this.retryable = retryable;
|
|
1574
|
+
this.status = status;
|
|
1575
|
+
}
|
|
1576
|
+
};
|
|
1577
|
+
var resolveAll = (hostname) => dns.promises.lookup(hostname, { all: true, verbatim: true });
|
|
1578
|
+
function httpsPost({ url, address, headers, body, timeoutMs, deadlineMs = DEADLINE_MS }) {
|
|
1579
|
+
return new Promise((resolve, reject) => {
|
|
1580
|
+
const request = https.request(
|
|
1581
|
+
{
|
|
1582
|
+
protocol: "https:",
|
|
1583
|
+
hostname: url.hostname,
|
|
1584
|
+
port: url.port || 443,
|
|
1585
|
+
path: `${url.pathname}${url.search}`,
|
|
1586
|
+
method: "POST",
|
|
1587
|
+
headers: { ...headers, "Content-Length": Buffer.byteLength(body) },
|
|
1588
|
+
servername: net.isIP(url.hostname) ? void 0 : url.hostname,
|
|
1589
|
+
timeout: timeoutMs,
|
|
1590
|
+
signal: AbortSignal.timeout(deadlineMs),
|
|
1591
|
+
// Pinned to the address that passed the check: no second lookup.
|
|
1592
|
+
lookup: (_hostname, options, callback) => {
|
|
1593
|
+
if (options && options.all) callback(null, [address]);
|
|
1594
|
+
else callback(null, address.address, address.family);
|
|
1595
|
+
}
|
|
1596
|
+
},
|
|
1597
|
+
(response) => {
|
|
1598
|
+
let received = 0;
|
|
1599
|
+
response.on("data", (chunk) => {
|
|
1600
|
+
received += chunk.length;
|
|
1601
|
+
if (received > MAX_RESPONSE_BYTES) response.destroy();
|
|
1602
|
+
});
|
|
1603
|
+
response.on("end", () => resolve(response.statusCode || 0));
|
|
1604
|
+
response.on("close", () => resolve(response.statusCode || 0));
|
|
1605
|
+
response.on("error", () => resolve(response.statusCode || 0));
|
|
1606
|
+
}
|
|
1607
|
+
);
|
|
1608
|
+
request.on("timeout", () => request.destroy(new DeliveryError("timeout", true)));
|
|
1609
|
+
request.on(
|
|
1610
|
+
"error",
|
|
1611
|
+
(err) => reject(
|
|
1612
|
+
err instanceof DeliveryError ? err : err?.name === "AbortError" ? new DeliveryError("timeout", true) : new DeliveryError("network_error", true)
|
|
1613
|
+
)
|
|
1614
|
+
);
|
|
1615
|
+
request.end(body);
|
|
1616
|
+
});
|
|
1617
|
+
}
|
|
1618
|
+
async function deliverOnce({
|
|
1619
|
+
url,
|
|
1620
|
+
body,
|
|
1621
|
+
headers,
|
|
1622
|
+
resolve = resolveAll,
|
|
1623
|
+
post = httpsPost,
|
|
1624
|
+
timeoutMs = TIMEOUT_MS,
|
|
1625
|
+
deadlineMs = DEADLINE_MS
|
|
1626
|
+
}) {
|
|
1627
|
+
let parsed;
|
|
1628
|
+
try {
|
|
1629
|
+
parsed = new URL(url);
|
|
1630
|
+
} catch {
|
|
1631
|
+
throw new DeliveryError("invalid_url", false);
|
|
1632
|
+
}
|
|
1633
|
+
if (parsed.protocol !== "https:" || parsed.username || parsed.password) {
|
|
1634
|
+
throw new DeliveryError("invalid_url", false);
|
|
1635
|
+
}
|
|
1636
|
+
const host = parsed.hostname.replace(/^\[|\]$/g, "");
|
|
1637
|
+
let addresses;
|
|
1638
|
+
if (net.isIP(host)) {
|
|
1639
|
+
addresses = [{ address: host, family: net.isIP(host) }];
|
|
1640
|
+
} else {
|
|
1641
|
+
try {
|
|
1642
|
+
addresses = await resolve(host);
|
|
1643
|
+
} catch {
|
|
1644
|
+
throw new DeliveryError("dns_failed", true);
|
|
1645
|
+
}
|
|
1646
|
+
}
|
|
1647
|
+
if (!Array.isArray(addresses) || addresses.length === 0)
|
|
1648
|
+
throw new DeliveryError("dns_failed", true);
|
|
1649
|
+
if (addresses.some((entry) => isBlockedAddress(entry.address))) {
|
|
1650
|
+
throw new DeliveryError("address_not_allowed", false);
|
|
1651
|
+
}
|
|
1652
|
+
const status = await post({
|
|
1653
|
+
url: parsed,
|
|
1654
|
+
address: addresses[0],
|
|
1655
|
+
headers,
|
|
1656
|
+
body,
|
|
1657
|
+
timeoutMs,
|
|
1658
|
+
deadlineMs
|
|
1659
|
+
});
|
|
1660
|
+
if (status >= 200 && status < 300) return { status };
|
|
1661
|
+
if (status >= 300 && status < 400)
|
|
1662
|
+
throw new DeliveryError("redirect_not_followed", false, status);
|
|
1663
|
+
throw new DeliveryError(`http_${status}`, status === 429 || status >= 500, status);
|
|
1664
|
+
}
|
|
1665
|
+
function buildSignedRequest({ event, data, secret, id = crypto.randomUUID(), now = /* @__PURE__ */ new Date() }) {
|
|
1666
|
+
const body = JSON.stringify({ id, event, createdAt: now.toISOString(), data });
|
|
1667
|
+
return {
|
|
1668
|
+
id,
|
|
1669
|
+
body,
|
|
1670
|
+
headers: {
|
|
1671
|
+
"Content-Type": "application/json",
|
|
1672
|
+
"User-Agent": USER_AGENT,
|
|
1673
|
+
[EVENT_HEADER]: event,
|
|
1674
|
+
[DELIVERY_HEADER]: id,
|
|
1675
|
+
[SIGNATURE_HEADER]: signPayload(secret, body, Math.floor(now.getTime() / 1e3))
|
|
1676
|
+
}
|
|
1677
|
+
};
|
|
1678
|
+
}
|
|
1679
|
+
async function deliverWithRetries({
|
|
1680
|
+
delays = RETRY_DELAYS_MS,
|
|
1681
|
+
sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms).unref?.()),
|
|
1682
|
+
...request
|
|
1683
|
+
}) {
|
|
1684
|
+
let attempts = 0;
|
|
1685
|
+
let last = { ok: false, status: null, code: "not_sent" };
|
|
1686
|
+
for (const delay of delays) {
|
|
1687
|
+
if (delay > 0) await sleep(delay);
|
|
1688
|
+
attempts += 1;
|
|
1689
|
+
try {
|
|
1690
|
+
const { status } = await deliverOnce(request);
|
|
1691
|
+
return { ok: true, status, code: null, attempts };
|
|
1692
|
+
} catch (err) {
|
|
1693
|
+
const error = err instanceof DeliveryError ? err : new DeliveryError("network_error", true);
|
|
1694
|
+
last = { ok: false, status: error.status, code: error.code };
|
|
1695
|
+
if (!error.retryable) break;
|
|
1696
|
+
}
|
|
1697
|
+
}
|
|
1698
|
+
return { ...last, attempts };
|
|
1699
|
+
}
|
|
1700
|
+
module.exports = {
|
|
1701
|
+
DEADLINE_MS,
|
|
1702
|
+
DELIVERY_HEADER,
|
|
1703
|
+
DeliveryError,
|
|
1704
|
+
EVENT_HEADER,
|
|
1705
|
+
RETRY_DELAYS_MS,
|
|
1706
|
+
SIGNATURE_HEADER,
|
|
1707
|
+
buildSignedRequest,
|
|
1708
|
+
deliverOnce,
|
|
1709
|
+
deliverWithRetries,
|
|
1710
|
+
isBlockedAddress,
|
|
1711
|
+
signPayload,
|
|
1712
|
+
verifySignature
|
|
1713
|
+
};
|
|
1714
|
+
}
|
|
1715
|
+
});
|
|
1716
|
+
|
|
1480
1717
|
// server/src/utils/detection-settings.js
|
|
1481
1718
|
var require_detection_settings = __commonJS({
|
|
1482
1719
|
"server/src/utils/detection-settings.js"(exports, module) {
|
|
1483
1720
|
"use strict";
|
|
1721
|
+
var net = __require("node:net");
|
|
1722
|
+
var { isBlockedAddress } = require_webhook_delivery();
|
|
1484
1723
|
var WEBHOOK_EVENTS = Object.freeze([
|
|
1485
1724
|
"login.success",
|
|
1486
1725
|
"login.suspicious",
|
|
@@ -1565,6 +1804,8 @@ var require_detection_settings = __commonJS({
|
|
|
1565
1804
|
if (!host || host === "localhost" || host.endsWith(".localhost") || host.endsWith(".local")) {
|
|
1566
1805
|
return null;
|
|
1567
1806
|
}
|
|
1807
|
+
const literal = host.replace(/^\[|\]$/g, "");
|
|
1808
|
+
if (net.isIP(literal) && isBlockedAddress(literal)) return null;
|
|
1568
1809
|
return parsed.toString();
|
|
1569
1810
|
}
|
|
1570
1811
|
function normalizeEventList(value) {
|
|
@@ -1935,6 +2176,89 @@ var require_impersonation_rules = __commonJS({
|
|
|
1935
2176
|
}
|
|
1936
2177
|
});
|
|
1937
2178
|
|
|
2179
|
+
// server/src/utils/trusted-proxies.js
|
|
2180
|
+
var require_trusted_proxies = __commonJS({
|
|
2181
|
+
"server/src/utils/trusted-proxies.js"(exports, module) {
|
|
2182
|
+
"use strict";
|
|
2183
|
+
var { parseTrustedAddress } = require_policy_settings();
|
|
2184
|
+
var MAX_TRUSTED_PROXIES = 50;
|
|
2185
|
+
function normalizeTrustedProxies(value) {
|
|
2186
|
+
if (!Array.isArray(value)) return [];
|
|
2187
|
+
const out = [];
|
|
2188
|
+
for (const entry of value.slice(0, MAX_TRUSTED_PROXIES)) {
|
|
2189
|
+
const parsed = parseTrustedAddress(entry);
|
|
2190
|
+
if (parsed && !out.includes(parsed.text)) out.push(parsed.text);
|
|
2191
|
+
}
|
|
2192
|
+
return out;
|
|
2193
|
+
}
|
|
2194
|
+
function isLegacyTrustAll(value) {
|
|
2195
|
+
return value === true;
|
|
2196
|
+
}
|
|
2197
|
+
function validateTrustedProxies(value) {
|
|
2198
|
+
if (typeof value === "boolean") return { value: [], error: null, legacyTrue: value };
|
|
2199
|
+
if (!Array.isArray(value) || value.length > MAX_TRUSTED_PROXIES) {
|
|
2200
|
+
return {
|
|
2201
|
+
value: null,
|
|
2202
|
+
legacyTrue: false,
|
|
2203
|
+
error: {
|
|
2204
|
+
path: ["trustedProxies"],
|
|
2205
|
+
message: `trustedProxies must be a list of at most ${MAX_TRUSTED_PROXIES} IP addresses or CIDR ranges`
|
|
2206
|
+
}
|
|
2207
|
+
};
|
|
2208
|
+
}
|
|
2209
|
+
const parsed = value.map(parseTrustedAddress);
|
|
2210
|
+
const invalid = parsed.findIndex((entry) => entry === null);
|
|
2211
|
+
if (invalid !== -1) {
|
|
2212
|
+
return {
|
|
2213
|
+
value: null,
|
|
2214
|
+
legacyTrue: false,
|
|
2215
|
+
error: {
|
|
2216
|
+
path: ["trustedProxies", invalid],
|
|
2217
|
+
message: "Each trusted proxy must be an IP address or a CIDR range such as 10.0.0.0/8"
|
|
2218
|
+
}
|
|
2219
|
+
};
|
|
2220
|
+
}
|
|
2221
|
+
return {
|
|
2222
|
+
value: [...new Set(parsed.map((entry) => (
|
|
2223
|
+
/** @type {any} */
|
|
2224
|
+
entry.text
|
|
2225
|
+
)))],
|
|
2226
|
+
error: null,
|
|
2227
|
+
legacyTrue: false
|
|
2228
|
+
};
|
|
2229
|
+
}
|
|
2230
|
+
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.";
|
|
2231
|
+
async function migrateLegacyProxyTrust(strapi2, log) {
|
|
2232
|
+
const { withPluginStoreKey } = require_plugin_store();
|
|
2233
|
+
const { notifySettingsChanged } = require_settings_loader();
|
|
2234
|
+
const config = isLegacyTrustAll(
|
|
2235
|
+
strapi2.config.get("plugin::magic-sessionmanager")?.trustedProxies
|
|
2236
|
+
);
|
|
2237
|
+
const store = strapi2.store({ type: "plugin", name: "magic-sessionmanager" });
|
|
2238
|
+
let stored = isLegacyTrustAll((await store.get({ key: "settings" }))?.trustedProxies);
|
|
2239
|
+
if (stored) {
|
|
2240
|
+
stored = await withPluginStoreKey(strapi2, "settings", async (scoped) => {
|
|
2241
|
+
const value = await scoped.get({ key: "settings" });
|
|
2242
|
+
if (!value || !isLegacyTrustAll(value.trustedProxies)) return false;
|
|
2243
|
+
await scoped.set({ key: "settings", value: { ...value, trustedProxies: [] } });
|
|
2244
|
+
return true;
|
|
2245
|
+
});
|
|
2246
|
+
if (stored) await notifySettingsChanged(strapi2);
|
|
2247
|
+
}
|
|
2248
|
+
if (stored || config) log.warn(LEGACY_WARNING);
|
|
2249
|
+
return { stored, config };
|
|
2250
|
+
}
|
|
2251
|
+
module.exports = {
|
|
2252
|
+
LEGACY_WARNING,
|
|
2253
|
+
MAX_TRUSTED_PROXIES,
|
|
2254
|
+
isLegacyTrustAll,
|
|
2255
|
+
migrateLegacyProxyTrust,
|
|
2256
|
+
normalizeTrustedProxies,
|
|
2257
|
+
validateTrustedProxies
|
|
2258
|
+
};
|
|
2259
|
+
}
|
|
2260
|
+
});
|
|
2261
|
+
|
|
1938
2262
|
// server/src/utils/settings-loader.js
|
|
1939
2263
|
var require_settings_loader = __commonJS({
|
|
1940
2264
|
"server/src/utils/settings-loader.js"(exports, module) {
|
|
@@ -1943,6 +2267,7 @@ var require_settings_loader = __commonJS({
|
|
|
1943
2267
|
var { normalizePolicySettings } = require_policy_settings();
|
|
1944
2268
|
var { normalizeDetectionSettings } = require_detection_settings();
|
|
1945
2269
|
var { normalizeImpersonationSettings } = require_impersonation_rules();
|
|
2270
|
+
var { normalizeTrustedProxies } = require_trusted_proxies();
|
|
1946
2271
|
var PLUGIN_ID = "magic-sessionmanager";
|
|
1947
2272
|
var SETTINGS_KEY = "settings";
|
|
1948
2273
|
var CACHE_TTL_MS = 30 * 1e3;
|
|
@@ -2072,7 +2397,8 @@ var require_settings_loader = __commonJS({
|
|
|
2072
2397
|
out.securityLogRetentionDays = toIntInRange(stored.securityLogRetentionDays, 90, 7, 730);
|
|
2073
2398
|
}
|
|
2074
2399
|
if (stored.trustedProxies !== void 0) {
|
|
2075
|
-
|
|
2400
|
+
const proxies = normalizeTrustedProxies(stored.trustedProxies);
|
|
2401
|
+
if (proxies.length > 0) out.trustedProxies = proxies;
|
|
2076
2402
|
}
|
|
2077
2403
|
Object.assign(out, normalizePolicySettings(stored));
|
|
2078
2404
|
Object.assign(out, normalizeDetectionSettings(stored));
|
|
@@ -2191,6 +2517,8 @@ var require_security_log_model = __commonJS({
|
|
|
2191
2517
|
SETTINGS_UPDATED: "settings.updated",
|
|
2192
2518
|
LOG_RETENTION_PURGED: "security-log.retention.purged",
|
|
2193
2519
|
LOG_READ: "security-log.read",
|
|
2520
|
+
// 4.22.1: SESSION_ENCRYPTION_KEY shorter than 32 bytes, once per key.
|
|
2521
|
+
CONFIG_WEAK_KEY: "config.encryption-key.weak",
|
|
2194
2522
|
// App users (Users & Permissions), 4.17.
|
|
2195
2523
|
USER_SIGN_IN_FAILED: "user.sign-in.failed",
|
|
2196
2524
|
USER_SIGN_IN_REFUSED: "user.sign-in.refused",
|
|
@@ -2254,7 +2582,8 @@ var require_security_log_model = __commonJS({
|
|
|
2254
2582
|
var ADMIN_LOG_EVENTS = Object.freeze([
|
|
2255
2583
|
SECURITY_EVENTS.SETTINGS_UPDATED,
|
|
2256
2584
|
SECURITY_EVENTS.LOG_READ,
|
|
2257
|
-
SECURITY_EVENTS.LOG_RETENTION_PURGED
|
|
2585
|
+
SECURITY_EVENTS.LOG_RETENTION_PURGED,
|
|
2586
|
+
SECURITY_EVENTS.CONFIG_WEAK_KEY
|
|
2258
2587
|
]);
|
|
2259
2588
|
var SIGN_IN_FILTERS = Object.freeze({
|
|
2260
2589
|
all: [...ADMIN_SIGN_IN_EVENTS, ...ADMIN_LOG_EVENTS],
|
|
@@ -2663,6 +2992,176 @@ var require_security_log_hardening = __commonJS({
|
|
|
2663
2992
|
}
|
|
2664
2993
|
});
|
|
2665
2994
|
|
|
2995
|
+
// server/src/utils/graphql-impersonation-guard.js
|
|
2996
|
+
var require_graphql_impersonation_guard = __commonJS({
|
|
2997
|
+
"server/src/utils/graphql-impersonation-guard.js"(exports, module) {
|
|
2998
|
+
"use strict";
|
|
2999
|
+
var { errors } = __require("@strapi/utils");
|
|
3000
|
+
var MARK = /* @__PURE__ */ Symbol.for("magic-sessionmanager.graphql-impersonation-guard");
|
|
3001
|
+
var MESSAGE = "Not allowed while impersonating";
|
|
3002
|
+
var REASON = "impersonation-mutation";
|
|
3003
|
+
function impersonationRefusal() {
|
|
3004
|
+
const error = new errors.ForbiddenError(MESSAGE, { reason: REASON });
|
|
3005
|
+
Object.defineProperty(error, "extensions", {
|
|
3006
|
+
value: {
|
|
3007
|
+
code: "FORBIDDEN",
|
|
3008
|
+
http: { status: 403 },
|
|
3009
|
+
error: { name: "ForbiddenError", message: MESSAGE, details: { reason: REASON } }
|
|
3010
|
+
},
|
|
3011
|
+
enumerable: false
|
|
3012
|
+
});
|
|
3013
|
+
return error;
|
|
3014
|
+
}
|
|
3015
|
+
function impersonationOf(contextValue) {
|
|
3016
|
+
const mark = contextValue?.koaContext?.state?.magicImpersonation ?? contextValue?.state?.magicImpersonation;
|
|
3017
|
+
return mark && typeof mark === "object" && typeof mark.id === "string" ? mark : null;
|
|
3018
|
+
}
|
|
3019
|
+
function createImpersonationApolloPlugin(strapi2) {
|
|
3020
|
+
return {
|
|
3021
|
+
[MARK]: true,
|
|
3022
|
+
async requestDidStart() {
|
|
3023
|
+
return {
|
|
3024
|
+
/**
|
|
3025
|
+
* @param {any} requestContext Apollo request context.
|
|
3026
|
+
* @returns {Promise<void>}
|
|
3027
|
+
* @throws {Error} ForbiddenError (HTTP 403, code FORBIDDEN) for a mutation while impersonating.
|
|
3028
|
+
*/
|
|
3029
|
+
async didResolveOperation(requestContext) {
|
|
3030
|
+
if (requestContext?.operation?.operation !== "mutation") return;
|
|
3031
|
+
const impersonation = impersonationOf(requestContext.contextValue);
|
|
3032
|
+
if (!impersonation) return;
|
|
3033
|
+
try {
|
|
3034
|
+
strapi2.plugin("magic-sessionmanager").service("impersonation").recordRefusedCall(impersonation, "mutation");
|
|
3035
|
+
} catch {
|
|
3036
|
+
}
|
|
3037
|
+
throw impersonationRefusal();
|
|
3038
|
+
}
|
|
3039
|
+
};
|
|
3040
|
+
}
|
|
3041
|
+
};
|
|
3042
|
+
}
|
|
3043
|
+
function installGraphqlImpersonationGuard(strapi2, log) {
|
|
3044
|
+
let graphql;
|
|
3045
|
+
try {
|
|
3046
|
+
graphql = strapi2.plugin("graphql") || null;
|
|
3047
|
+
} catch {
|
|
3048
|
+
graphql = null;
|
|
3049
|
+
}
|
|
3050
|
+
if (!graphql) return false;
|
|
3051
|
+
if (typeof strapi2.config?.get !== "function" || typeof strapi2.config?.set !== "function") {
|
|
3052
|
+
return false;
|
|
3053
|
+
}
|
|
3054
|
+
try {
|
|
3055
|
+
const key = "plugin::graphql.apolloServer";
|
|
3056
|
+
const current = strapi2.config.get(key);
|
|
3057
|
+
const server = current && typeof current === "object" ? current : {};
|
|
3058
|
+
const plugins = Array.isArray(server.plugins) ? server.plugins : [];
|
|
3059
|
+
if (plugins.some((plugin) => plugin && plugin[MARK])) return true;
|
|
3060
|
+
strapi2.config.set(key, {
|
|
3061
|
+
...server,
|
|
3062
|
+
plugins: [...plugins, createImpersonationApolloPlugin(strapi2)]
|
|
3063
|
+
});
|
|
3064
|
+
} catch (err) {
|
|
3065
|
+
log?.warn?.("[IMPERSONATION] GraphQL guard could not be installed:", err?.name || "Error");
|
|
3066
|
+
return false;
|
|
3067
|
+
}
|
|
3068
|
+
log?.info?.("[IMPERSONATION] GraphQL mutations are refused while impersonating");
|
|
3069
|
+
return true;
|
|
3070
|
+
}
|
|
3071
|
+
module.exports = {
|
|
3072
|
+
createImpersonationApolloPlugin,
|
|
3073
|
+
impersonationRefusal,
|
|
3074
|
+
installGraphqlImpersonationGuard
|
|
3075
|
+
};
|
|
3076
|
+
}
|
|
3077
|
+
});
|
|
3078
|
+
|
|
3079
|
+
// server/src/utils/auth-controller-guard.js
|
|
3080
|
+
var require_auth_controller_guard = __commonJS({
|
|
3081
|
+
"server/src/utils/auth-controller-guard.js"(exports, module) {
|
|
3082
|
+
"use strict";
|
|
3083
|
+
var WRAPPED = /* @__PURE__ */ Symbol.for("magic-sessionmanager.auth-controller.wrapped");
|
|
3084
|
+
var GUARDED_ACTIONS = Object.freeze({
|
|
3085
|
+
callback: "callback",
|
|
3086
|
+
register: "newSession",
|
|
3087
|
+
resetPassword: "newSession",
|
|
3088
|
+
emailConfirmation: "newSession"
|
|
3089
|
+
});
|
|
3090
|
+
var handlersByStrapi = /* @__PURE__ */ new WeakMap();
|
|
3091
|
+
function installAuthControllerGuard(strapi2, log) {
|
|
3092
|
+
let controller;
|
|
3093
|
+
try {
|
|
3094
|
+
controller = strapi2.plugin("users-permissions")?.controller("auth");
|
|
3095
|
+
} catch {
|
|
3096
|
+
controller = null;
|
|
3097
|
+
}
|
|
3098
|
+
if (!controller || typeof controller !== "object") {
|
|
3099
|
+
log?.warn?.(
|
|
3100
|
+
"[AUTH] Users & Permissions auth controller not found; sign-in checks use paths only"
|
|
3101
|
+
);
|
|
3102
|
+
return [];
|
|
3103
|
+
}
|
|
3104
|
+
const wrapped = [];
|
|
3105
|
+
for (const [action, kind] of Object.entries(GUARDED_ACTIONS)) {
|
|
3106
|
+
const original = controller[action];
|
|
3107
|
+
if (typeof original !== "function") continue;
|
|
3108
|
+
if (original[WRAPPED]) {
|
|
3109
|
+
wrapped.push(action);
|
|
3110
|
+
continue;
|
|
3111
|
+
}
|
|
3112
|
+
const guarded = async function magicSessionAuthGuard(ctx, ...rest) {
|
|
3113
|
+
const run = () => original.call(this, ctx, ...rest);
|
|
3114
|
+
const handlers = handlersByStrapi.get(strapi2);
|
|
3115
|
+
if (!handlers || typeof handlers[kind] !== "function") return run();
|
|
3116
|
+
return handlers[kind](ctx, run);
|
|
3117
|
+
};
|
|
3118
|
+
Object.defineProperty(guarded, WRAPPED, { value: original });
|
|
3119
|
+
controller[action] = guarded;
|
|
3120
|
+
wrapped.push(action);
|
|
3121
|
+
}
|
|
3122
|
+
return wrapped;
|
|
3123
|
+
}
|
|
3124
|
+
function setAuthControllerHandlers(strapi2, handlers) {
|
|
3125
|
+
if (handlers) handlersByStrapi.set(strapi2, handlers);
|
|
3126
|
+
else handlersByStrapi.delete(strapi2);
|
|
3127
|
+
}
|
|
3128
|
+
function uninstallAuthControllerGuard(strapi2) {
|
|
3129
|
+
setAuthControllerHandlers(strapi2, null);
|
|
3130
|
+
let controller;
|
|
3131
|
+
try {
|
|
3132
|
+
controller = strapi2.plugin("users-permissions")?.controller("auth");
|
|
3133
|
+
} catch {
|
|
3134
|
+
return;
|
|
3135
|
+
}
|
|
3136
|
+
if (!controller) return;
|
|
3137
|
+
for (const action of Object.keys(GUARDED_ACTIONS)) {
|
|
3138
|
+
const original = controller[action]?.[WRAPPED];
|
|
3139
|
+
if (typeof original === "function") controller[action] = original;
|
|
3140
|
+
}
|
|
3141
|
+
}
|
|
3142
|
+
var INVALID_CREDENTIALS_MESSAGE = "Invalid identifier or password";
|
|
3143
|
+
function classifyCallbackOutcome(thrown, ctx) {
|
|
3144
|
+
if (thrown) {
|
|
3145
|
+
const error = (
|
|
3146
|
+
/** @type {any} */
|
|
3147
|
+
thrown
|
|
3148
|
+
);
|
|
3149
|
+
return error?.name === "ValidationError" && error?.message === INVALID_CREDENTIALS_MESSAGE ? "failure" : "neutral";
|
|
3150
|
+
}
|
|
3151
|
+
const body = ctx?.body;
|
|
3152
|
+
return body && typeof body === "object" && body.jwt ? "success" : "neutral";
|
|
3153
|
+
}
|
|
3154
|
+
module.exports = {
|
|
3155
|
+
GUARDED_ACTIONS,
|
|
3156
|
+
INVALID_CREDENTIALS_MESSAGE,
|
|
3157
|
+
classifyCallbackOutcome,
|
|
3158
|
+
installAuthControllerGuard,
|
|
3159
|
+
setAuthControllerHandlers,
|
|
3160
|
+
uninstallAuthControllerGuard
|
|
3161
|
+
};
|
|
3162
|
+
}
|
|
3163
|
+
});
|
|
3164
|
+
|
|
2666
3165
|
// server/src/register.js
|
|
2667
3166
|
var require_register = __commonJS({
|
|
2668
3167
|
"server/src/register.js"(exports, module) {
|
|
@@ -2672,6 +3171,8 @@ var require_register = __commonJS({
|
|
|
2672
3171
|
var { isCallerRevocationScope } = require_block_revocation_scope();
|
|
2673
3172
|
var { checkStrapiVersion } = require_strapi_version();
|
|
2674
3173
|
var { disableGraphqlShadowCrud } = require_security_log_hardening();
|
|
3174
|
+
var { installGraphqlImpersonationGuard } = require_graphql_impersonation_guard();
|
|
3175
|
+
var { installAuthControllerGuard } = require_auth_controller_guard();
|
|
2675
3176
|
var USER_UID = "plugin::users-permissions.user";
|
|
2676
3177
|
module.exports = async ({ strapi: strapi2 }) => {
|
|
2677
3178
|
const log = createLogger(strapi2);
|
|
@@ -2770,6 +3271,8 @@ var require_register = __commonJS({
|
|
|
2770
3271
|
}
|
|
2771
3272
|
]);
|
|
2772
3273
|
disableGraphqlShadowCrud(strapi2, log);
|
|
3274
|
+
installGraphqlImpersonationGuard(strapi2, log);
|
|
3275
|
+
installAuthControllerGuard(strapi2, log);
|
|
2773
3276
|
try {
|
|
2774
3277
|
strapi2.db.lifecycles.subscribe(createContentApiPermissionsLifecycle(strapi2));
|
|
2775
3278
|
} catch (err) {
|
|
@@ -2845,42 +3348,69 @@ var require_register = __commonJS({
|
|
|
2845
3348
|
var require_getClientIp = __commonJS({
|
|
2846
3349
|
"server/src/utils/getClientIp.js"(exports, module) {
|
|
2847
3350
|
"use strict";
|
|
2848
|
-
|
|
2849
|
-
|
|
2850
|
-
|
|
2851
|
-
|
|
2852
|
-
|
|
3351
|
+
var net = __require("node:net");
|
|
3352
|
+
var { isTrustedAddress } = require_policy_settings();
|
|
3353
|
+
var { normalizeTrustedProxies } = require_trusted_proxies();
|
|
3354
|
+
var MAX_FORWARDED_LENGTH = 2048;
|
|
3355
|
+
var MAX_FORWARDED_HOPS = 20;
|
|
3356
|
+
var cleanIp = (ip) => {
|
|
3357
|
+
if (!ip) return "unknown";
|
|
3358
|
+
let value = String(ip).trim();
|
|
3359
|
+
if (value.startsWith("[")) {
|
|
3360
|
+
const bracketEnd = value.indexOf("]");
|
|
3361
|
+
if (bracketEnd !== -1) {
|
|
3362
|
+
value = value.substring(1, bracketEnd);
|
|
3363
|
+
}
|
|
3364
|
+
}
|
|
3365
|
+
if (value.toLowerCase().startsWith("::ffff:") && net.isIPv4(value.substring(7))) {
|
|
3366
|
+
value = value.substring(7);
|
|
2853
3367
|
}
|
|
3368
|
+
if (value.includes(".") && value.includes(":") && value.indexOf(":") === value.lastIndexOf(":")) {
|
|
3369
|
+
value = value.split(":")[0];
|
|
3370
|
+
}
|
|
3371
|
+
return value || "unknown";
|
|
3372
|
+
};
|
|
3373
|
+
function trustedProxyList(ctx) {
|
|
3374
|
+
const fromSettings = ctx?.state?.__magicSessionSettings?.trustedProxies;
|
|
3375
|
+
if (fromSettings !== void 0) return normalizeTrustedProxies(fromSettings);
|
|
2854
3376
|
try {
|
|
2855
|
-
const config = ctx?.
|
|
2856
|
-
|
|
2857
|
-
if (trusted === true) return true;
|
|
2858
|
-
if (Array.isArray(trusted) && trusted.length > 0) return true;
|
|
3377
|
+
const config = ctx?.app?.context?.strapi?.config?.get?.("plugin::magic-sessionmanager");
|
|
3378
|
+
return normalizeTrustedProxies(config?.trustedProxies);
|
|
2859
3379
|
} catch {
|
|
3380
|
+
return [];
|
|
2860
3381
|
}
|
|
2861
|
-
|
|
3382
|
+
}
|
|
3383
|
+
function socketAddress(ctx) {
|
|
3384
|
+
const raw = ctx?.req?.socket?.remoteAddress ?? ctx?.request?.socket?.remoteAddress;
|
|
3385
|
+
const cleaned = cleanIp(raw);
|
|
3386
|
+
return cleaned !== "unknown" && net.isIP(cleaned) ? cleaned : null;
|
|
3387
|
+
}
|
|
3388
|
+
function rightMostUntrustedHop(ctx, proxies) {
|
|
3389
|
+
const headers = ctx?.request?.headers || ctx?.request?.header || {};
|
|
3390
|
+
let header = headers["x-forwarded-for"];
|
|
3391
|
+
if (Array.isArray(header)) header = header.join(",");
|
|
3392
|
+
if (typeof header !== "string" || !header) return null;
|
|
3393
|
+
const hops = header.slice(0, MAX_FORWARDED_LENGTH).split(",").map((hop) => cleanIp(hop)).slice(-MAX_FORWARDED_HOPS);
|
|
3394
|
+
let lastValid = null;
|
|
3395
|
+
for (let index = hops.length - 1; index >= 0; index--) {
|
|
3396
|
+
const hop = hops[index];
|
|
3397
|
+
if (!net.isIP(hop)) return lastValid;
|
|
3398
|
+
if (!isTrustedAddress(proxies, hop)) return hop;
|
|
3399
|
+
lastValid = hop;
|
|
3400
|
+
}
|
|
3401
|
+
return lastValid;
|
|
2862
3402
|
}
|
|
2863
3403
|
var getClientIp = (ctx) => {
|
|
2864
3404
|
try {
|
|
2865
|
-
const
|
|
2866
|
-
|
|
2867
|
-
|
|
2868
|
-
if (
|
|
2869
|
-
|
|
2870
|
-
|
|
2871
|
-
if (
|
|
2872
|
-
|
|
2873
|
-
|
|
2874
|
-
if (clientIp) return cleanIp(clientIp);
|
|
2875
|
-
}
|
|
2876
|
-
if (headers["x-client-ip"]) return cleanIp(headers["x-client-ip"]);
|
|
2877
|
-
if (headers["x-cluster-client-ip"]) return cleanIp(headers["x-cluster-client-ip"]);
|
|
2878
|
-
if (headers["forwarded"]) {
|
|
2879
|
-
const match = headers["forwarded"].match(/for=([^;,\s]+)/);
|
|
2880
|
-
if (match && match[1]) return cleanIp(match[1].replace(/"/g, ""));
|
|
2881
|
-
}
|
|
2882
|
-
}
|
|
2883
|
-
if (ctx.request.ip) return cleanIp(ctx.request.ip);
|
|
3405
|
+
const proxies = trustedProxyList(ctx);
|
|
3406
|
+
if (proxies.length > 0) {
|
|
3407
|
+
const peer = socketAddress(ctx);
|
|
3408
|
+
if (peer && isTrustedAddress(proxies, peer)) {
|
|
3409
|
+
return rightMostUntrustedHop(ctx, proxies) || peer;
|
|
3410
|
+
}
|
|
3411
|
+
if (peer) return peer;
|
|
3412
|
+
}
|
|
3413
|
+
if (ctx?.request?.ip) return cleanIp(ctx.request.ip);
|
|
2884
3414
|
return "unknown";
|
|
2885
3415
|
} catch (error) {
|
|
2886
3416
|
if (ctx?.app?.context?.strapi?.log?.debug) {
|
|
@@ -2892,24 +3422,8 @@ var require_getClientIp = __commonJS({
|
|
|
2892
3422
|
return "unknown";
|
|
2893
3423
|
}
|
|
2894
3424
|
};
|
|
2895
|
-
var cleanIp = (ip) => {
|
|
2896
|
-
if (!ip) return "unknown";
|
|
2897
|
-
ip = String(ip).trim();
|
|
2898
|
-
if (ip.startsWith("[")) {
|
|
2899
|
-
const bracketEnd = ip.indexOf("]");
|
|
2900
|
-
if (bracketEnd !== -1) {
|
|
2901
|
-
ip = ip.substring(1, bracketEnd);
|
|
2902
|
-
}
|
|
2903
|
-
}
|
|
2904
|
-
if (ip.startsWith("::ffff:")) {
|
|
2905
|
-
ip = ip.substring(7);
|
|
2906
|
-
}
|
|
2907
|
-
if (ip.includes(".") && ip.includes(":") && ip.indexOf(":") === ip.lastIndexOf(":")) {
|
|
2908
|
-
ip = ip.split(":")[0];
|
|
2909
|
-
}
|
|
2910
|
-
return ip || "unknown";
|
|
2911
|
-
};
|
|
2912
3425
|
module.exports = getClientIp;
|
|
3426
|
+
module.exports.cleanIp = cleanIp;
|
|
2913
3427
|
}
|
|
2914
3428
|
});
|
|
2915
3429
|
|
|
@@ -2922,10 +3436,22 @@ var require_encryption = __commonJS({
|
|
|
2922
3436
|
var IV_LENGTH = 16;
|
|
2923
3437
|
var AUTH_TAG_LENGTH = 16;
|
|
2924
3438
|
var warnedMissingKey = false;
|
|
3439
|
+
var warnedShortKey = false;
|
|
3440
|
+
var MIN_KEY_BYTES = 32;
|
|
3441
|
+
function isEncryptionKeyShort() {
|
|
3442
|
+
const envKey = process.env.SESSION_ENCRYPTION_KEY;
|
|
3443
|
+
return typeof envKey === "string" && envKey.length > 0 ? Buffer.byteLength(envKey, "utf8") < MIN_KEY_BYTES : false;
|
|
3444
|
+
}
|
|
2925
3445
|
var isProduction = () => process.env.NODE_ENV === "production";
|
|
2926
3446
|
function getEncryptionKey() {
|
|
2927
3447
|
const envKey = process.env.SESSION_ENCRYPTION_KEY;
|
|
2928
3448
|
if (envKey && envKey.length > 0) {
|
|
3449
|
+
if (!warnedShortKey && isEncryptionKeyShort()) {
|
|
3450
|
+
warnedShortKey = true;
|
|
3451
|
+
console.warn(
|
|
3452
|
+
`[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).`
|
|
3453
|
+
);
|
|
3454
|
+
}
|
|
2929
3455
|
return crypto.createHash("sha256").update(envKey).digest();
|
|
2930
3456
|
}
|
|
2931
3457
|
if (isProduction()) {
|
|
@@ -3009,6 +3535,8 @@ var require_encryption = __commonJS({
|
|
|
3009
3535
|
);
|
|
3010
3536
|
}
|
|
3011
3537
|
module.exports = {
|
|
3538
|
+
MIN_KEY_BYTES,
|
|
3539
|
+
isEncryptionKeyShort,
|
|
3012
3540
|
derivePurposeKey,
|
|
3013
3541
|
getEncryptionKeyCheck,
|
|
3014
3542
|
encryptToken,
|
|
@@ -3558,7 +4086,6 @@ var require_auth_routes = __commonJS({
|
|
|
3558
4086
|
"POST /api/magic-link/login-totp"
|
|
3559
4087
|
]);
|
|
3560
4088
|
var FAILED_LOGIN_ROUTES = /* @__PURE__ */ new Set([
|
|
3561
|
-
"POST /api/auth/local",
|
|
3562
4089
|
"POST /api/magic-link/login-totp",
|
|
3563
4090
|
"POST /api/magic-link/otp/verify",
|
|
3564
4091
|
"POST /api/magic-link/verify-mfa-totp"
|
|
@@ -3601,18 +4128,24 @@ var require_auth_routes = __commonJS({
|
|
|
3601
4128
|
if (!trimmed) return DEFAULT_API_PREFIX;
|
|
3602
4129
|
return trimmed.startsWith("/") ? trimmed : `/${trimmed}`;
|
|
3603
4130
|
}
|
|
4131
|
+
function normalizeRequestPath(path) {
|
|
4132
|
+
const value = path.toLowerCase().replace(/\/{2,}/g, "/");
|
|
4133
|
+
return value.length > 1 ? value.replace(/\/+$/, "") || "/" : value;
|
|
4134
|
+
}
|
|
3604
4135
|
function toCanonicalApiPath(path, prefix) {
|
|
3605
4136
|
if (typeof path !== "string") return null;
|
|
3606
|
-
const
|
|
3607
|
-
|
|
3608
|
-
if (
|
|
3609
|
-
if (
|
|
3610
|
-
|
|
4137
|
+
const normalizedPath = normalizeRequestPath(path);
|
|
4138
|
+
const normalized = normalizeApiPrefix(prefix).toLowerCase();
|
|
4139
|
+
if (normalized === DEFAULT_API_PREFIX) return normalizedPath;
|
|
4140
|
+
if (normalizedPath === normalized) return DEFAULT_API_PREFIX;
|
|
4141
|
+
if (normalizedPath.startsWith(`${normalized}/`)) {
|
|
4142
|
+
return `${DEFAULT_API_PREFIX}${normalizedPath.slice(normalized.length)}`;
|
|
3611
4143
|
}
|
|
3612
4144
|
return null;
|
|
3613
4145
|
}
|
|
3614
4146
|
module.exports = {
|
|
3615
4147
|
normalizeApiPrefix,
|
|
4148
|
+
normalizeRequestPath,
|
|
3616
4149
|
toCanonicalApiPath,
|
|
3617
4150
|
classifyJwtIssuingRequest,
|
|
3618
4151
|
isFailedLoginTrackedPath,
|
|
@@ -4272,6 +4805,15 @@ var require_admin_request_info = __commonJS({
|
|
|
4272
4805
|
}
|
|
4273
4806
|
return null;
|
|
4274
4807
|
}
|
|
4808
|
+
function ipBucket(ip) {
|
|
4809
|
+
const value = normalizeIp(typeof ip === "string" ? ip : "");
|
|
4810
|
+
if (!value) return null;
|
|
4811
|
+
if (net.isIPv4(value)) return value;
|
|
4812
|
+
if (net.isIPv6(value)) {
|
|
4813
|
+
return `${ipv6Groups(value).slice(0, 4).map((group) => group.toString(16)).join(":")}::/64`;
|
|
4814
|
+
}
|
|
4815
|
+
return null;
|
|
4816
|
+
}
|
|
4275
4817
|
function getRequestUserAgent(ctx) {
|
|
4276
4818
|
const value = ctx?.request?.headers?.["user-agent"];
|
|
4277
4819
|
if (typeof value !== "string" || !value.trim()) return null;
|
|
@@ -4298,6 +4840,7 @@ var require_admin_request_info = __commonJS({
|
|
|
4298
4840
|
module.exports = {
|
|
4299
4841
|
MAX_USER_AGENT_LENGTH,
|
|
4300
4842
|
anonymizeIp,
|
|
4843
|
+
ipBucket,
|
|
4301
4844
|
describeUserAgent,
|
|
4302
4845
|
getRequestIp,
|
|
4303
4846
|
getSocketIp,
|
|
@@ -4598,6 +5141,7 @@ var require_login_lockout = __commonJS({
|
|
|
4598
5141
|
"use strict";
|
|
4599
5142
|
var { hashedKey } = require_coordination();
|
|
4600
5143
|
var { isTrustedAddress } = require_policy_settings();
|
|
5144
|
+
var { ipBucket } = require_admin_request_info();
|
|
4601
5145
|
var LOCK_PREFIX = "lock:";
|
|
4602
5146
|
var KEY_PATTERN = /^(lf|la):[a-f0-9]{48}$/;
|
|
4603
5147
|
var MAX_LISTED_LOCKS = 200;
|
|
@@ -4607,7 +5151,7 @@ var require_login_lockout = __commonJS({
|
|
|
4607
5151
|
if (!value || value.length > 254) return null;
|
|
4608
5152
|
return value;
|
|
4609
5153
|
}
|
|
4610
|
-
var ipKey = (ip) => hashedKey("lf", ip);
|
|
5154
|
+
var ipKey = (ip) => hashedKey("lf", ipBucket(ip) || ip);
|
|
4611
5155
|
var accountKey = (identifier) => hashedKey("la", identifier);
|
|
4612
5156
|
function createLoginLockout(coordinator, { now = () => Date.now() } = {}) {
|
|
4613
5157
|
const remainingSeconds = async (key) => {
|
|
@@ -4627,15 +5171,18 @@ var require_login_lockout = __commonJS({
|
|
|
4627
5171
|
* Checks the locks and counts the attempt before the password check.
|
|
4628
5172
|
*
|
|
4629
5173
|
* @param {{ip: string|null, identifier: string|null, policy: LockoutPolicy,
|
|
4630
|
-
* accountMax: number}} input Client IP, normalised
|
|
4631
|
-
* account threshold for this account's role
|
|
5174
|
+
* accountMax: number, accountExempt?: boolean}} input Client IP, normalised
|
|
5175
|
+
* identifier, policy, the account threshold for this account's role, and
|
|
5176
|
+
* whether the request comes from a device the account is known to use.
|
|
4632
5177
|
* @returns {Promise<{outcome: 'allow'|'locked'|'busy', retryAfter: number,
|
|
4633
5178
|
* lockedKind: 'ip'|'account'|null, reservation: Reservation}>} Decision.
|
|
4634
5179
|
* @sideeffect Increments the shared counters.
|
|
4635
5180
|
*/
|
|
4636
|
-
async reserve({ ip, identifier, policy, accountMax }) {
|
|
4637
|
-
const
|
|
4638
|
-
const
|
|
5181
|
+
async reserve({ ip, identifier, policy, accountMax, accountExempt = false }) {
|
|
5182
|
+
const knownIp = typeof ip === "string" && !!ip && ip !== "unknown";
|
|
5183
|
+
const trusted = knownIp && isTrustedAddress(policy.trusted, ip);
|
|
5184
|
+
const countIp = policy.ipMax > 0 && knownIp && !trusted;
|
|
5185
|
+
const countAccount = accountMax > 0 && typeof identifier === "string" && !!identifier && !trusted && accountExempt !== true;
|
|
4639
5186
|
const reservation = {
|
|
4640
5187
|
ipKey: countIp ? ipKey(
|
|
4641
5188
|
/** @type {string} */
|
|
@@ -4688,10 +5235,8 @@ var require_login_lockout = __commonJS({
|
|
|
4688
5235
|
*/
|
|
4689
5236
|
async settle(reservation, result, { policy, accountMax, display = {} }) {
|
|
4690
5237
|
if (result === "success") {
|
|
4691
|
-
|
|
4692
|
-
|
|
4693
|
-
await coordinator.clear(key);
|
|
4694
|
-
}
|
|
5238
|
+
if (reservation.ipKey) await coordinator.release(reservation.ipKey);
|
|
5239
|
+
if (reservation.accountKey) await coordinator.clear(reservation.accountKey);
|
|
4695
5240
|
return [];
|
|
4696
5241
|
}
|
|
4697
5242
|
if (result !== "failure") {
|
|
@@ -5155,6 +5700,15 @@ var require_sign_in_signals = __commonJS({
|
|
|
5155
5700
|
});
|
|
5156
5701
|
return Array.isArray(rows) ? rows : [];
|
|
5157
5702
|
}
|
|
5703
|
+
async function isRecognizedDevice(strapi2, userDocumentId, { userAgent, deviceId }) {
|
|
5704
|
+
if (typeof userDocumentId !== "string" || !userDocumentId) return false;
|
|
5705
|
+
if (typeof deviceId !== "string" || !deviceId) return false;
|
|
5706
|
+
const deviceKey = deviceKeyOf(userAgent || "", deviceId);
|
|
5707
|
+
const count = await strapi2.documents(SESSION_UID).count({
|
|
5708
|
+
filters: { user: { documentId: userDocumentId }, deviceKey }
|
|
5709
|
+
});
|
|
5710
|
+
return Number(count) > 0;
|
|
5711
|
+
}
|
|
5158
5712
|
function isNewDevice(previous, { deviceKey, userAgent }) {
|
|
5159
5713
|
if (previous.length === 0) return false;
|
|
5160
5714
|
if (previous.some((row) => row.deviceKey && row.deviceKey === deviceKey)) return false;
|
|
@@ -5183,7 +5737,7 @@ var require_sign_in_signals = __commonJS({
|
|
|
5183
5737
|
const token = await issueNotMeToken(getCoordinator(strapi2), { sessionId, userId });
|
|
5184
5738
|
if (!token) return null;
|
|
5185
5739
|
const prefix = normalizeApiPrefix(strapi2.config.get("api.rest.prefix", "/api"));
|
|
5186
|
-
return `${base}${prefix}/magic-sessionmanager/not-me
|
|
5740
|
+
return `${base}${prefix}/magic-sessionmanager/not-me#token=${encodeURIComponent(token)}`;
|
|
5187
5741
|
}
|
|
5188
5742
|
async function runSignInSignals({
|
|
5189
5743
|
strapi: strapi2,
|
|
@@ -5272,6 +5826,7 @@ var require_sign_in_signals = __commonJS({
|
|
|
5272
5826
|
return outcome;
|
|
5273
5827
|
}
|
|
5274
5828
|
module.exports = {
|
|
5829
|
+
isRecognizedDevice,
|
|
5275
5830
|
notMeUrl,
|
|
5276
5831
|
runSignInSignals,
|
|
5277
5832
|
deviceFamilies,
|
|
@@ -5376,7 +5931,11 @@ var require_impersonation_guard = __commonJS({
|
|
|
5376
5931
|
`impersonation-${restricted}`
|
|
5377
5932
|
);
|
|
5378
5933
|
}
|
|
5379
|
-
ctx.state.magicImpersonation = {
|
|
5934
|
+
ctx.state.magicImpersonation = {
|
|
5935
|
+
id: impersonation.id,
|
|
5936
|
+
actorId: impersonation.actorId,
|
|
5937
|
+
targetId: impersonation.targetId || null
|
|
5938
|
+
};
|
|
5380
5939
|
try {
|
|
5381
5940
|
await next();
|
|
5382
5941
|
} finally {
|
|
@@ -9470,7 +10029,13 @@ var require_bootstrap = __commonJS({
|
|
|
9470
10029
|
"server/src/bootstrap.js"(exports, module) {
|
|
9471
10030
|
"use strict";
|
|
9472
10031
|
var getClientIp = require_getClientIp();
|
|
9473
|
-
var {
|
|
10032
|
+
var {
|
|
10033
|
+
MIN_KEY_BYTES,
|
|
10034
|
+
encryptToken,
|
|
10035
|
+
getEncryptionKeyCheck,
|
|
10036
|
+
hashToken,
|
|
10037
|
+
isEncryptionKeyShort
|
|
10038
|
+
} = require_encryption();
|
|
9474
10039
|
var { createLogger } = require_logger();
|
|
9475
10040
|
var { resolveUserDocumentId } = require_resolve_user();
|
|
9476
10041
|
var { getPluginSettings, getSessionCreationGraceMs } = require_settings_loader();
|
|
@@ -9481,7 +10046,12 @@ var require_bootstrap = __commonJS({
|
|
|
9481
10046
|
var { REVOCATION_UID } = require_session_revocation();
|
|
9482
10047
|
var { getNativeSessionManager } = require_native_session_manager();
|
|
9483
10048
|
var { CONTENT_API_PERMISSIONS_VERSION } = require_content_api_permissions();
|
|
9484
|
-
var {
|
|
10049
|
+
var {
|
|
10050
|
+
getCoordinator,
|
|
10051
|
+
hashedKey,
|
|
10052
|
+
initCoordination,
|
|
10053
|
+
LockTimeoutError
|
|
10054
|
+
} = require_coordination();
|
|
9485
10055
|
var { removeLegacyLicenseData, withPluginStoreKey } = require_plugin_store();
|
|
9486
10056
|
var {
|
|
9487
10057
|
normalizeApiPrefix,
|
|
@@ -9530,8 +10100,20 @@ var require_bootstrap = __commonJS({
|
|
|
9530
10100
|
} = require_sign_in_policies();
|
|
9531
10101
|
var { SECURITY_EVENTS, USER_SIGN_IN_EVENTS } = require_security_log_model();
|
|
9532
10102
|
var { applyUpgradeDefaults } = require_upgrade_defaults();
|
|
9533
|
-
var {
|
|
10103
|
+
var {
|
|
10104
|
+
deviceKeyOf,
|
|
10105
|
+
isRecognizedDevice,
|
|
10106
|
+
requestDeviceId,
|
|
10107
|
+
runSignInSignals
|
|
10108
|
+
} = require_sign_in_signals();
|
|
9534
10109
|
var { anonymizeIp, normalizeIp } = require_admin_request_info();
|
|
10110
|
+
var { migrateLegacyProxyTrust } = require_trusted_proxies();
|
|
10111
|
+
var { errors: utilsErrors } = __require("@strapi/utils");
|
|
10112
|
+
var {
|
|
10113
|
+
classifyCallbackOutcome,
|
|
10114
|
+
setAuthControllerHandlers
|
|
10115
|
+
} = require_auth_controller_guard();
|
|
10116
|
+
var { normalizePath } = require_impersonation_rules();
|
|
9535
10117
|
var SESSION_UID = "plugin::magic-sessionmanager.session";
|
|
9536
10118
|
var RETENTION_INTERVAL_MS = 24 * 60 * 60 * 1e3;
|
|
9537
10119
|
var JOB_LEASES = Object.freeze({
|
|
@@ -9574,6 +10156,12 @@ var require_bootstrap = __commonJS({
|
|
|
9574
10156
|
try {
|
|
9575
10157
|
const coordinator = await initCoordination(strapi2, log);
|
|
9576
10158
|
await checkEncryptionKeyConsistency(strapi2, log);
|
|
10159
|
+
await warnShortEncryptionKey(strapi2, log);
|
|
10160
|
+
try {
|
|
10161
|
+
await migrateLegacyProxyTrust(strapi2, log);
|
|
10162
|
+
} catch (err) {
|
|
10163
|
+
log.warn("[CONFIG] trustedProxies could not be migrated:", err?.name || "Error");
|
|
10164
|
+
}
|
|
9577
10165
|
try {
|
|
9578
10166
|
await applyUpgradeDefaults(strapi2, log);
|
|
9579
10167
|
} catch (err) {
|
|
@@ -9687,8 +10275,9 @@ var require_bootstrap = __commonJS({
|
|
|
9687
10275
|
impersonationSweep.unref?.();
|
|
9688
10276
|
strapi2.sessionManagerIntervals.impersonationSweep = impersonationSweep;
|
|
9689
10277
|
strapi2.plugin("magic-sessionmanager").service("impersonation").checkHandoffSetup();
|
|
9690
|
-
mountPreLoginGeoGuard({ strapi: strapi2, log });
|
|
9691
|
-
mountFailedLoginLockout({ strapi: strapi2, log });
|
|
10278
|
+
const geoCheck = mountPreLoginGeoGuard({ strapi: strapi2, log });
|
|
10279
|
+
const lockoutGuard = mountFailedLoginLockout({ strapi: strapi2, log });
|
|
10280
|
+
connectAuthControllerGuard({ strapi: strapi2, geoCheck, lockoutGuard });
|
|
9692
10281
|
mountLogoutRoute({ strapi: strapi2, log, sessionService });
|
|
9693
10282
|
mountLoginInterceptor({ strapi: strapi2, log, sessionService });
|
|
9694
10283
|
mountRefreshTokenInterceptor({ strapi: strapi2, log, sessionService });
|
|
@@ -9746,6 +10335,28 @@ var require_bootstrap = __commonJS({
|
|
|
9746
10335
|
log.debug("[CONFIG] Encryption key consistency check skipped:", err?.name || "Error");
|
|
9747
10336
|
}
|
|
9748
10337
|
}
|
|
10338
|
+
async function warnShortEncryptionKey(strapi2, log) {
|
|
10339
|
+
if (!isEncryptionKeyShort()) return false;
|
|
10340
|
+
log.error(
|
|
10341
|
+
`[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).`
|
|
10342
|
+
);
|
|
10343
|
+
try {
|
|
10344
|
+
const coordinator = getCoordinator(strapi2);
|
|
10345
|
+
const check = getEncryptionKeyCheck();
|
|
10346
|
+
const marker = "instance:weak-encryption-key-recorded";
|
|
10347
|
+
if (await coordinator.cacheGet(marker) === check) return true;
|
|
10348
|
+
const recorded = strapi2.plugin("magic-sessionmanager").service("security-log").record({
|
|
10349
|
+
event: SECURITY_EVENTS.CONFIG_WEAK_KEY,
|
|
10350
|
+
actorType: "system",
|
|
10351
|
+
targetType: "config",
|
|
10352
|
+
meta: { minBytes: MIN_KEY_BYTES }
|
|
10353
|
+
});
|
|
10354
|
+
if (recorded !== false) await coordinator.cacheSet(marker, check, Infinity);
|
|
10355
|
+
} catch (err) {
|
|
10356
|
+
log.debug("[SECURITY] Weak key event not recorded:", err?.name || "Error");
|
|
10357
|
+
}
|
|
10358
|
+
return true;
|
|
10359
|
+
}
|
|
9749
10360
|
function mountPreLoginGeoGuard({ strapi: strapi2, log }) {
|
|
9750
10361
|
const shouldRecordRefusal = createRefusalDedup();
|
|
9751
10362
|
const shouldRecordUnknownAccount = createRefusalDedup({ windowMs: 5 * 60 * 1e3 });
|
|
@@ -9768,19 +10379,14 @@ var require_bootstrap = __commonJS({
|
|
|
9768
10379
|
meta: { reason }
|
|
9769
10380
|
});
|
|
9770
10381
|
};
|
|
9771
|
-
|
|
9772
|
-
if (
|
|
9773
|
-
|
|
9774
|
-
}
|
|
10382
|
+
const check = async (ctx) => {
|
|
10383
|
+
if (ctx.state?.__magicSessionGeoChecked) return null;
|
|
10384
|
+
if (ctx.state) ctx.state.__magicSessionGeoChecked = true;
|
|
9775
10385
|
const settings = await getRequestSettings(strapi2, ctx);
|
|
9776
10386
|
const needsGeoCheck = settings.blockSuspiciousSessions || settings.enableGeofencing || settings.enableGeolocation;
|
|
9777
|
-
if (!needsGeoCheck)
|
|
9778
|
-
return next();
|
|
9779
|
-
}
|
|
10387
|
+
if (!needsGeoCheck) return null;
|
|
9780
10388
|
const ip = getClientIp(ctx);
|
|
9781
|
-
if (!ip || ip === "unknown")
|
|
9782
|
-
return next();
|
|
9783
|
-
}
|
|
10389
|
+
if (!ip || ip === "unknown") return null;
|
|
9784
10390
|
try {
|
|
9785
10391
|
const geolocationService = strapi2.plugin("magic-sessionmanager").service("geolocation");
|
|
9786
10392
|
const geoData = await geolocationService.getIpInfo(ip);
|
|
@@ -9788,16 +10394,11 @@ var require_bootstrap = __commonJS({
|
|
|
9788
10394
|
if (decision.blocked) {
|
|
9789
10395
|
log.warn(`[PRE-BLOCKED] Login rejected (${decision.reason})`);
|
|
9790
10396
|
await recordRefusal(ctx, settings, ip, decision.reason);
|
|
9791
|
-
ctx.status = 403;
|
|
9792
|
-
ctx.body = {
|
|
9793
|
-
error: {
|
|
9794
|
-
status: 403,
|
|
9795
|
-
name: "ForbiddenError",
|
|
9796
|
-
message: decision.reason?.startsWith("geo_lookup_unavailable:") ? "Login temporarily unavailable. Please contact support." : "Login blocked for security reasons. Please contact support."
|
|
9797
|
-
}
|
|
9798
|
-
};
|
|
9799
10397
|
ctx.state.__magicSessionGeoData = geoData;
|
|
9800
|
-
return
|
|
10398
|
+
return {
|
|
10399
|
+
status: 403,
|
|
10400
|
+
message: decision.reason?.startsWith("geo_lookup_unavailable:") ? "Login temporarily unavailable. Please contact support." : "Login blocked for security reasons. Please contact support."
|
|
10401
|
+
};
|
|
9801
10402
|
}
|
|
9802
10403
|
if (decision.status === "ok") {
|
|
9803
10404
|
ctx.state.__magicSessionGeoData = geoData;
|
|
@@ -9807,21 +10408,31 @@ var require_bootstrap = __commonJS({
|
|
|
9807
10408
|
if (failureDecision.blocked) {
|
|
9808
10409
|
log.warn("[PRE-BLOCKED] Login rejected because GeoIP lookup failed");
|
|
9809
10410
|
await recordRefusal(ctx, settings, ip, "geo_lookup_unavailable:error");
|
|
9810
|
-
|
|
9811
|
-
|
|
9812
|
-
|
|
9813
|
-
status: 403,
|
|
9814
|
-
name: "ForbiddenError",
|
|
9815
|
-
message: "Login temporarily unavailable. Please contact support."
|
|
9816
|
-
}
|
|
10411
|
+
return {
|
|
10412
|
+
status: 403,
|
|
10413
|
+
message: "Login temporarily unavailable. Please contact support."
|
|
9817
10414
|
};
|
|
9818
|
-
return;
|
|
9819
10415
|
}
|
|
9820
10416
|
log.debug("Pre-login geo guard error (allowing by configured policy):", err?.name || "Error");
|
|
9821
10417
|
}
|
|
10418
|
+
return null;
|
|
10419
|
+
};
|
|
10420
|
+
strapi2.server.use(async (ctx, next) => {
|
|
10421
|
+
if (!shouldRunPreAuthGeoGuard(apiPathOf(strapi2, ctx), ctx.method)) {
|
|
10422
|
+
return next();
|
|
10423
|
+
}
|
|
10424
|
+
const refusal = await check(ctx);
|
|
10425
|
+
if (refusal) {
|
|
10426
|
+
ctx.status = refusal.status;
|
|
10427
|
+
ctx.body = {
|
|
10428
|
+
error: { status: refusal.status, name: "ForbiddenError", message: refusal.message }
|
|
10429
|
+
};
|
|
10430
|
+
return;
|
|
10431
|
+
}
|
|
9822
10432
|
await next();
|
|
9823
10433
|
});
|
|
9824
10434
|
log.info("[SUCCESS] Pre-login geo guard mounted");
|
|
10435
|
+
return check;
|
|
9825
10436
|
}
|
|
9826
10437
|
function mountLogoutRoute({ strapi: strapi2, log, sessionService }) {
|
|
9827
10438
|
const logoutPath = `${normalizeApiPrefix(strapi2.config.get("api.rest.prefix", "/api"))}/auth/logout`;
|
|
@@ -10007,16 +10618,16 @@ var require_bootstrap = __commonJS({
|
|
|
10007
10618
|
}
|
|
10008
10619
|
function mountFailedLoginLockout({ strapi: strapi2, log }) {
|
|
10009
10620
|
const lockout = createLoginLockout(getCoordinator(strapi2));
|
|
10621
|
+
const coordinator = getCoordinator(strapi2);
|
|
10010
10622
|
const shouldRecordRefusal = createRefusalDedup();
|
|
10011
10623
|
const shouldRecordUnknownAccount = createRefusalDedup({ windowMs: 5 * 60 * 1e3 });
|
|
10012
10624
|
const underAddressCap = createAddressCap();
|
|
10013
10625
|
const unknownAccountKey = (ip) => `unknown|${anonymizeIp(normalizeIp(ip || "")) || "none"}`;
|
|
10014
|
-
|
|
10015
|
-
if (!isFailedLoginTrackedPath(apiPathOf(strapi2, ctx), ctx.method)) return next();
|
|
10626
|
+
const guard = async (ctx, run, classify, refuse) => {
|
|
10016
10627
|
const settings = await getRequestSettings(strapi2, ctx);
|
|
10017
10628
|
const policy = resolveLockoutPolicy(settings);
|
|
10018
10629
|
const accountPossible = policy.accountMax > 0 || policy.accountMaxByRole;
|
|
10019
|
-
if (policy.ipMax <= 0 && !accountPossible && !policy.record) return
|
|
10630
|
+
if (policy.ipMax <= 0 && !accountPossible && !policy.record) return run();
|
|
10020
10631
|
const rawIp = getClientIp(ctx);
|
|
10021
10632
|
const ip = rawIp && rawIp !== "unknown" ? rawIp : null;
|
|
10022
10633
|
const identifier = readSignInIdentifier(ctx);
|
|
@@ -10037,6 +10648,15 @@ var require_bootstrap = __commonJS({
|
|
|
10037
10648
|
};
|
|
10038
10649
|
if (policy.accountMaxByRole) await loadAccount();
|
|
10039
10650
|
const accountMax = accountThresholdFor(settings, account?.role || null);
|
|
10651
|
+
let accountExempt = false;
|
|
10652
|
+
const deviceId = requestDeviceId(ctx);
|
|
10653
|
+
if (accountMax > 0 && identifier && deviceId) {
|
|
10654
|
+
await loadAccount();
|
|
10655
|
+
accountExempt = await isRecognizedDevice(strapi2, account?.documentId || null, {
|
|
10656
|
+
userAgent,
|
|
10657
|
+
deviceId
|
|
10658
|
+
}).catch(() => false);
|
|
10659
|
+
}
|
|
10040
10660
|
const event = (name, meta) => {
|
|
10041
10661
|
const signInFamily = USER_SIGN_IN_EVENTS.includes(name);
|
|
10042
10662
|
if (signInFamily && !policy.record) return false;
|
|
@@ -10064,7 +10684,7 @@ var require_bootstrap = __commonJS({
|
|
|
10064
10684
|
};
|
|
10065
10685
|
let decision;
|
|
10066
10686
|
try {
|
|
10067
|
-
decision = await lockout.reserve({ ip, identifier, policy, accountMax });
|
|
10687
|
+
decision = await lockout.reserve({ ip, identifier, policy, accountMax, accountExempt });
|
|
10068
10688
|
} catch (err) {
|
|
10069
10689
|
log.debug("[LOCKOUT] Counter update failed:", err?.name || "Error");
|
|
10070
10690
|
decision = {
|
|
@@ -10075,47 +10695,38 @@ var require_bootstrap = __commonJS({
|
|
|
10075
10695
|
};
|
|
10076
10696
|
}
|
|
10077
10697
|
if (decision.outcome === "locked") {
|
|
10078
|
-
ctx.set("Retry-After", String(decision.retryAfter));
|
|
10079
10698
|
log.warn(
|
|
10080
10699
|
`[LOCKOUT] Rejected sign-in from a locked client (${decision.retryAfter}s remaining)`
|
|
10081
10700
|
);
|
|
10082
10701
|
if (policy.record) await loadAccount();
|
|
10083
10702
|
refusedOnce("lockout", { lock: decision.lockedKind });
|
|
10084
|
-
ctx
|
|
10085
|
-
|
|
10086
|
-
|
|
10087
|
-
|
|
10088
|
-
|
|
10089
|
-
|
|
10090
|
-
details: { retryAfter: decision.retryAfter }
|
|
10091
|
-
}
|
|
10092
|
-
};
|
|
10093
|
-
return;
|
|
10703
|
+
return refuse(ctx, {
|
|
10704
|
+
status: 429,
|
|
10705
|
+
name: "TooManyRequestsError",
|
|
10706
|
+
message: "Too many failed login attempts. Please try again later.",
|
|
10707
|
+
retryAfter: decision.retryAfter
|
|
10708
|
+
});
|
|
10094
10709
|
}
|
|
10095
10710
|
if (decision.outcome === "busy") {
|
|
10096
10711
|
if (policy.record) await loadAccount();
|
|
10097
10712
|
refusedOnce("too-many-attempts", {});
|
|
10098
|
-
ctx
|
|
10099
|
-
|
|
10100
|
-
|
|
10101
|
-
|
|
10102
|
-
|
|
10103
|
-
|
|
10104
|
-
message: "Too many login attempts at once. Please try again.",
|
|
10105
|
-
details: { retryAfter: 1 }
|
|
10106
|
-
}
|
|
10107
|
-
};
|
|
10108
|
-
return;
|
|
10713
|
+
return refuse(ctx, {
|
|
10714
|
+
status: 429,
|
|
10715
|
+
name: "TooManyRequestsError",
|
|
10716
|
+
message: "Too many login attempts at once. Please try again.",
|
|
10717
|
+
retryAfter: 1
|
|
10718
|
+
});
|
|
10109
10719
|
}
|
|
10110
10720
|
let thrown = null;
|
|
10721
|
+
let returned;
|
|
10111
10722
|
try {
|
|
10112
|
-
await
|
|
10723
|
+
returned = await run();
|
|
10113
10724
|
} catch (err) {
|
|
10114
10725
|
thrown = err;
|
|
10115
10726
|
}
|
|
10116
|
-
const
|
|
10117
|
-
const result = !thrown && status === 200 && ctx.body && ctx.body.jwt ? "success" : status >= 400 && status < 500 && status !== 429 ? "failure" : "neutral";
|
|
10727
|
+
const result = classify(thrown, ctx);
|
|
10118
10728
|
if (result === "failure") {
|
|
10729
|
+
const status = thrown ? statusOfThrownError(thrown) : ctx.status;
|
|
10119
10730
|
if (policy.record || decision.reservation.accountKey) await loadAccount();
|
|
10120
10731
|
if (account) {
|
|
10121
10732
|
event(SECURITY_EVENTS.USER_SIGN_IN_FAILED, { status });
|
|
@@ -10143,21 +10754,93 @@ var require_bootstrap = __commonJS({
|
|
|
10143
10754
|
minutes
|
|
10144
10755
|
});
|
|
10145
10756
|
if (lock.kind === "account" && policy.notifyUser && account?.email) {
|
|
10146
|
-
const
|
|
10147
|
-
|
|
10148
|
-
|
|
10149
|
-
|
|
10150
|
-
|
|
10151
|
-
|
|
10152
|
-
|
|
10757
|
+
const mailWindowMs = Math.max(policy.windowMs, policy.durationMs);
|
|
10758
|
+
const sent = await coordinator.hit(hashedKey("lm", lock.id), mailWindowMs).then((entry) => Number(entry?.hits) || 0).catch(() => 1);
|
|
10759
|
+
if (sent === 1) {
|
|
10760
|
+
const notifications = strapi2.plugin("magic-sessionmanager").service("notifications");
|
|
10761
|
+
notifications.sendAccountLockedEmail({
|
|
10762
|
+
user: account,
|
|
10763
|
+
minutes,
|
|
10764
|
+
until: lock.until
|
|
10765
|
+
}).catch(() => {
|
|
10766
|
+
});
|
|
10767
|
+
}
|
|
10153
10768
|
}
|
|
10154
10769
|
}
|
|
10155
10770
|
} catch (err) {
|
|
10156
10771
|
log.debug("[LOCKOUT] Counter update failed:", err?.name || "Error");
|
|
10157
10772
|
}
|
|
10158
|
-
if (thrown) throw thrown;
|
|
10159
|
-
|
|
10160
|
-
|
|
10773
|
+
if (thrown) throw thrown;
|
|
10774
|
+
return returned;
|
|
10775
|
+
};
|
|
10776
|
+
strapi2.server.use(async (ctx, next) => {
|
|
10777
|
+
if (!isFailedLoginTrackedPath(apiPathOf(strapi2, ctx), ctx.method)) return next();
|
|
10778
|
+
return guard(ctx, next, classifyRouteOutcome, refuseOverHttp);
|
|
10779
|
+
});
|
|
10780
|
+
log.info("[SUCCESS] Failed-login lockout middleware mounted");
|
|
10781
|
+
return guard;
|
|
10782
|
+
}
|
|
10783
|
+
function classifyRouteOutcome(thrown, ctx) {
|
|
10784
|
+
const status = thrown ? statusOfThrownError(thrown) : ctx.status;
|
|
10785
|
+
if (!thrown && status === 200 && ctx.body && ctx.body.jwt) return "success";
|
|
10786
|
+
return status === 400 || status === 401 ? "failure" : "neutral";
|
|
10787
|
+
}
|
|
10788
|
+
function refuseOverHttp(ctx, refusal) {
|
|
10789
|
+
ctx.set("Retry-After", String(refusal.retryAfter));
|
|
10790
|
+
ctx.status = refusal.status;
|
|
10791
|
+
ctx.body = {
|
|
10792
|
+
error: {
|
|
10793
|
+
status: refusal.status,
|
|
10794
|
+
name: refusal.name,
|
|
10795
|
+
message: refusal.message,
|
|
10796
|
+
details: { retryAfter: refusal.retryAfter }
|
|
10797
|
+
}
|
|
10798
|
+
};
|
|
10799
|
+
}
|
|
10800
|
+
function isGraphqlRequest(strapi2, ctx) {
|
|
10801
|
+
let endpoint = "/graphql";
|
|
10802
|
+
try {
|
|
10803
|
+
endpoint = strapi2.plugin("graphql")?.config?.("endpoint") || endpoint;
|
|
10804
|
+
} catch {
|
|
10805
|
+
}
|
|
10806
|
+
const original = String(ctx.originalUrl || ctx.url || "").split("?")[0];
|
|
10807
|
+
return normalizePath(original) === normalizePath(endpoint);
|
|
10808
|
+
}
|
|
10809
|
+
function createAuthControllerHandlers({ strapi: strapi2, geoCheck, lockoutGuard }) {
|
|
10810
|
+
const refuse = (ctx, refusal) => {
|
|
10811
|
+
if (refusal.retryAfter) ctx.set("Retry-After", String(refusal.retryAfter));
|
|
10812
|
+
if (isGraphqlRequest(strapi2, ctx)) {
|
|
10813
|
+
const details = refusal.retryAfter ? { retryAfter: refusal.retryAfter } : {};
|
|
10814
|
+
throw refusal.status === 429 ? new utilsErrors.RateLimitError(refusal.message, details) : new utilsErrors.ForbiddenError(refusal.message, details);
|
|
10815
|
+
}
|
|
10816
|
+
if (refusal.status === 429) return refuseOverHttp(ctx, refusal);
|
|
10817
|
+
ctx.status = refusal.status;
|
|
10818
|
+
ctx.body = {
|
|
10819
|
+
error: { status: refusal.status, name: refusal.name, message: refusal.message }
|
|
10820
|
+
};
|
|
10821
|
+
return void 0;
|
|
10822
|
+
};
|
|
10823
|
+
const geoFirst = async (ctx) => {
|
|
10824
|
+
const refusal = await geoCheck(ctx);
|
|
10825
|
+
if (!refusal) return false;
|
|
10826
|
+
refuse(ctx, { ...refusal, name: "ForbiddenError", retryAfter: 0 });
|
|
10827
|
+
return true;
|
|
10828
|
+
};
|
|
10829
|
+
return {
|
|
10830
|
+
async callback(ctx, run) {
|
|
10831
|
+
if (await geoFirst(ctx)) return void 0;
|
|
10832
|
+
const provider = ctx.params?.provider || "local";
|
|
10833
|
+
if (provider !== "local") return run();
|
|
10834
|
+
return lockoutGuard(ctx, run, classifyCallbackOutcome, refuse);
|
|
10835
|
+
},
|
|
10836
|
+
async newSession(ctx, run) {
|
|
10837
|
+
if (await geoFirst(ctx)) return void 0;
|
|
10838
|
+
return run();
|
|
10839
|
+
}
|
|
10840
|
+
};
|
|
10841
|
+
}
|
|
10842
|
+
function connectAuthControllerGuard(deps) {
|
|
10843
|
+
setAuthControllerHandlers(deps.strapi, createAuthControllerHandlers(deps));
|
|
10161
10844
|
}
|
|
10162
10845
|
function statusOfThrownError(err) {
|
|
10163
10846
|
const status = Number(err?.status ?? err?.statusCode);
|
|
@@ -11367,6 +12050,8 @@ var require_bootstrap = __commonJS({
|
|
|
11367
12050
|
}
|
|
11368
12051
|
}
|
|
11369
12052
|
module.exports.__private = {
|
|
12053
|
+
warnShortEncryptionKey,
|
|
12054
|
+
createAuthControllerHandlers,
|
|
11370
12055
|
registerSessionAwareAuthStrategy,
|
|
11371
12056
|
mountFailedLoginLockout,
|
|
11372
12057
|
ensureSessionLookupIndexes,
|
|
@@ -11386,6 +12071,7 @@ var require_destroy = __commonJS({
|
|
|
11386
12071
|
"server/src/destroy.js"(exports, module) {
|
|
11387
12072
|
"use strict";
|
|
11388
12073
|
var { createLogger } = require_logger();
|
|
12074
|
+
var { uninstallAuthControllerGuard } = require_auth_controller_guard();
|
|
11389
12075
|
module.exports = async ({ strapi: strapi2 }) => {
|
|
11390
12076
|
const log = createLogger(strapi2);
|
|
11391
12077
|
if (strapi2.sessionManagerIntervals) {
|
|
@@ -11419,6 +12105,11 @@ var require_destroy = __commonJS({
|
|
|
11419
12105
|
}
|
|
11420
12106
|
strapi2.sessionManagerAdminActivityUninstall = null;
|
|
11421
12107
|
}
|
|
12108
|
+
try {
|
|
12109
|
+
uninstallAuthControllerGuard(strapi2);
|
|
12110
|
+
} catch (err) {
|
|
12111
|
+
log.warn("Failed to restore the Users & Permissions auth controller:", err?.name || "Error");
|
|
12112
|
+
}
|
|
11422
12113
|
try {
|
|
11423
12114
|
strapi2.plugin("magic-sessionmanager")?.service("webhooks")?.stop?.();
|
|
11424
12115
|
} catch (err) {
|
|
@@ -14892,7 +15583,13 @@ var require_settings_access = __commonJS({
|
|
|
14892
15583
|
// Signed webhook, event selection, impossible travel and shortened IPs.
|
|
14893
15584
|
...PROTECTED_DETECTION_KEYS,
|
|
14894
15585
|
// Impersonation switch (4.20): whether admins can act as app users.
|
|
14895
|
-
...IMPERSONATION_KEYS
|
|
15586
|
+
...IMPERSONATION_KEYS,
|
|
15587
|
+
// Security review 2 (4.22.1): which proxies may name the client address
|
|
15588
|
+
// (H2), the IP lockout threshold (H2) and the alert email texts, which go
|
|
15589
|
+
// to app users from the site's own address (hardening 6).
|
|
15590
|
+
"trustedProxies",
|
|
15591
|
+
"maxFailedLogins",
|
|
15592
|
+
"emailTemplates"
|
|
14896
15593
|
]);
|
|
14897
15594
|
var WEBHOOK_SECRETS = Object.freeze([
|
|
14898
15595
|
{ key: "discordWebhookUrl", has: "hasDiscordWebhook", hint: "discordWebhookHint" },
|
|
@@ -15002,6 +15699,7 @@ var require_settings = __commonJS({
|
|
|
15002
15699
|
validateImpersonationSettings
|
|
15003
15700
|
} = require_impersonation_rules();
|
|
15004
15701
|
var { encryptToken } = require_encryption();
|
|
15702
|
+
var { normalizeTrustedProxies, validateTrustedProxies } = require_trusted_proxies();
|
|
15005
15703
|
var WEBHOOK_SECRET_PATTERN = /^[\x21-\x7e]{32,256}$/;
|
|
15006
15704
|
var path = __require("node:path");
|
|
15007
15705
|
var ALLOWED_WEBHOOK_DOMAINS = {
|
|
@@ -15177,7 +15875,9 @@ var require_settings = __commonJS({
|
|
|
15177
15875
|
discordWebhookUrl: "",
|
|
15178
15876
|
slackWebhookUrl: "",
|
|
15179
15877
|
strictSessionEnforcement: false,
|
|
15180
|
-
|
|
15878
|
+
// A list of proxy addresses or CIDR ranges since 4.22.1; the legacy
|
|
15879
|
+
// boolean is read as an empty list (Strapi's server.proxy settings decide).
|
|
15880
|
+
trustedProxies: [],
|
|
15181
15881
|
emailTemplates: DEFAULT_EMAIL_TEMPLATES,
|
|
15182
15882
|
...SECURITY_LOG_DEFAULTS,
|
|
15183
15883
|
...POLICY_DEFAULTS,
|
|
@@ -15198,7 +15898,8 @@ var require_settings = __commonJS({
|
|
|
15198
15898
|
...DEFAULT_EMAIL_TEMPLATES,
|
|
15199
15899
|
...storedTemplates
|
|
15200
15900
|
},
|
|
15201
|
-
geoIpDatabasePath: getSafeGeoIpFilename(safeStored.geoIpDatabasePath)
|
|
15901
|
+
geoIpDatabasePath: getSafeGeoIpFilename(safeStored.geoIpDatabasePath),
|
|
15902
|
+
trustedProxies: normalizeTrustedProxies(safeStored.trustedProxies)
|
|
15202
15903
|
};
|
|
15203
15904
|
}
|
|
15204
15905
|
var INTEGER_SETTING_RANGES = {
|
|
@@ -15223,8 +15924,7 @@ var require_settings = __commonJS({
|
|
|
15223
15924
|
"alertOnNewLocation",
|
|
15224
15925
|
"alertOnVpnProxy",
|
|
15225
15926
|
"enableWebhooks",
|
|
15226
|
-
"strictSessionEnforcement"
|
|
15227
|
-
"trustedProxies"
|
|
15927
|
+
"strictSessionEnforcement"
|
|
15228
15928
|
];
|
|
15229
15929
|
var GEO_IP_PROVIDER_VALUES = ["auto", "local-mmdb", "ipapi", "disabled"];
|
|
15230
15930
|
var GEO_LOOKUP_FAILURE_MODE_VALUES = ["auto", "allow", "block"];
|
|
@@ -15298,6 +15998,11 @@ var require_settings = __commonJS({
|
|
|
15298
15998
|
next[key] = body[key];
|
|
15299
15999
|
}
|
|
15300
16000
|
}
|
|
16001
|
+
if (has("trustedProxies")) {
|
|
16002
|
+
const proxies = validateTrustedProxies(body.trustedProxies);
|
|
16003
|
+
if (proxies.error) errors.push(proxies.error);
|
|
16004
|
+
else next.trustedProxies = proxies.value;
|
|
16005
|
+
}
|
|
15301
16006
|
for (const key of ["allowedCountries", "blockedCountries"]) {
|
|
15302
16007
|
if (!has(key)) continue;
|
|
15303
16008
|
const list = body[key];
|
|
@@ -15416,6 +16121,15 @@ var require_settings = __commonJS({
|
|
|
15416
16121
|
next.genericWebhookSecret = encryptToken(secret);
|
|
15417
16122
|
}
|
|
15418
16123
|
}
|
|
16124
|
+
const urlChanges = typeof next.genericWebhookUrl === "string" && next.genericWebhookUrl !== "" && next.genericWebhookUrl !== (current.genericWebhookUrl || "");
|
|
16125
|
+
const secretStored = typeof current.genericWebhookSecret === "string" && current.genericWebhookSecret !== "";
|
|
16126
|
+
const secretGiven = typeof next.genericWebhookSecret === "string" && next.genericWebhookSecret !== "";
|
|
16127
|
+
if (urlChanges && secretStored && !secretGiven) {
|
|
16128
|
+
errors.push({
|
|
16129
|
+
path: ["genericWebhookSecret"],
|
|
16130
|
+
message: "Enter the webhook secret again when you change the webhook URL"
|
|
16131
|
+
});
|
|
16132
|
+
}
|
|
15419
16133
|
if (errors.length > 0) return { errors };
|
|
15420
16134
|
const settings = {};
|
|
15421
16135
|
for (const key of Object.keys(DEFAULT_SETTINGS)) {
|
|
@@ -17128,10 +17842,43 @@ var require_lockouts = __commonJS({
|
|
|
17128
17842
|
}
|
|
17129
17843
|
});
|
|
17130
17844
|
|
|
17845
|
+
// server/src/utils/user-export.js
|
|
17846
|
+
var require_user_export = __commonJS({
|
|
17847
|
+
"server/src/utils/user-export.js"(exports, module) {
|
|
17848
|
+
"use strict";
|
|
17849
|
+
var { SECURITY_EVENTS } = require_security_log_model();
|
|
17850
|
+
var IMPERSONATION_TEXT = Object.freeze({
|
|
17851
|
+
[SECURITY_EVENTS.IMPERSONATION_STARTED]: "An administrator opened your account",
|
|
17852
|
+
[SECURITY_EVENTS.IMPERSONATION_ENDED]: "The administrator access to your account ended",
|
|
17853
|
+
[SECURITY_EVENTS.IMPERSONATION_EXPIRED]: "The administrator access to your account ended",
|
|
17854
|
+
[SECURITY_EVENTS.IMPERSONATION_REFUSED]: "An administrator access to your account was refused"
|
|
17855
|
+
});
|
|
17856
|
+
function toUserExportEvent(row) {
|
|
17857
|
+
const { id: _id, ...rest } = row || {};
|
|
17858
|
+
const text = IMPERSONATION_TEXT[rest.event];
|
|
17859
|
+
if (!text) return rest;
|
|
17860
|
+
const minutes = Number(rest.meta?.durationMinutes);
|
|
17861
|
+
return {
|
|
17862
|
+
event: rest.event,
|
|
17863
|
+
createdAt: rest.createdAt,
|
|
17864
|
+
ip: null,
|
|
17865
|
+
userAgent: null,
|
|
17866
|
+
geo: null,
|
|
17867
|
+
meta: {
|
|
17868
|
+
description: text,
|
|
17869
|
+
...Number.isInteger(minutes) && minutes > 0 ? { durationMinutes: minutes } : {}
|
|
17870
|
+
}
|
|
17871
|
+
};
|
|
17872
|
+
}
|
|
17873
|
+
module.exports = { IMPERSONATION_TEXT, toUserExportEvent };
|
|
17874
|
+
}
|
|
17875
|
+
});
|
|
17876
|
+
|
|
17131
17877
|
// server/src/controllers/self-service.js
|
|
17132
17878
|
var require_self_service = __commonJS({
|
|
17133
17879
|
"server/src/controllers/self-service.js"(exports, module) {
|
|
17134
17880
|
"use strict";
|
|
17881
|
+
var crypto = __require("node:crypto");
|
|
17135
17882
|
var { getCoordinator } = require_coordination();
|
|
17136
17883
|
var { consumeNotMeToken, readNotMeToken } = require_not_me_link();
|
|
17137
17884
|
var { recordUserEvent } = require_sign_in_policies();
|
|
@@ -17139,6 +17886,7 @@ var require_self_service = __commonJS({
|
|
|
17139
17886
|
var { SECURITY_EVENTS } = require_security_log_model();
|
|
17140
17887
|
var { sendServerError } = require_http_errors();
|
|
17141
17888
|
var { createLogger } = require_logger();
|
|
17889
|
+
var { toUserExportEvent } = require_user_export();
|
|
17142
17890
|
var SESSION_UID = "plugin::magic-sessionmanager.session";
|
|
17143
17891
|
var EVENT_UID = "plugin::magic-sessionmanager.security-event";
|
|
17144
17892
|
var USER_UID = "plugin::users-permissions.user";
|
|
@@ -17205,19 +17953,21 @@ var require_self_service = __commonJS({
|
|
|
17205
17953
|
return "en";
|
|
17206
17954
|
}
|
|
17207
17955
|
var escapeHtml = (value) => String(value ?? "").replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """).replace(/'/g, "'");
|
|
17208
|
-
function
|
|
17956
|
+
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);})();`;
|
|
17957
|
+
var FRAGMENT_SCRIPT_HASH = `sha256-${crypto.createHash("sha256").update(FRAGMENT_SCRIPT).digest("base64")}`;
|
|
17958
|
+
function sendPage(ctx, status, lang, title, body, { withScript = false } = {}) {
|
|
17209
17959
|
ctx.status = status;
|
|
17210
17960
|
ctx.set("Content-Type", "text/html; charset=utf-8");
|
|
17211
17961
|
ctx.set(
|
|
17212
17962
|
"Content-Security-Policy",
|
|
17213
|
-
|
|
17963
|
+
`default-src 'none'; style-src 'unsafe-inline'; ${withScript ? `script-src '${FRAGMENT_SCRIPT_HASH}'; ` : ""}form-action 'self'; frame-ancestors 'none'; base-uri 'none'`
|
|
17214
17964
|
);
|
|
17215
17965
|
ctx.set("Referrer-Policy", "no-referrer");
|
|
17216
17966
|
ctx.set("Cache-Control", "no-store");
|
|
17217
17967
|
ctx.set("X-Robots-Tag", "noindex");
|
|
17218
17968
|
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>
|
|
17219
17969
|
<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>
|
|
17220
|
-
<body><main><h1>${escapeHtml(title)}</h1>${body}</main
|
|
17970
|
+
<body><main><h1>${escapeHtml(title)}</h1>${body}</main>${withScript ? `<script>${FRAGMENT_SCRIPT}</script>` : ""}</body></html>`;
|
|
17221
17971
|
}
|
|
17222
17972
|
module.exports = ({ strapi: strapi2 }) => {
|
|
17223
17973
|
const log = createLogger(strapi2);
|
|
@@ -17225,17 +17975,20 @@ var require_self_service = __commonJS({
|
|
|
17225
17975
|
/**
|
|
17226
17976
|
* Confirmation page of the "This wasn't me" link. Uses nothing.
|
|
17227
17977
|
*
|
|
17228
|
-
* @route GET /api/magic-sessionmanager/not-me
|
|
17978
|
+
* @route GET /api/magic-sessionmanager/not-me (token in `#token=`; `?token=` before 4.22.1)
|
|
17229
17979
|
* @auth none (public on purpose: the link is opened from an email; the
|
|
17230
17980
|
* signed token is checked, and nothing changes until the POST)
|
|
17231
17981
|
* @param {any} ctx Koa context.
|
|
17232
|
-
* @returns {Promise<void>} 200 page with two buttons, or 410 when
|
|
17982
|
+
* @returns {Promise<void>} 200 page with two buttons, or 410 when a `?token=` link is
|
|
17983
|
+
* invalid. Without `?token=` the page is served with the hashed script that copies the
|
|
17984
|
+
* fragment token into the forms; the POST checks it.
|
|
17233
17985
|
*/
|
|
17234
17986
|
async notMePage(ctx) {
|
|
17235
17987
|
const lang = pageLanguage(ctx);
|
|
17236
17988
|
const text = PAGE_TEXT[lang];
|
|
17237
|
-
const
|
|
17238
|
-
|
|
17989
|
+
const hasQueryToken = typeof ctx.query?.token === "string" && ctx.query.token !== "";
|
|
17990
|
+
const token = hasQueryToken ? ctx.query.token : "";
|
|
17991
|
+
if (hasQueryToken && !readNotMeToken(token)) {
|
|
17239
17992
|
return sendPage(ctx, 410, lang, text.title, `<p>${escapeHtml(text.invalid)}</p>`);
|
|
17240
17993
|
}
|
|
17241
17994
|
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>`;
|
|
@@ -17244,7 +17997,8 @@ var require_self_service = __commonJS({
|
|
|
17244
17997
|
200,
|
|
17245
17998
|
lang,
|
|
17246
17999
|
text.title,
|
|
17247
|
-
`<p>${escapeHtml(text.body)}</p>${form("session", text.one, "")}${form("all", text.all, "secondary")}
|
|
18000
|
+
`<p>${escapeHtml(text.body)}</p>${form("session", text.one, "")}${form("all", text.all, "secondary")}`,
|
|
18001
|
+
{ withScript: !hasQueryToken }
|
|
17248
18002
|
);
|
|
17249
18003
|
},
|
|
17250
18004
|
/**
|
|
@@ -17397,7 +18151,9 @@ var require_self_service = __commonJS({
|
|
|
17397
18151
|
exportedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
17398
18152
|
user: user ? { documentId: user.documentId, username: user.username, email: user.email } : { documentId: userDocumentId },
|
|
17399
18153
|
sessions,
|
|
17400
|
-
|
|
18154
|
+
// Impersonation events show a fixed text and the duration only
|
|
18155
|
+
// (security review 2, L3): the admin's reason stays internal.
|
|
18156
|
+
securityEvents: (Array.isArray(events) ? events : []).map(toUserExportEvent)
|
|
17401
18157
|
};
|
|
17402
18158
|
} catch (err) {
|
|
17403
18159
|
log.error("[my-data] Export failed:", err?.name || "Error");
|
|
@@ -17957,7 +18713,8 @@ var require_impersonation = __commonJS({
|
|
|
17957
18713
|
* Caller (with roles), target id and request body.
|
|
17958
18714
|
* @returns {Promise<object>} Impersonation DTO plus the preview.
|
|
17959
18715
|
* @throws {ImpersonationError} 400 invalid body or id; 403 feature off, self, Super Admin
|
|
17960
|
-
* or not a subset of the caller's permissions; 404
|
|
18716
|
+
* (callers with `admin::users.read`) or not a subset of the caller's permissions; 404
|
|
18717
|
+
* unknown admin, or a Super Admin for callers without `admin::users.read`.
|
|
17961
18718
|
* @sideeffect Creates an impersonation row; queues `impersonation.started` or `.refused`.
|
|
17962
18719
|
*/
|
|
17963
18720
|
async previewAdmin({ actor, adminId, body, canReadAdmins }) {
|
|
@@ -17987,6 +18744,15 @@ var require_impersonation = __commonJS({
|
|
|
17987
18744
|
]);
|
|
17988
18745
|
if (!target) throw new ImpersonationError(404, "Admin not found");
|
|
17989
18746
|
const refusal = await previewRefusal(strapi2, caller || actor, target);
|
|
18747
|
+
if (refusal?.reason === "super-admin" && !canReadAdmins) {
|
|
18748
|
+
service.recordRefused({
|
|
18749
|
+
actorId,
|
|
18750
|
+
targetType: "admin",
|
|
18751
|
+
targetId: adminId,
|
|
18752
|
+
reason: "super-admin"
|
|
18753
|
+
});
|
|
18754
|
+
throw new ImpersonationError(404, "Admin not found");
|
|
18755
|
+
}
|
|
17990
18756
|
if (refusal) {
|
|
17991
18757
|
const messages = {
|
|
17992
18758
|
self: "You cannot view yourself as another admin",
|
|
@@ -18396,7 +19162,10 @@ var require_impersonation = __commonJS({
|
|
|
18396
19162
|
};
|
|
18397
19163
|
},
|
|
18398
19164
|
/**
|
|
18399
|
-
* Loads one impersonation for the request guard (
|
|
19165
|
+
* Loads one impersonation for the request guard. Only a finished (or
|
|
19166
|
+
* unknown) impersonation is cached for 5 seconds; an active one is read
|
|
19167
|
+
* on every request, so ending it on one process takes effect on every
|
|
19168
|
+
* other process at once (security review 2, hardening 4).
|
|
18400
19169
|
*
|
|
18401
19170
|
* @param {string} documentId Impersonation id.
|
|
18402
19171
|
* @returns {Promise<{id: string, actorId: string, targetId: string|null, state: string,
|
|
@@ -18416,7 +19185,9 @@ var require_impersonation = __commonJS({
|
|
|
18416
19185
|
state: row.state,
|
|
18417
19186
|
expiresAt: new Date(row.expiresAt).getTime()
|
|
18418
19187
|
} : null;
|
|
18419
|
-
|
|
19188
|
+
if (!value || value.state !== "active") {
|
|
19189
|
+
remember(recordCache, documentId, { value, at: Date.now() });
|
|
19190
|
+
}
|
|
18420
19191
|
return value;
|
|
18421
19192
|
},
|
|
18422
19193
|
/**
|
|
@@ -22953,227 +23724,6 @@ var require_security_log = __commonJS({
|
|
|
22953
23724
|
}
|
|
22954
23725
|
});
|
|
22955
23726
|
|
|
22956
|
-
// server/src/utils/webhook-delivery.js
|
|
22957
|
-
var require_webhook_delivery = __commonJS({
|
|
22958
|
-
"server/src/utils/webhook-delivery.js"(exports, module) {
|
|
22959
|
-
"use strict";
|
|
22960
|
-
var crypto = __require("node:crypto");
|
|
22961
|
-
var dns = __require("node:dns");
|
|
22962
|
-
var https = __require("node:https");
|
|
22963
|
-
var net = __require("node:net");
|
|
22964
|
-
var SIGNATURE_HEADER = "X-Magic-Sessionmanager-Signature";
|
|
22965
|
-
var EVENT_HEADER = "X-Magic-Sessionmanager-Event";
|
|
22966
|
-
var DELIVERY_HEADER = "X-Magic-Sessionmanager-Delivery";
|
|
22967
|
-
var USER_AGENT = "Strapi-Magic-SessionManager-Webhook/2.0";
|
|
22968
|
-
var TIMEOUT_MS = 5e3;
|
|
22969
|
-
var MAX_RESPONSE_BYTES = 64 * 1024;
|
|
22970
|
-
var RETRY_DELAYS_MS = Object.freeze([0, 2e3, 1e4]);
|
|
22971
|
-
var BLOCKED = (() => {
|
|
22972
|
-
const list = new net.BlockList();
|
|
22973
|
-
for (const [address, prefix] of [
|
|
22974
|
-
["0.0.0.0", 8],
|
|
22975
|
-
["10.0.0.0", 8],
|
|
22976
|
-
["100.64.0.0", 10],
|
|
22977
|
-
["127.0.0.0", 8],
|
|
22978
|
-
["169.254.0.0", 16],
|
|
22979
|
-
["172.16.0.0", 12],
|
|
22980
|
-
["192.0.0.0", 24],
|
|
22981
|
-
["192.0.2.0", 24],
|
|
22982
|
-
["192.88.99.0", 24],
|
|
22983
|
-
["192.168.0.0", 16],
|
|
22984
|
-
["198.18.0.0", 15],
|
|
22985
|
-
["198.51.100.0", 24],
|
|
22986
|
-
["203.0.113.0", 24],
|
|
22987
|
-
["224.0.0.0", 4],
|
|
22988
|
-
["240.0.0.0", 4]
|
|
22989
|
-
]) {
|
|
22990
|
-
list.addSubnet(address, prefix, "ipv4");
|
|
22991
|
-
}
|
|
22992
|
-
for (const [address, prefix] of [
|
|
22993
|
-
["::", 128],
|
|
22994
|
-
["::1", 128],
|
|
22995
|
-
// IPv4-mapped addresses (::ffff:0:0/96) are not listed: BlockList
|
|
22996
|
-
// checks them against the IPv4 rules above, and a listed /96 would
|
|
22997
|
-
// match every IPv4 address.
|
|
22998
|
-
["64:ff9b::", 96],
|
|
22999
|
-
["64:ff9b:1::", 48],
|
|
23000
|
-
["100::", 64],
|
|
23001
|
-
["2001::", 23],
|
|
23002
|
-
["2001:db8::", 32],
|
|
23003
|
-
["2002::", 16],
|
|
23004
|
-
["fc00::", 7],
|
|
23005
|
-
["fe80::", 10],
|
|
23006
|
-
["fec0::", 10],
|
|
23007
|
-
["ff00::", 8]
|
|
23008
|
-
]) {
|
|
23009
|
-
list.addSubnet(address, prefix, "ipv6");
|
|
23010
|
-
}
|
|
23011
|
-
return list;
|
|
23012
|
-
})();
|
|
23013
|
-
function isBlockedAddress(address) {
|
|
23014
|
-
let value = String(address || "").trim();
|
|
23015
|
-
if (value.toLowerCase().startsWith("::ffff:") && net.isIPv4(value.slice(7))) {
|
|
23016
|
-
value = value.slice(7);
|
|
23017
|
-
}
|
|
23018
|
-
const version = net.isIP(value);
|
|
23019
|
-
if (version === 0) return true;
|
|
23020
|
-
return BLOCKED.check(value, version === 4 ? "ipv4" : "ipv6");
|
|
23021
|
-
}
|
|
23022
|
-
function signPayload(secret, body, timestamp = Math.floor(Date.now() / 1e3)) {
|
|
23023
|
-
const digest = crypto.createHmac("sha256", secret).update(`${timestamp}.${body}`).digest("hex");
|
|
23024
|
-
return `t=${timestamp},v1=${digest}`;
|
|
23025
|
-
}
|
|
23026
|
-
function verifySignature(secret, body, header, { toleranceSeconds = 300, now = Date.now() } = {}) {
|
|
23027
|
-
const match = /^t=(\d{1,12}),v1=([a-f0-9]{64})$/.exec(String(header || ""));
|
|
23028
|
-
if (!match) return false;
|
|
23029
|
-
const timestamp = Number(match[1]);
|
|
23030
|
-
if (Math.abs(now / 1e3 - timestamp) > toleranceSeconds) return false;
|
|
23031
|
-
const expected = crypto.createHmac("sha256", secret).update(`${timestamp}.${body}`).digest();
|
|
23032
|
-
const given = Buffer.from(match[2], "hex");
|
|
23033
|
-
return given.length === expected.length && crypto.timingSafeEqual(given, expected);
|
|
23034
|
-
}
|
|
23035
|
-
var DeliveryError = class extends Error {
|
|
23036
|
-
/**
|
|
23037
|
-
* @param {string} code Stable code.
|
|
23038
|
-
* @param {boolean} retryable Whether another attempt may succeed.
|
|
23039
|
-
* @param {number|null} [status] HTTP status, when there was one.
|
|
23040
|
-
*/
|
|
23041
|
-
constructor(code, retryable, status = null) {
|
|
23042
|
-
super(code);
|
|
23043
|
-
this.name = "DeliveryError";
|
|
23044
|
-
this.code = code;
|
|
23045
|
-
this.retryable = retryable;
|
|
23046
|
-
this.status = status;
|
|
23047
|
-
}
|
|
23048
|
-
};
|
|
23049
|
-
var resolveAll = (hostname) => dns.promises.lookup(hostname, { all: true, verbatim: true });
|
|
23050
|
-
function httpsPost({ url, address, headers, body, timeoutMs }) {
|
|
23051
|
-
return new Promise((resolve, reject) => {
|
|
23052
|
-
const request = https.request(
|
|
23053
|
-
{
|
|
23054
|
-
protocol: "https:",
|
|
23055
|
-
hostname: url.hostname,
|
|
23056
|
-
port: url.port || 443,
|
|
23057
|
-
path: `${url.pathname}${url.search}`,
|
|
23058
|
-
method: "POST",
|
|
23059
|
-
headers: { ...headers, "Content-Length": Buffer.byteLength(body) },
|
|
23060
|
-
servername: net.isIP(url.hostname) ? void 0 : url.hostname,
|
|
23061
|
-
timeout: timeoutMs,
|
|
23062
|
-
// Pinned to the address that passed the check: no second lookup.
|
|
23063
|
-
lookup: (_hostname, options, callback) => {
|
|
23064
|
-
if (options && options.all) callback(null, [address]);
|
|
23065
|
-
else callback(null, address.address, address.family);
|
|
23066
|
-
}
|
|
23067
|
-
},
|
|
23068
|
-
(response) => {
|
|
23069
|
-
let received = 0;
|
|
23070
|
-
response.on("data", (chunk) => {
|
|
23071
|
-
received += chunk.length;
|
|
23072
|
-
if (received > MAX_RESPONSE_BYTES) response.destroy();
|
|
23073
|
-
});
|
|
23074
|
-
response.on("end", () => resolve(response.statusCode || 0));
|
|
23075
|
-
response.on("close", () => resolve(response.statusCode || 0));
|
|
23076
|
-
response.on("error", () => resolve(response.statusCode || 0));
|
|
23077
|
-
}
|
|
23078
|
-
);
|
|
23079
|
-
request.on("timeout", () => request.destroy(new DeliveryError("timeout", true)));
|
|
23080
|
-
request.on(
|
|
23081
|
-
"error",
|
|
23082
|
-
(err) => reject(err instanceof DeliveryError ? err : new DeliveryError("network_error", true))
|
|
23083
|
-
);
|
|
23084
|
-
request.end(body);
|
|
23085
|
-
});
|
|
23086
|
-
}
|
|
23087
|
-
async function deliverOnce({
|
|
23088
|
-
url,
|
|
23089
|
-
body,
|
|
23090
|
-
headers,
|
|
23091
|
-
resolve = resolveAll,
|
|
23092
|
-
post = httpsPost,
|
|
23093
|
-
timeoutMs = TIMEOUT_MS
|
|
23094
|
-
}) {
|
|
23095
|
-
let parsed;
|
|
23096
|
-
try {
|
|
23097
|
-
parsed = new URL(url);
|
|
23098
|
-
} catch {
|
|
23099
|
-
throw new DeliveryError("invalid_url", false);
|
|
23100
|
-
}
|
|
23101
|
-
if (parsed.protocol !== "https:" || parsed.username || parsed.password) {
|
|
23102
|
-
throw new DeliveryError("invalid_url", false);
|
|
23103
|
-
}
|
|
23104
|
-
const host = parsed.hostname.replace(/^\[|\]$/g, "");
|
|
23105
|
-
let addresses;
|
|
23106
|
-
if (net.isIP(host)) {
|
|
23107
|
-
addresses = [{ address: host, family: net.isIP(host) }];
|
|
23108
|
-
} else {
|
|
23109
|
-
try {
|
|
23110
|
-
addresses = await resolve(host);
|
|
23111
|
-
} catch {
|
|
23112
|
-
throw new DeliveryError("dns_failed", true);
|
|
23113
|
-
}
|
|
23114
|
-
}
|
|
23115
|
-
if (!Array.isArray(addresses) || addresses.length === 0)
|
|
23116
|
-
throw new DeliveryError("dns_failed", true);
|
|
23117
|
-
if (addresses.some((entry) => isBlockedAddress(entry.address))) {
|
|
23118
|
-
throw new DeliveryError("address_not_allowed", false);
|
|
23119
|
-
}
|
|
23120
|
-
const status = await post({ url: parsed, address: addresses[0], headers, body, timeoutMs });
|
|
23121
|
-
if (status >= 200 && status < 300) return { status };
|
|
23122
|
-
if (status >= 300 && status < 400)
|
|
23123
|
-
throw new DeliveryError("redirect_not_followed", false, status);
|
|
23124
|
-
throw new DeliveryError(`http_${status}`, status === 429 || status >= 500, status);
|
|
23125
|
-
}
|
|
23126
|
-
function buildSignedRequest({ event, data, secret, id = crypto.randomUUID(), now = /* @__PURE__ */ new Date() }) {
|
|
23127
|
-
const body = JSON.stringify({ id, event, createdAt: now.toISOString(), data });
|
|
23128
|
-
return {
|
|
23129
|
-
id,
|
|
23130
|
-
body,
|
|
23131
|
-
headers: {
|
|
23132
|
-
"Content-Type": "application/json",
|
|
23133
|
-
"User-Agent": USER_AGENT,
|
|
23134
|
-
[EVENT_HEADER]: event,
|
|
23135
|
-
[DELIVERY_HEADER]: id,
|
|
23136
|
-
[SIGNATURE_HEADER]: signPayload(secret, body, Math.floor(now.getTime() / 1e3))
|
|
23137
|
-
}
|
|
23138
|
-
};
|
|
23139
|
-
}
|
|
23140
|
-
async function deliverWithRetries({
|
|
23141
|
-
delays = RETRY_DELAYS_MS,
|
|
23142
|
-
sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms).unref?.()),
|
|
23143
|
-
...request
|
|
23144
|
-
}) {
|
|
23145
|
-
let attempts = 0;
|
|
23146
|
-
let last = { ok: false, status: null, code: "not_sent" };
|
|
23147
|
-
for (const delay of delays) {
|
|
23148
|
-
if (delay > 0) await sleep(delay);
|
|
23149
|
-
attempts += 1;
|
|
23150
|
-
try {
|
|
23151
|
-
const { status } = await deliverOnce(request);
|
|
23152
|
-
return { ok: true, status, code: null, attempts };
|
|
23153
|
-
} catch (err) {
|
|
23154
|
-
const error = err instanceof DeliveryError ? err : new DeliveryError("network_error", true);
|
|
23155
|
-
last = { ok: false, status: error.status, code: error.code };
|
|
23156
|
-
if (!error.retryable) break;
|
|
23157
|
-
}
|
|
23158
|
-
}
|
|
23159
|
-
return { ...last, attempts };
|
|
23160
|
-
}
|
|
23161
|
-
module.exports = {
|
|
23162
|
-
DELIVERY_HEADER,
|
|
23163
|
-
DeliveryError,
|
|
23164
|
-
EVENT_HEADER,
|
|
23165
|
-
RETRY_DELAYS_MS,
|
|
23166
|
-
SIGNATURE_HEADER,
|
|
23167
|
-
buildSignedRequest,
|
|
23168
|
-
deliverOnce,
|
|
23169
|
-
deliverWithRetries,
|
|
23170
|
-
isBlockedAddress,
|
|
23171
|
-
signPayload,
|
|
23172
|
-
verifySignature
|
|
23173
|
-
};
|
|
23174
|
-
}
|
|
23175
|
-
});
|
|
23176
|
-
|
|
23177
23727
|
// server/src/services/webhooks.js
|
|
23178
23728
|
var require_webhooks2 = __commonJS({
|
|
23179
23729
|
"server/src/services/webhooks.js"(exports, module) {
|
|
@@ -23452,12 +24002,14 @@ var require_rate_limit = __commonJS({
|
|
|
23452
24002
|
"use strict";
|
|
23453
24003
|
var { getPluginSettings } = require_settings_loader();
|
|
23454
24004
|
var { getCoordinator, hashedKey, __resetMemoryForTests } = require_coordination();
|
|
24005
|
+
var { ipBucket } = require_admin_request_info();
|
|
23455
24006
|
var callerKey = (ctx) => {
|
|
23456
24007
|
const userId = ctx.state?.user?.id;
|
|
23457
24008
|
if (userId) return `u:${userId}`;
|
|
23458
24009
|
const tokenId = ctx.state?.auth?.credentials?.id ?? ctx.state?.auth?.credentials?.token ?? null;
|
|
23459
24010
|
if (tokenId) return `t:${String(tokenId).slice(-16)}`;
|
|
23460
|
-
|
|
24011
|
+
const ip = ctx.request.ip || ctx.ip || "";
|
|
24012
|
+
return `ip:${ipBucket(ip) || ip || "unknown"}`;
|
|
23461
24013
|
};
|
|
23462
24014
|
var routeKey = (ctx) => {
|
|
23463
24015
|
const route = ctx.state?.route;
|