Supercharge your AI agents with data from the web and beyond. Building the library for superintelligence. 🔥
TypeScript aiai-agentsai-crawlerai-scrapingai-searchcrawlerdata-extractionhtml-to-markdownllmmarkdownscraperscrapingweb-crawlerweb-dataweb-data-extractionweb-scraperweb-scrapingweb-searchwebscraping
fix(api): require SLACK_TOKEN_ENCRYPTION_KEY to store Slack tokens in production (#5308)
David Tippett35558b35e696
diff --git a/apps/api/src/config.ts b/apps/api/src/config.tsindex 2d8b7cd22..bbefcb89e 100644--- a/apps/api/src/config.ts+++ b/apps/api/src/config.ts@@ -609,7 +609,8 @@ const configSchema = z.object({// https://api.firecrawl.dev/v2/slack/oauth/callback).SLACK_OAUTH_REDIRECT_URL: z.string().optional(),// 32-byte key (hex or base64) used to AES-256-GCM encrypt stored bot tokens.- // If unset, tokens are stored with a `plain:` prefix (self-hosted only).+ // Required when ENV=production. Elsewhere, if unset, tokens are stored with a+ // `plain:` prefix.SLACK_TOKEN_ENCRYPTION_KEY: z.string().optional(),ALLOW_LOCAL_WEBHOOKS: z.stringbool().optional(),WEBHOOK_USE_RABBITMQ: z.stringbool().optional(),diff --git a/apps/api/src/services/integrations/slack/crypto.ts b/apps/api/src/services/integrations/slack/crypto.tsindex a86b0b528..295242471 100644--- a/apps/api/src/services/integrations/slack/crypto.ts+++ b/apps/api/src/services/integrations/slack/crypto.ts@@ -5,8 +5,8 @@ const PLAINTEXT_PREFIX = "plain:";const GCM_PREFIX = "gcm:";// Accepts a 32-byte key as hex (64 chars) or base64. Returns null ONLY when the-// key is unset (self-hosted plaintext fallback). A key that is set but malformed-// throws, so a misconfiguration never silently downgrades to plaintext storage.+// key is unset. A key that is set but malformed throws, so a misconfiguration+// never silently downgrades to plaintext storage.function getKey(): Buffer | null {const raw = config.SLACK_TOKEN_ENCRYPTION_KEY?.trim();if (!raw) return null;@@ -33,11 +33,16 @@ function getKey(): Buffer | null {return key;}-// Encrypts a Slack bot token for storage. When no encryption key is configured-// the token is stored with a `plain:` marker (self-hosted only).+// Encrypts a Slack bot token for storage. Without a key, production refuses to+// store the token; other environments store it with a `plain:` marker.export function encryptSlackToken(token: string): string {const key = getKey();if (!key) {+ if (config.ENV === "production") {+ throw new Error(+ "SLACK_TOKEN_ENCRYPTION_KEY is not set; refusing to store a plaintext Slack token in production",+ );+ }return `${PLAINTEXT_PREFIX}${token}`;}const iv = crypto.randomBytes(12);