@@ -3,7 +3,7 @@ import { createLogger } from '@sim/logger'
33import { getErrorMessage } from '@sim/utils/errors'
44import { generateId } from '@sim/utils/id'
55import { and , eq , sql } from 'drizzle-orm'
6- import { getActivelyBannedUserIds } from '@/lib/auth/ban'
6+ import { getActivelyBannedUserIds , isEmailDomainBlocked } from '@/lib/auth/ban'
77import { resolveOrCreateChat } from '@/lib/copilot/chat/lifecycle'
88import { appendCopilotChatMessages } from '@/lib/copilot/chat/messages-store'
99import { buildIntegrationToolSchemas } from '@/lib/copilot/chat/payload'
@@ -94,11 +94,34 @@ export async function executeInboxTask(taskId: string): Promise<void> {
9494 return
9595 }
9696
97- // No email response on purpose — never mail a suspended account.
98- const [ bannedUserId ] = await getActivelyBannedUserIds ( [ userId ] )
99- if ( bannedUserId ) {
100- logger . warn ( 'Blocking inbox task: resolved user is banned' , { taskId, userId } )
101- await markTaskFailed ( taskId , 'User account is suspended' )
97+ // Blocked senders and banned accounts must not drive the agent; the sender
98+ // email is checked directly because non-members resolve to the workspace
99+ // owner. Fails closed on lookup errors. No email response in any of these
100+ // paths — never mail a suspended account.
101+ let blockReason : string | null = null
102+ try {
103+ const [ senderBlocked , [ bannedUserId ] ] = await Promise . all ( [
104+ isEmailDomainBlocked ( inboxTask . fromEmail ) ,
105+ getActivelyBannedUserIds ( [ userId ] ) ,
106+ ] )
107+ if ( senderBlocked || bannedUserId ) {
108+ logger . warn ( 'Blocking inbox task: sender or resolved user is banned' , {
109+ taskId,
110+ userId,
111+ senderBlocked,
112+ } )
113+ blockReason = 'User account is suspended'
114+ }
115+ } catch ( error ) {
116+ logger . error ( 'Inbox task ban check failed; failing closed' , {
117+ taskId,
118+ error : getErrorMessage ( error , 'Unknown error' ) ,
119+ } )
120+ blockReason = 'Unable to verify account status'
121+ }
122+ if ( blockReason ) {
123+ responseSent = true
124+ await markTaskFailed ( taskId , blockReason )
102125 return
103126 }
104127
0 commit comments