Add join captcha gate
This commit is contained in:
@@ -5,6 +5,7 @@ import { randomUUID } from "node:crypto";
|
||||
|
||||
const port = Number(process.env.PORT || 3000);
|
||||
const host = process.env.HOST || "127.0.0.1";
|
||||
const captchaPassphrase = process.env.KKKMEET_CAPTCHA_PASSPHRASE || "kkkmeet";
|
||||
const publicDir = join(process.cwd(), "public");
|
||||
const rooms = new Map();
|
||||
const watchStates = new Map();
|
||||
@@ -48,6 +49,10 @@ function normalizeClientId(value) {
|
||||
return /^[a-z0-9_-]{16,80}$/i.test(normalized) ? normalized : "";
|
||||
}
|
||||
|
||||
function captchaAccepted(value) {
|
||||
return String(value || "") === captchaPassphrase;
|
||||
}
|
||||
|
||||
function normalizePlaylist(playlist) {
|
||||
if (!Array.isArray(playlist)) return [];
|
||||
|
||||
@@ -137,6 +142,11 @@ const server = http.createServer(async (req, res) => {
|
||||
|
||||
try {
|
||||
if (req.method === "GET" && url.pathname.startsWith("/events/")) {
|
||||
if (!captchaAccepted(url.searchParams.get("captcha"))) {
|
||||
sendJson(res, 403, { error: "Captcha passphrase is required." });
|
||||
return;
|
||||
}
|
||||
|
||||
const roomId = url.pathname.split("/").at(-1) || defaultRoomId;
|
||||
const displayName = normalizeName(url.searchParams.get("name"));
|
||||
const clientId = normalizeClientId(url.searchParams.get("clientId"));
|
||||
@@ -180,6 +190,16 @@ const server = http.createServer(async (req, res) => {
|
||||
return;
|
||||
}
|
||||
|
||||
if (req.method === "GET" && url.pathname === "/config") {
|
||||
sendJson(res, 200, {
|
||||
captcha: {
|
||||
enabled: true,
|
||||
passphrase: captchaPassphrase
|
||||
}
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
if (req.method === "POST" && url.pathname.startsWith("/room-event/")) {
|
||||
const roomId = url.pathname.split("/").at(-1) || defaultRoomId;
|
||||
const payload = await parseJson(req);
|
||||
|
||||
Reference in New Issue
Block a user