Skip to content

Commit bf2ccad

Browse files
committed
don't allow external channels in app mentions or messages
1 parent cfc8cbf commit bf2ccad

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

integrations/slack/src/handlers/handlers.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import { Logger } from '@gitbook/runtime';
22

3+
import type { SlashEvent } from './commands';
34
import { notifyOnlySupportedThreads, queryLens, saveThread } from '../actions';
45
import { SlackRuntimeContext } from '../configuration';
56
import { isSaveThreadMessage, stripBotName } from '../utils';
6-
import type { SlashEvent } from './commands';
77

88
const logger = Logger('slack:api');
99

@@ -40,9 +40,10 @@ export async function queryLensSlashHandler(slashEvent: SlashEvent, context: Sla
4040
export async function messageEventHandler(eventPayload: any, context: SlackRuntimeContext) {
4141
// pull out required params from the slashEvent for queryLens
4242
const { type, text, bot_id, thread_ts, channel, user, team } = eventPayload.event;
43+
const isExternalChannel = eventPayload.is_ext_shared_channel;
4344

4445
// check for bot_id so that the bot doesn't trigger itself
45-
if (['message', 'app_mention'].includes(type) && !bot_id) {
46+
if (['message', 'app_mention'].includes(type) && !bot_id && !isExternalChannel) {
4647
// strip out the bot-name in the mention and account for user mentions within the query
4748
// @ts-ignore
4849
const parsedQuery = stripBotName(text, eventPayload.authorizations[0]?.user_id);
@@ -73,9 +74,10 @@ export async function messageEventHandler(eventPayload: any, context: SlackRunti
7374
export async function appMentionEventHandler(eventPayload: any, context: SlackRuntimeContext) {
7475
// pull out required params from the slashEvent for queryLens
7576
const { type, text, bot_id, thread_ts, channel, user, team } = eventPayload.event;
77+
const isExternalChannel = eventPayload.is_ext_shared_channel;
7678

7779
// check for bot_id so that the bot doesn't trigger itself
78-
if (['message', 'app_mention'].includes(type) && !bot_id) {
80+
if (['message', 'app_mention'].includes(type) && !bot_id && !isExternalChannel) {
7981
// strip out the bot-name in the mention and account for user mentions within the query
8082
// @ts-ignore
8183
const parsedMessage = stripBotName(text, eventPayload.authorizations[0]?.user_id);

integrations/slack/src/router.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ export const handleFetchEvent: FetchEventCallback = async (request, context) =>
112112
verifySlackRequest,
113113
createSlackCommandsHandler({
114114
'/gitbook': queryLensSlashHandler,
115+
'/gitbookstaging': queryLensSlashHandler, // needed to allow our staging app to co-exist with the prod app
115116
}),
116117
acknowledgeSlackRequest
117118
);

0 commit comments

Comments
 (0)