MCPcopy Create free account
hub / github.com/adcontextprotocol/adcp / createSlackSignatureVerifier

Function createSlackSignatureVerifier

server/src/middleware/slack.ts:43–85  ·  view source on GitHub ↗
(
  signingSecret: string | undefined,
  appName: string = 'Slack'
)

Source from the content-addressed store, hash-verified

41 * @returns Express middleware that verifies signatures
42 */
43export function createSlackSignatureVerifier(
44 signingSecret: string | undefined,
45 appName: string = 'Slack'
46): RequestHandler {
47 return (req: Request, res: Response, next: NextFunction): void => {
48 if (!signingSecret) {
49 logger.warn(`${appName}: Signing secret not configured, skipping verification`);
50 next();
51 return;
52 }
53
54 const signature = req.headers['x-slack-signature'] as string;
55 const timestamp = req.headers['x-slack-request-timestamp'] as string;
56
57 if (!signature || !timestamp) {
58 logger.warn(`${appName}: Missing signature headers`);
59 res.status(401).json({ error: 'Missing signature headers' });
60 return;
61 }
62
63 const rawBody = (req as any).rawBody;
64 if (!rawBody) {
65 logger.warn(`${appName}: Raw body not captured for signature verification`);
66 res.status(500).json({ error: 'Internal error' });
67 return;
68 }
69
70 const isValid = verifySlackSignature(
71 signingSecret,
72 signature,
73 timestamp,
74 rawBody
75 );
76
77 if (!isValid) {
78 logger.warn(`${appName}: Invalid signature`);
79 res.status(401).json({ error: 'Invalid signature' });
80 return;
81 }
82
83 next();
84 };
85}
86
87/**
88 * Middleware to handle Slack URL verification challenge

Callers 1

createSlackRouterFunction · 0.85

Calls 2

warnMethod · 0.80
verifySlackSignatureFunction · 0.50

Tested by

no test coverage detected