Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix(microsoft-ad): add $search/$filter guard, $count=true, and member…
…Id validation

- Prevent using $search and $filter together (Graph API rejects this)
- Add $count=true when $search is used (required with ConsistencyLevel: eventual)
- Validate and trim memberId in add_group_member body before use

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
  • Loading branch information
waleedlatif1 and claude committed Mar 19, 2026
commit 763de06038f25475ce618b3ac46fabcdf5989ee9
10 changes: 7 additions & 3 deletions apps/sim/tools/microsoft_ad/add_group_member.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,13 @@ export const addGroupMemberTool: ToolConfig<
Authorization: `Bearer ${params.accessToken}`,
'Content-Type': 'application/json',
}),
body: (params) => ({
'@odata.id': `https://graph.microsoft.com/v1.0/directoryObjects/${params.memberId}`,
}),
body: (params) => {
const memberId = params.memberId?.trim()
if (!memberId) throw new Error('Member ID is required')
return {
'@odata.id': `https://graph.microsoft.com/v1.0/directoryObjects/${memberId}`,
}
},
},
transformResponse: async (_response: Response, params?: MicrosoftAdAddGroupMemberParams) => {
return {
Expand Down
8 changes: 7 additions & 1 deletion apps/sim/tools/microsoft_ad/list_groups.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,14 @@ export const listGroupsTool: ToolConfig<
'$select=id,displayName,description,mail,mailEnabled,mailNickname,securityEnabled,groupTypes,visibility,createdDateTime'
)
if (params.top) queryParts.push(`$top=${params.top}`)
if (params.search && params.filter) {
throw new Error('$search and $filter cannot be used together in Microsoft Graph API')
}
if (params.filter) queryParts.push(`$filter=${encodeURIComponent(params.filter)}`)
if (params.search) queryParts.push(`$search="${encodeURIComponent(params.search)}"`)
if (params.search) {
queryParts.push(`$search="${encodeURIComponent(params.search)}"`)
queryParts.push('$count=true')
}
return `https://graph.microsoft.com/v1.0/groups?${queryParts.join('&')}`
},
method: 'GET',
Expand Down
8 changes: 7 additions & 1 deletion apps/sim/tools/microsoft_ad/list_users.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,14 @@ export const listUsersTool: ToolConfig<MicrosoftAdListUsersParams, MicrosoftAdLi
'$select=id,displayName,givenName,surname,userPrincipalName,mail,jobTitle,department,officeLocation,mobilePhone,accountEnabled'
)
if (params.top) queryParts.push(`$top=${params.top}`)
if (params.search && params.filter) {
throw new Error('$search and $filter cannot be used together in Microsoft Graph API')
}
if (params.filter) queryParts.push(`$filter=${encodeURIComponent(params.filter)}`)
if (params.search) queryParts.push(`$search="${encodeURIComponent(params.search)}"`)
if (params.search) {
queryParts.push(`$search="${encodeURIComponent(params.search)}"`)
queryParts.push('$count=true')
}
return `https://graph.microsoft.com/v1.0/users?${queryParts.join('&')}`
Comment thread
waleedlatif1 marked this conversation as resolved.
},
method: 'GET',
Expand Down
Loading