Skip to content

Commit 210cab9

Browse files
waleedlatif1claude
andcommitted
fix(monday): validate all numeric IDs and sanitize columns in GraphQL queries
- Add sanitizeNumericId() helper to tools/monday/utils.ts for consistent validation across all tool body builders - Apply to all 13 instances of boardId, itemId, parentItemId interpolation across 11 tool files, preventing GraphQL injection via crafted IDs - Wrap JSON.parse in search_items.ts with try-catch for user-friendly error on malformed column filter JSON Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent dc7814b commit 210cab9

13 files changed

Lines changed: 110 additions & 29 deletions

apps/sim/tools/monday/archive_item.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
import type { MondayArchiveItemParams, MondayArchiveItemResponse } from '@/tools/monday/types'
2-
import { extractMondayError, MONDAY_API_URL, mondayHeaders } from '@/tools/monday/utils'
2+
import {
3+
extractMondayError,
4+
MONDAY_API_URL,
5+
mondayHeaders,
6+
sanitizeNumericId,
7+
} from '@/tools/monday/utils'
38
import type { ToolConfig } from '@/tools/types'
49

510
export const mondayArchiveItemTool: ToolConfig<MondayArchiveItemParams, MondayArchiveItemResponse> =
@@ -34,7 +39,7 @@ export const mondayArchiveItemTool: ToolConfig<MondayArchiveItemParams, MondayAr
3439
method: 'POST',
3540
headers: (params) => mondayHeaders(params.accessToken),
3641
body: (params) => ({
37-
query: `mutation { archive_item(item_id: ${params.itemId}) { id } }`,
42+
query: `mutation { archive_item(item_id: ${sanitizeNumericId(params.itemId, 'itemId')}) { id } }`,
3843
}),
3944
},
4045

apps/sim/tools/monday/create_group.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
import type { MondayCreateGroupParams, MondayCreateGroupResponse } from '@/tools/monday/types'
2-
import { extractMondayError, MONDAY_API_URL, mondayHeaders } from '@/tools/monday/utils'
2+
import {
3+
extractMondayError,
4+
MONDAY_API_URL,
5+
mondayHeaders,
6+
sanitizeNumericId,
7+
} from '@/tools/monday/utils'
38
import type { ToolConfig } from '@/tools/types'
49

