Skip to content

Commit 5541eef

Browse files
authored
fix(slack): scope interactive conversation bindings safely (#118662)
* fix(slack): scope interactive conversation bindings safely * fix(slack): satisfy typed sender authorization lint
1 parent f7434f9 commit 5541eef

6 files changed

Lines changed: 276 additions & 43 deletions

File tree

‎extensions/slack/src/channel.test.ts‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -862,6 +862,12 @@ describe("slackPlugin messaging targets", () => {
862862
expect(messaging?.resolveDeliveryTarget?.({ conversationId: "c08gqh53ejm" })).toEqual({
863863
to: "channel:c08gqh53ejm",
864864
});
865+
expect(messaging?.resolveDeliveryTarget?.({ conversationId: "G08GQH53EJM" })).toEqual({
866+
to: "channel:g08gqh53ejm",
867+
});
868+
expect(messaging?.resolveDeliveryTarget?.({ conversationId: "user:U08GQH53EJM" })).toEqual({
869+
to: "user:u08gqh53ejm",
870+
});
865871
expect(
866872
messaging?.resolveDeliveryTarget?.({
867873
conversationId: "1712345678.123456",
@@ -871,6 +877,24 @@ describe("slackPlugin messaging targets", () => {
871877
to: "channel:c08gqh53ejm",
872878
threadId: "1712345678.123456",
873879
});
880+
expect(
881+
messaging?.resolveDeliveryTarget?.({
882+
conversationId: "1712345678.654321",
883+
parentConversationId: "user:U08GQH53EJM",
884+
}),
885+
).toEqual({
886+
to: "user:u08gqh53ejm",
887+
threadId: "1712345678.654321",
888+
});
889+
expect(
890+
messaging?.resolveDeliveryTarget?.({
891+
conversationId: "1712345678.777777",
892+
parentConversationId: "G08GQH53EJM",
893+
}),
894+
).toEqual({
895+
to: "channel:g08gqh53ejm",
896+
threadId: "1712345678.777777",
897+
});
874898
expect(messaging?.resolveSessionTarget?.({ kind: "channel", id: "C08GQH53EJM" })).toBe(
875899
"channel:c08gqh53ejm",
876900
);

‎extensions/slack/src/channel.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -664,8 +664,8 @@ export const slackPlugin: ChannelPlugin<ResolvedSlackAccount, SlackProbe> = crea
664664
const parent = parentConversationId?.trim();
665665
const child = conversationId.trim();
666666
return parent && parent !== child
667-
? { to: normalizeSlackMessagingTarget(`channel:${parent}`), threadId: child }
668-
: { to: normalizeSlackMessagingTarget(`channel:${child}`) };
667+
? { to: normalizeSlackMessagingTarget(parent), threadId: child }
668+
: { to: normalizeSlackMessagingTarget(child) };
669669
},
670670
resolveSessionTarget: ({ id }) => {
671671
// Session identities stay folded; send.ts restores unambiguous IDs at the API boundary.

‎extensions/slack/src/interactive-dispatch.ts‎

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,10 +103,20 @@ type SlackInteractiveDispatchContext = Omit<
103103
export async function dispatchSlackPluginInteractiveHandler(params: {
104104
data: string;
105105
interactionId: string;
106+
channelType?: "im" | "mpim" | "channel" | "group";
106107
ctx: SlackInteractiveDispatchContext;
107108
respond: SlackInteractiveHandlerContext["respond"];
108109
onMatched?: () => Promise<void> | void;
109110
}) {
111+
const senderId = params.ctx.senderId?.trim();
112+
const baseConversationId =
113+
params.channelType === "im"
114+
? senderId
115+
? `user:${senderId}`
116+
: ""
117+
: params.ctx.conversationId.trim();
118+
const threadId = params.ctx.threadId?.trim() || undefined;
119+
110120
return await dispatchPluginInteractiveHandler<SlackInteractiveHandlerRegistration>({
111121
channel: "slack",
112122
data: params.data,
@@ -124,14 +134,20 @@ export async function dispatchSlackPluginInteractiveHandler(params: {
124134
},
125135
respond: params.respond,
126136
...createInteractiveConversationBindingHelpers({
127-
registration,
137+
// The shared helpers fail closed without owner authority; never expose it to unauthenticated actions.
138+
registration:
139+
params.ctx.auth.isAuthorizedSender && baseConversationId
140+
? registration
141+
: { ...registration, pluginRoot: undefined },
128142
senderId: params.ctx.senderId,
129143
conversation: {
130144
channel: "slack",
131145
accountId: params.ctx.accountId,
132-
conversationId: params.ctx.conversationId,
133-
parentConversationId: params.ctx.parentConversationId,
134-
threadId: params.ctx.threadId,
146+
conversationId: threadId ?? baseConversationId,
147+
parentConversationId: threadId
148+
? (params.ctx.parentConversationId ?? baseConversationId)
149+
: params.ctx.parentConversationId,
150+
threadId,
135151
},
136152
}),
137153
}),

‎extensions/slack/src/monitor/events/interactions.block-actions.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -770,6 +770,7 @@ async function dispatchSlackPluginInteraction(params: {
770770
parsed: ParsedSlackBlockAction;
771771
pluginInteractionData: string;
772772
auth: { isAuthorizedSender: boolean };
773+
channelType?: Parameters<typeof dispatchSlackPluginInteractiveHandler>[0]["channelType"];
773774
respond?: SlackBlockActionRespond;
774775
}): Promise<boolean> {
775776
const pluginInteractionId = buildSlackPluginInteractionId({
@@ -793,6 +794,7 @@ async function dispatchSlackPluginInteraction(params: {
793794
const pluginResult = await dispatchSlackPluginInteractiveHandler({
794795
data: params.pluginInteractionData,
795796
interactionId: pluginInteractionId,
797+
channelType: params.channelType,
796798
ctx: {
797799
accountId: params.ctx.accountId,
798800
interactionId: pluginInteractionId,
@@ -1138,6 +1140,7 @@ async function handleSlackBlockAction(params: {
11381140
auth: {
11391141
isAuthorizedSender,
11401142
},
1143+
channelType: auth.channelType,
11411144
respond,
11421145
});
11431146
if (handled) {

‎extensions/slack/src/monitor/events/interactions.modal.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,7 @@ async function dispatchSlackModalPluginInteractiveHandler(params: {
222222
interactionType: SlackModalInteractionKind;
223223
data: string | undefined;
224224
auth: { isAuthorizedSender: boolean };
225+
channelType?: Parameters<typeof dispatchSlackPluginInteractiveHandler>[0]["channelType"];
225226
payload: SlackModalEventBase["payload"];
226227
stateValues?: unknown;
227228
sessionRouting: SlackModalEventBase["sessionRouting"];
@@ -248,6 +249,7 @@ async function dispatchSlackModalPluginInteractiveHandler(params: {
248249
const result = await dispatchSlackPluginInteractiveHandler({
249250
data: params.data,
250251
interactionId,
252+
channelType: params.channelType,
251253
ctx: {
252254
accountId: params.ctx.accountId,
253255
interactionId,
@@ -377,6 +379,7 @@ async function emitSlackModalLifecycleEvent(params: {
377379
interactionType: params.interactionType,
378380
data: pluginInteractiveData,
379381
auth: { isAuthorizedSender: auth.allowed },
382+
channelType: auth.channelType,
380383
payload,
381384
stateValues,
382385
sessionRouting,

0 commit comments

Comments
 (0)