Skip to content

Commit cfdbf8f

Browse files
committed
πŸ”’οΈ secure /chatwoot endpoint behind api key when using -k #2362
1 parent 643f07f commit cfdbf8f

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

β€Žsrc/cli/index.tsβ€Ž

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -100,13 +100,6 @@ async function start() {
100100
}
101101
})
102102

103-
if(cliConfig?.chatwootUrl){
104-
spinner.info('Setting Up Chatwoot handler');
105-
spinner.info('Make sure to set up the Chatwoot inbox webhook to the following path on this process: /chatwoot');
106-
await setupChatwoot(cliConfig, client);
107-
spinner.succeed('Chatwoot handler set up successfully');
108-
}
109-
110103
if(cliConfig?.botPressUrl){
111104
spinner.info('Setting Up Botpress handler');
112105
setupBotPressHandler(cliConfig, client)
@@ -138,6 +131,13 @@ async function start() {
138131
setupAuthenticationLayer(cliConfig)
139132
}
140133

134+
if(cliConfig?.chatwootUrl){
135+
spinner.info('Setting Up Chatwoot handler');
136+
spinner.info(`Make sure to set up the Chatwoot inbox webhook to the following path on this process: /chatwoot${cliConfig.key ? `?api_key=YOUR-API-KEY` : ''}`);
137+
await setupChatwoot(cliConfig, client);
138+
spinner.succeed('Chatwoot handler set up successfully');
139+
}
140+
141141
setupRefocusDisengageMiddleware(cliConfig)
142142

143143
if (cliConfig && cliConfig.generateApiDocs && collections["swagger"]) {

β€Žsrc/cli/server.tsβ€Ž

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,9 @@ export const setupAuthenticationLayer : (cliConfig : cliFlags) => void = (cliCon
5050
return next();
5151
}
5252
const apiKey = req.get('key') || req.get('api_key')
53-
if (!apiKey || apiKey !== cliConfig.key) {
53+
if (req.path.includes('chatwoot') && req.query['api_key'] && req.query['api_key'] == cliConfig.key) {
54+
next();
55+
} else if (!apiKey || apiKey !== cliConfig.key) {
5456
res.status(401).json({ error: 'unauthorised' })
5557
} else {
5658
next()

0 commit comments

Comments
Β (0)