@@ -176,12 +176,6 @@ export async function findWebhookAndWorkflow(
176176 return null
177177}
178178
179- /**
180- * Resolves environment variables in a string value
181- * @param value - String that may contain {{VARIABLE}} references
182- * @param envVars - Map of environment variable name to decrypted value
183- * @returns String with all {{VARIABLE}} references replaced with actual values
184- */
185179function resolveEnvVariablesInString ( value : string , envVars : Record < string , string > ) : string {
186180 const envMatches = value . match ( / \{ \{ ( [ ^ } ] + ) \} \} / g)
187181 if ( ! envMatches ) {
@@ -202,12 +196,6 @@ function resolveEnvVariablesInString(value: string, envVars: Record<string, stri
202196 return resolvedValue
203197}
204198
205- /**
206- * Resolves environment variables in providerConfig
207- * @param providerConfig - Provider configuration that may contain {{VARIABLE}} references
208- * @param envVars - Map of environment variable name to decrypted value
209- * @returns Provider config with all {{VARIABLE}} references resolved
210- */
211199function resolveProviderConfigEnvVars (
212200 providerConfig : Record < string , any > ,
213201 envVars : Record < string , string >
@@ -232,7 +220,6 @@ export async function verifyProviderAuth(
232220 rawBody : string ,
233221 requestId : string
234222) : Promise < NextResponse | null > {
235- // Fetch and decrypt environment variables for resolving {{VARIABLE}} references in providerConfig
236223 let decryptedEnvVars : Record < string , string > = { }
237224 try {
238225 decryptedEnvVars = await getEffectiveDecryptedEnv (
@@ -243,7 +230,6 @@ export async function verifyProviderAuth(
243230 logger . error ( `[${ requestId } ] Failed to fetch environment variables for webhook verification` , {
244231 error : error instanceof Error ? error . message : String ( error ) ,
245232 } )
246- // Continue without env vars - if config needs them, verification will fail appropriately
247233 }
248234
249235 // Resolve environment variables in providerConfig and mutate in place
@@ -279,6 +265,37 @@ export async function verifyProviderAuth(
279265 }
280266 }
281267
268+ // Slack webhook signature verification
269+ if ( foundWebhook . provider === 'slack' ) {
270+ const signingSecret = providerConfig . signingSecret as string | undefined
271+
272+ if ( signingSecret ) {
273+ const signature = request . headers . get ( 'x-slack-signature' )
274+ const timestamp = request . headers . get ( 'x-slack-request-timestamp' )
275+
276+ if ( ! signature || ! timestamp ) {
277+ logger . warn ( `[${ requestId } ] Slack webhook missing signature headers` )
278+ return new NextResponse ( 'Unauthorized - Missing Slack signature' , { status : 401 } )
279+ }
280+
281+ const { validateSlackSignature } = await import ( '@/lib/webhooks/utils' )
282+
283+ const isValidSignature = await validateSlackSignature (
284+ signingSecret ,
285+ signature ,
286+ timestamp ,
287+ rawBody
288+ )
289+
290+ if ( ! isValidSignature ) {
291+ logger . warn ( `[${ requestId } ] Slack signature verification failed` )
292+ return new NextResponse ( 'Unauthorized - Invalid Slack signature' , { status : 401 } )
293+ }
294+
295+ logger . debug ( `[${ requestId } ] Slack signature verified successfully` )
296+ }
297+ }
298+
282299 // Provider-specific verification (utils may return a response for some providers)
283300 const providerVerification = verifyProviderWebhook ( foundWebhook , request , requestId )
284301 if ( providerVerification ) {
0 commit comments