@luckystack/server 0.3.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +37 -4
- package/dist/index.js.map +1 -1
- package/package.json +10 -10
package/dist/index.js
CHANGED
|
@@ -472,6 +472,40 @@ var handleAuthApiRoute = async ({
|
|
|
472
472
|
return true;
|
|
473
473
|
}
|
|
474
474
|
if (login.isFullOAuthProvider(provider)) {
|
|
475
|
+
const oauthRateLimiting = config.rateLimiting;
|
|
476
|
+
const oauthRequesterIp = resolveClientIp({
|
|
477
|
+
rawAddress: req.socket.remoteAddress,
|
|
478
|
+
headers: req.headers,
|
|
479
|
+
trustProxy: config.http.trustProxy,
|
|
480
|
+
trustedProxyHopCount: config.http.trustedProxyHopCount
|
|
481
|
+
});
|
|
482
|
+
const oauthInitLimit = oauthRateLimiting.defaultApiLimit !== false && oauthRateLimiting.defaultApiLimit > 0 ? oauthRateLimiting.defaultApiLimit : oauthRateLimiting.auth.enabled && oauthRateLimiting.auth.maxAttempts > 0 ? oauthRateLimiting.auth.maxAttempts : null;
|
|
483
|
+
if (oauthInitLimit !== null) {
|
|
484
|
+
const oauthInitWindowMs = oauthRateLimiting.defaultApiLimit === false ? oauthRateLimiting.auth.windowMs : oauthRateLimiting.windowMs;
|
|
485
|
+
const { allowed, resetIn } = await checkRateLimit({
|
|
486
|
+
key: `ip:${oauthRequesterIp}:auth:oauth-init`,
|
|
487
|
+
limit: oauthInitLimit,
|
|
488
|
+
windowMs: oauthInitWindowMs
|
|
489
|
+
});
|
|
490
|
+
if (!allowed) {
|
|
491
|
+
void dispatchHook2("rateLimitExceeded", {
|
|
492
|
+
scope: "auth",
|
|
493
|
+
key: `ip:${oauthRequesterIp}:auth:oauth-init`,
|
|
494
|
+
limit: oauthInitLimit,
|
|
495
|
+
windowMs: oauthInitWindowMs,
|
|
496
|
+
count: oauthInitLimit + 1,
|
|
497
|
+
route: routePath,
|
|
498
|
+
ip: oauthRequesterIp
|
|
499
|
+
});
|
|
500
|
+
res.writeHead(429, { "content-type": "application/json; charset=utf-8" });
|
|
501
|
+
res.end(JSON.stringify({
|
|
502
|
+
status: false,
|
|
503
|
+
reason: "api.rateLimitExceeded",
|
|
504
|
+
errorParams: [{ key: "seconds", value: resetIn }]
|
|
505
|
+
}));
|
|
506
|
+
return true;
|
|
507
|
+
}
|
|
508
|
+
}
|
|
475
509
|
const reqUrl = new URL(req.url ?? "/", "http://placeholder");
|
|
476
510
|
const returnUrl = reqUrl.searchParams.get("return_url") ?? void 0;
|
|
477
511
|
const oauthState = await login.createOAuthState(provider.name, { usePkce: provider.usePkce, returnUrl });
|
|
@@ -1419,8 +1453,7 @@ var executeRoomMutation = async (opts) => {
|
|
|
1419
1453
|
return;
|
|
1420
1454
|
}
|
|
1421
1455
|
const existingRoomCodes = getSessionRoomCodes(session);
|
|
1422
|
-
const
|
|
1423
|
-
const physicalRoom = formatRoomName(group, { purpose: roomPurpose, userId: session.id });
|
|
1456
|
+
const physicalRoom = formatRoomName(group, { purpose: "broadcast", userId: session.id });
|
|
1424
1457
|
const nextRoomCodes = await mutate(socket, physicalRoom, group, existingRoomCodes, session.id);
|
|
1425
1458
|
const sanitizedSession = sanitizeSessionRoomKeys(session);
|
|
1426
1459
|
await writeSession(token, { ...sanitizedSession, roomCodes: nextRoomCodes });
|
|
@@ -1486,7 +1519,7 @@ var registerRoomEvents = (ctx) => {
|
|
|
1486
1519
|
const oldest = kept[0];
|
|
1487
1520
|
if (oldest === void 0) break;
|
|
1488
1521
|
kept = kept.slice(1);
|
|
1489
|
-
await sock.leave(formatRoomName(oldest, { purpose: "
|
|
1522
|
+
await sock.leave(formatRoomName(oldest, { purpose: "broadcast", userId }));
|
|
1490
1523
|
}
|
|
1491
1524
|
}
|
|
1492
1525
|
await sock.join(physicalRoom);
|
|
@@ -1637,7 +1670,7 @@ var rejoinPersistedRooms = (ctx) => {
|
|
|
1637
1670
|
const roomCodes = session ? getSessionRoomCodes(session) : [];
|
|
1638
1671
|
const userId = session?.id ?? null;
|
|
1639
1672
|
for (const roomCode of roomCodes) {
|
|
1640
|
-
await socket.join(formatRoomName(roomCode, { purpose: "
|
|
1673
|
+
await socket.join(formatRoomName(roomCode, { purpose: "broadcast", userId }));
|
|
1641
1674
|
}
|
|
1642
1675
|
return roomCodes;
|
|
1643
1676
|
});
|