feat: limit Discord sharing and support community allowlists

This commit is contained in:
syntaxbullet
2026-09-04 18:25:09 +02:00
parent d624ee6c3c
commit 32002151e0
9 changed files with 892 additions and 7 deletions

View File

@@ -1,8 +1,11 @@
export type DiscordSharingConfig = { token: string; channelId: string };
export type DiscordSharingConfig = { token: string; channelId: string; allowedUserIds?: string[] };
/** Read only from the server entrypoint; never include credentials in public config. */
export function readDiscordSharingConfig(env = process.env): DiscordSharingConfig {
const allowedUserIds = (env.DISCORD_SHARING_ALLOWED_USER_IDS ?? "").split(",").map(id => id.trim()).filter(Boolean);
if (allowedUserIds.some(id => !/^\d{17,20}$/.test(id))) throw new Error("DISCORD_SHARING_ALLOWED_USER_IDS must contain comma-separated Discord user IDs");
return {
allowedUserIds,
token: (env.DISCORD_BOT_TOKEN ?? "").trim().replace(/^Bot\s+/i, ""),
channelId: (env.DISCORD_SHARING_CHANNEL_ID ?? "").trim(),
};