fix: block development writes to Discord channels

This commit is contained in:
syntaxbullet
2026-09-07 11:57:23 +02:00
parent 6d1d12953c
commit e6002ad619
4 changed files with 45 additions and 3 deletions

View File

@@ -1,10 +1,12 @@
export type DiscordSharingConfig = { token: string; channelId: string; allowedUserIds?: string[] };
export type DiscordSharingConfig = { token: string; channelId: string; allowedUserIds?: string[]; writesEnabled?: boolean };
/** 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 {
// Real channel writes are production-only. Test fixtures may inject a stub config.
writesEnabled: env.NODE_ENV === "production",
allowedUserIds,
token: (env.DISCORD_BOT_TOKEN ?? "").trim().replace(/^Bot\s+/i, ""),
channelId: (env.DISCORD_SHARING_CHANNEL_ID ?? "").trim(),