Skip to content

Commit

Permalink
don't allow external channels in app mentions or messages
Browse files Browse the repository at this point in the history
  • Loading branch information
scazan committed Nov 13, 2023
1 parent cfc8cbf commit bf2ccad
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
8 changes: 5 additions & 3 deletions integrations/slack/src/handlers/handlers.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { Logger } from '@gitbook/runtime';

import type { SlashEvent } from './commands';
import { notifyOnlySupportedThreads, queryLens, saveThread } from '../actions';
import { SlackRuntimeContext } from '../configuration';
import { isSaveThreadMessage, stripBotName } from '../utils';
import type { SlashEvent } from './commands';

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

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

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

// check for bot_id so that the bot doesn't trigger itself
if (['message', 'app_mention'].includes(type) && !bot_id) {
if (['message', 'app_mention'].includes(type) && !bot_id && !isExternalChannel) {
// strip out the bot-name in the mention and account for user mentions within the query
// @ts-ignore
const parsedMessage = stripBotName(text, eventPayload.authorizations[0]?.user_id);
Expand Down
1 change: 1 addition & 0 deletions integrations/slack/src/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ export const handleFetchEvent: FetchEventCallback = async (request, context) =>
verifySlackRequest,
createSlackCommandsHandler({
'/gitbook': queryLensSlashHandler,
'/gitbookstaging': queryLensSlashHandler, // needed to allow our staging app to co-exist with the prod app
}),
acknowledgeSlackRequest
);
Expand Down

0 comments on commit bf2ccad

Please sign in to comment.