Skip to content

Commit 24a5c8a

Browse files
waleedlatif1claude
andcommitted
fix(monday): deduplicate numeric ID validation, sanitize limit/page params
- Refactor sanitizeNumericId to delegate to validateMondayNumericId from input-validation.ts, eliminating duplicated regex logic - Add sanitizeLimit helper for safe integer coercion with bounds - Apply sanitizeLimit to limit/page params in list_boards, get_items, and search_items for consistent validation across all GraphQL params Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 210cab9 commit 24a5c8a

File tree

4 files changed

+29
-11
lines changed

4 files changed

+29
-11
lines changed

apps/sim/tools/monday/get_items.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import {
33
extractMondayError,
44
MONDAY_API_URL,
55
mondayHeaders,
6+
sanitizeLimit,
67
sanitizeNumericId,
78
} from '@/tools/monday/utils'
89
import type { ToolConfig } from '@/tools/types'
@@ -85,7 +86,7 @@ export const mondayGetItemsTool: ToolConfig<MondayGetItemsParams, MondayGetItems
8586
method: 'POST',
8687
headers: (params) => mondayHeaders(params.accessToken),
8788
body: (params) => {
88-
const limit = params.limit ?? 25
89+
const limit = sanitizeLimit(params.limit, 25, 500)
8990
const boardId = sanitizeNumericId(params.boardId, 'boardId')
9091
if (params.groupId) {
9192
return {

apps/sim/tools/monday/list_boards.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
import type { MondayListBoardsParams, MondayListBoardsResponse } 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+
sanitizeLimit,
7+
} from '@/tools/monday/utils'
38
import type { ToolConfig } from '@/tools/types'
49

510
export const mondayListBoardsTool: ToolConfig<MondayListBoardsParams, MondayListBoardsResponse> = {
@@ -39,8 +44,8 @@ export const mondayListBoardsTool: ToolConfig<MondayListBoardsParams, MondayList
3944
method: 'POST',
4045
headers: (params) => mondayHeaders(params.accessToken),
4146
body: (params) => {
42-
const limit = params.limit ?? 25
43-
const page = params.page ?? 1
47+
const limit = sanitizeLimit(params.limit, 25, 500)
48+
const page = sanitizeLimit(params.page, 1, 10000)
4449
return {
4550
query: `query { boards(limit: ${limit}, page: ${page}, state: active) { id name description state board_kind items_count url updated_at } }`,
4651
}

apps/sim/tools/monday/search_items.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import {
33
extractMondayError,
44
MONDAY_API_URL,
55
mondayHeaders,
6+
sanitizeLimit,
67
sanitizeNumericId,
78
} from '@/tools/monday/utils'
89
import type { ToolConfig } from '@/tools/types'
@@ -58,7 +59,7 @@ export const mondaySearchItemsTool: ToolConfig<MondaySearchItemsParams, MondaySe
5859
method: 'POST',
5960
headers: (params) => mondayHeaders(params.accessToken),
6061
body: (params) => {
61-
const limit = params.limit ?? 25
62+
const limit = sanitizeLimit(params.limit, 25, 500)
6263
if (params.cursor) {
6364
return {
6465
query: `query { next_items_page(limit: ${limit}, cursor: ${JSON.stringify(params.cursor)}) { cursor items { id name state board { id } group { id title } column_values { id text value type } created_at updated_at url } } }`,

apps/sim/tools/monday/utils.ts

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { validateMondayNumericId } from '@/lib/core/security/input-validation'
2+
13
export const MONDAY_API_URL = 'https://api.monday.com/v2'
24

35
export function mondayHeaders(accessToken: string): Record<string, string> {
@@ -9,15 +11,24 @@ export function mondayHeaders(accessToken: string): Record<string, string> {
911
}
1012

1113
/**
12-
* Validates that a Monday.com numeric ID (boardId, itemId, etc.) contains only digits.
13-
* Throws with a user-friendly message if invalid, preventing GraphQL injection.
14+
* Validates a Monday.com numeric ID and returns the sanitized string.
15+
* Delegates to validateMondayNumericId; throws on invalid input.
1416
*/
1517
export function sanitizeNumericId(value: string | number, paramName: string): string {
16-
const str = String(value).trim()
17-
if (!/^\d+$/.test(str)) {
18-
throw new Error(`${paramName} must be a numeric integer`)
18+
const result = validateMondayNumericId(value, paramName)
19+
if (!result.isValid) {
20+
throw new Error(result.error!)
1921
}
20-
return str
22+
return result.sanitized!
23+
}
24+
25+
/**
26+
* Coerces a limit/page param to a safe integer within bounds.
27+
*/
28+
export function sanitizeLimit(value: number | undefined, defaultVal: number, max: number): number {
29+
const n = Number(value ?? defaultVal)
30+
if (!Number.isFinite(n) || n < 1) return defaultVal
31+
return Math.min(n, max)
2132
}
2233

2334
export function extractMondayError(data: Record<string, unknown>): string | null {

0 commit comments

Comments
 (0)