510
export const mondayCreateGroupTool: ToolConfig<MondayCreateGroupParams, MondayCreateGroupResponse> =
@@ -47,7 +52,7 @@ export const mondayCreateGroupTool: ToolConfig<MondayCreateGroupParams, MondayCr
4752
headers: (params) => mondayHeaders(params.accessToken),
4853
body: (params) => {
4954
const args: string[] = [
50-
`board_id: ${params.boardId}`,
55+
`board_id: ${sanitizeNumericId(params.boardId, 'boardId')}`,
5156
`group_name: ${JSON.stringify(params.groupName)}`,
5257
]
5358
if (params.groupColor) {

apps/sim/tools/monday/create_item.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
import type { MondayCreateItemParams, MondayCreateItemResponse } from '@/tools/monday/types'
2-
import { extractMondayError, MONDAY_API_URL, mondayHeaders } from '@/tools/monday/utils'
2+
import {
3+
extractMondayError,
4+
MONDAY_API_URL,
5+
mondayHeaders,
6+
sanitizeNumericId,
7+
} from '@/tools/monday/utils'
38
import type { ToolConfig } from '@/tools/types'
49

510
export const mondayCreateItemTool: ToolConfig<MondayCreateItemParams, MondayCreateItemResponse> = {
@@ -53,7 +58,7 @@ export const mondayCreateItemTool: ToolConfig<MondayCreateItemParams, MondayCrea
5358
headers: (params) => mondayHeaders(params.accessToken),
5459
body: (params) => {
5560
const args: string[] = [
56-
`board_id: ${params.boardId}`,
61+
`board_id: ${sanitizeNumericId(params.boardId, 'boardId')}`,
5762
`item_name: ${JSON.stringify(params.itemName)}`,
5863
]
5964
if (params.groupId) {

apps/sim/tools/monday/create_subitem.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
import type { MondayCreateSubitemParams, MondayCreateSubitemResponse } from '@/tools/monday/types'
2-
import { extractMondayError, MONDAY_API_URL, mondayHeaders } from '@/tools/monday/utils'
2+
import {
3+
extractMondayError,
4+
MONDAY_API_URL,
5+
mondayHeaders,
6+
sanitizeNumericId,
7+
} from '@/tools/monday/utils'
38
import type { ToolConfig } from '@/tools/types'
49

510
export const mondayCreateSubitemTool: ToolConfig<
@@ -49,7 +54,7 @@ export const mondayCreateSubitemTool: ToolConfig<
4954
headers: (params) => mondayHeaders(params.accessToken),
5055
body: (params) => {
5156
const args: string[] = [
52-
`parent_item_id: ${params.parentItemId}`,
57+
`parent_item_id: ${sanitizeNumericId(params.parentItemId, 'parentItemId')}`,
5358
`item_name: ${JSON.stringify(params.itemName)}`,
5459
]
5560
if (params.columnValues) {

apps/sim/tools/monday/create_update.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
import type { MondayCreateUpdateParams, MondayCreateUpdateResponse } from '@/tools/monday/types'
2-
import { extractMondayError, MONDAY_API_URL, mondayHeaders } from '@/tools/monday/utils'
2+
import {
3+
extractMondayError,
4+
MONDAY_API_URL,
5+
mondayHeaders,
6+
sanitizeNumericId,
7+
} from '@/tools/monday/utils'
38
import type { ToolConfig } from '@/tools/types'
49

510
export const mondayCreateUpdateTool: ToolConfig<
@@ -42,7 +47,7 @@ export const mondayCreateUpdateTool: ToolConfig<
4247
method: 'POST',
4348
headers: (params) => mondayHeaders(params.accessToken),
4449
body: (params) => ({
45-
query: `mutation { create_update(item_id: ${params.itemId}, body: ${JSON.stringify(params.body)}) { id body text_body created_at creator_id item_id } }`,
50+
query: `mutation { create_update(item_id: ${sanitizeNumericId(params.itemId, 'itemId')}, body: ${JSON.stringify(params.body)}) { id body text_body created_at creator_id item_id } }`,
4651
}),
4752
},
4853

apps/sim/tools/monday/delete_item.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
import type { MondayDeleteItemParams, MondayDeleteItemResponse } from '@/tools/monday/types'
2-
import { extractMondayError, MONDAY_API_URL, mondayHeaders } from '@/tools/monday/utils'
2+
import {
3+
extractMondayError,
4+
MONDAY_API_URL,
5+
mondayHeaders,
6+
sanitizeNumericId,
7+
} from '@/tools/monday/utils'
38
import type { ToolConfig } from '@/tools/types'
49

510
export const mondayDeleteItemTool: ToolConfig<MondayDeleteItemParams, MondayDeleteItemResponse> = {
@@ -33,7 +38,7 @@ export const mondayDeleteItemTool: ToolConfig<MondayDeleteItemParams, MondayDele
3338
method: 'POST',
3439
headers: (params) => mondayHeaders(params.accessToken),
3540
body: (params) => ({
36-
query: `mutation { delete_item(item_id: ${params.itemId}) { id } }`,
41+
query: `mutation { delete_item(item_id: ${sanitizeNumericId(params.itemId, 'itemId')}) { id } }`,
3742
}),
3843
},
3944

apps/sim/tools/monday/get_board.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
import type { MondayGetBoardParams, MondayGetBoardResponse } from '@/tools/monday/types'
2-
import { extractMondayError, MONDAY_API_URL, mondayHeaders } from '@/tools/monday/utils'
2+
import {
3+
extractMondayError,
4+
MONDAY_API_URL,
5+
mondayHeaders,
6+
sanitizeNumericId,
7+
} from '@/tools/monday/utils'
38
import type { ToolConfig } from '@/tools/types'
49

510
export const mondayGetBoardTool: ToolConfig<MondayGetBoardParams, MondayGetBoardResponse> = {
@@ -33,7 +38,7 @@ export const mondayGetBoardTool: ToolConfig<MondayGetBoardParams, MondayGetBoard
3338
method: 'POST',
3439
headers: (params) => mondayHeaders(params.accessToken),
3540
body: (params) => ({
36-
query: `query { boards(ids: [${params.boardId}]) { id name description state board_kind items_count url updated_at groups { id title color archived deleted position } columns { id title type } } }`,
41+
query: `query { boards(ids: [${sanitizeNumericId(params.boardId, 'boardId')}]) { id name description state board_kind items_count url updated_at groups { id title color archived deleted position } columns { id title type } } }`,
3742
}),
3843
},
3944

apps/sim/tools/monday/get_item.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
import type { MondayGetItemParams, MondayGetItemResponse } from '@/tools/monday/types'
2-
import { extractMondayError, MONDAY_API_URL, mondayHeaders } from '@/tools/monday/utils'
2+
import {
3+
extractMondayError,
4+
MONDAY_API_URL,
5+
mondayHeaders,
6+
sanitizeNumericId,
7+
} from '@/tools/monday/utils'
38
import type { ToolConfig } from '@/tools/types'
49

510
export const mondayGetItemTool: ToolConfig<MondayGetItemParams, MondayGetItemResponse> = {
@@ -33,7 +38,7 @@ export const mondayGetItemTool: ToolConfig<MondayGetItemParams, MondayGetItemRes
3338
method: 'POST',
3439
headers: (params) => mondayHeaders(params.accessToken),
3540
body: (params) => ({
36-
query: `query { items(ids: [${params.itemId}]) { id name state board { id } group { id title } column_values { id text value type } created_at updated_at url } }`,
41+
query: `query { items(ids: [${sanitizeNumericId(params.itemId, 'itemId')}]) { id name state board { id } group { id title } column_values { id text value type } created_at updated_at url } }`,
3742
}),
3843
},
3944

apps/sim/tools/monday/get_items.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
import type { MondayGetItemsParams, MondayGetItemsResponse } from '@/tools/monday/types'
2-
import { extractMondayError, MONDAY_API_URL, mondayHeaders } from '@/tools/monday/utils'
2+
import {
3+
extractMondayError,
4+
MONDAY_API_URL,
5+
mondayHeaders,
6+
sanitizeNumericId,
7+
} from '@/tools/monday/utils'
38
import type { ToolConfig } from '@/tools/types'
49

510
function mapItem(item: Record<string, unknown>): {
@@ -81,13 +86,14 @@ export const mondayGetItemsTool: ToolConfig<MondayGetItemsParams, MondayGetItems
8186
headers: (params) => mondayHeaders(params.accessToken),
8287
body: (params) => {
8388
const limit = params.limit ?? 25
89+
const boardId = sanitizeNumericId(params.boardId, 'boardId')
8490
if (params.groupId) {
8591
return {
86-
query: `query { boards(ids: [${params.boardId}]) { groups(ids: [${JSON.stringify(params.groupId)}]) { items_page(limit: ${limit}) { items { id name state board { id } group { id title } column_values { id text value type } created_at updated_at url } } } } }`,
92+
query: `query { boards(ids: [${boardId}]) { groups(ids: [${JSON.stringify(params.groupId)}]) { items_page(limit: ${limit}) { items { id name state board { id } group { id title } column_values { id text value type } created_at updated_at url } } } } }`,
8793
}
8894
}
8995
return {
90-
query: `query { boards(ids: [${params.boardId}]) { items_page(limit: ${limit}) { items { id name state board { id } group { id title } column_values { id text value type } created_at updated_at url } } } }`,
96+
query: `query { boards(ids: [${boardId}]) { items_page(limit: ${limit}) { items { id name state board { id } group { id title } column_values { id text value type } created_at updated_at url } } } }`,
9197
}
9298
},
9399
},

apps/sim/tools/monday/move_item_to_group.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,12 @@ import type {
22
MondayMoveItemToGroupParams,
33
MondayMoveItemToGroupResponse,
44
} from '@/tools/monday/types'
5-
import { extractMondayError, MONDAY_API_URL, mondayHeaders } from '@/tools/monday/utils'
5+
import {
6+
extractMondayError,
7+
MONDAY_API_URL,
8+
mondayHeaders,
9+
sanitizeNumericId,
10+
} from '@/tools/monday/utils'
611
import type { ToolConfig } from '@/tools/types'
712

813
export const mondayMoveItemToGroupTool: ToolConfig<
@@ -45,7 +50,7 @@ export const mondayMoveItemToGroupTool: ToolConfig<
4550
method: 'POST',
4651
headers: (params) => mondayHeaders(params.accessToken),
4752
body: (params) => ({
48-
query: `mutation { move_item_to_group(item_id: ${params.itemId}, group_id: ${JSON.stringify(params.groupId)}) { id name state board { id } group { id title } column_values { id text value type } created_at updated_at url } }`,
53+
query: `mutation { move_item_to_group(item_id: ${sanitizeNumericId(params.itemId, 'itemId')}, group_id: ${JSON.stringify(params.groupId)}) { id name state board { id } group { id title } column_values { id text value type } created_at updated_at url } }`,
4954
}),
5055
},
5156

0 commit comments

Comments
 (0)