Skip to content

Commit a0fd7c8

Browse files
committed
improvement(inputs): sanitize trigger inputs better
1 parent 0d0209a commit a0fd7c8

File tree

2 files changed

+34
-19
lines changed

2 files changed

+34
-19
lines changed

apps/sim/executor/execution/block-executor.ts

Lines changed: 33 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {
44
containsUserFileWithMetadata,
55
hydrateUserFilesWithBase64,
66
} from '@/lib/uploads/utils/user-file-base64.server'
7+
import { sanitizeInputFormat, sanitizeTools } from '@/lib/workflows/comparison/normalize'
78
import {
89
BlockType,
910
buildResumeApiUrl,
@@ -34,6 +35,7 @@ import { validateBlockType } from '@/executor/utils/permission-check'
3435
import type { VariableResolver } from '@/executor/variables/resolver'
3536
import type { SerializedBlock } from '@/serializer/types'
3637
import type { SubflowType } from '@/stores/workflows/workflow/types'
38+
import { SYSTEM_SUBBLOCK_IDS } from '@/triggers/constants'
3739

3840
const logger = createLogger('BlockExecutor')
3941

@@ -87,7 +89,7 @@ export class BlockExecutor {
8789
resolvedInputs = this.resolver.resolveInputs(ctx, node.id, block.config.params, block)
8890

8991
if (blockLog) {
90-
blockLog.input = this.parseJsonInputs(resolvedInputs)
92+
blockLog.input = this.sanitizeInputsForLog(resolvedInputs)
9193
}
9294
} catch (error) {
9395
cleanupSelfReference?.()
@@ -162,7 +164,7 @@ export class BlockExecutor {
162164
ctx,
163165
node,
164166
block,
165-
this.parseJsonInputs(resolvedInputs),
167+
this.sanitizeInputsForLog(resolvedInputs),
166168
displayOutput,
167169
duration
168170
)
@@ -241,7 +243,7 @@ export class BlockExecutor {
241243
blockLog.durationMs = duration
242244
blockLog.success = false
243245
blockLog.error = errorMessage
244-
blockLog.input = this.parseJsonInputs(input)
246+
blockLog.input = this.sanitizeInputsForLog(input)
245247
blockLog.output = filterOutputForLog(block.metadata?.id || '', errorOutput, { block })
246248
}
247249

@@ -260,7 +262,7 @@ export class BlockExecutor {
260262
ctx,
261263
node,
262264
block,
263-
this.parseJsonInputs(input),
265+
this.sanitizeInputsForLog(input),
264266
displayOutput,
265267
duration
266268
)
@@ -352,29 +354,41 @@ export class BlockExecutor {
352354
}
353355

354356
/**
355-
* Parse JSON string inputs to objects for log display only.
356-
* Attempts to parse any string that looks like JSON.
357+
* Sanitizes inputs for log display.
358+
* - Filters out system fields (UI-only, readonly, internal flags)
359+
* - Removes UI state from inputFormat items (e.g., collapsed)
360+
* - Parses JSON strings to objects for readability
357361
* Returns a new object - does not mutate the original inputs.
358362
*/
359-
private parseJsonInputs(inputs: Record<string, any>): Record<string, any> {
360-
let result = inputs
361-
let hasChanges = false
363+
private sanitizeInputsForLog(inputs: Record<string, any>): Record<string, any> {
364+
const result: Record<string, any> = {}
362365

363366
for (const [key, value] of Object.entries(inputs)) {
364-
// isJSONString is a quick heuristic (checks for { or [), not a validator.
365-
// Invalid JSON is safely caught below - this just avoids JSON.parse on every string.
366-
if (typeof value !== 'string' || !isJSONString(value)) {
367+
if (SYSTEM_SUBBLOCK_IDS.includes(key) || key === 'triggerMode') {
367368
continue
368369
}
369370

370-
try {
371-
if (!hasChanges) {
372-
result = { ...inputs }
373-
hasChanges = true
371+
if (key === 'inputFormat' && Array.isArray(value)) {
372+
result[key] = sanitizeInputFormat(value)
373+
continue
374+
}
375+
376+
if (key === 'tools' && Array.isArray(value)) {
377+
result[key] = sanitizeTools(value)
378+
continue
379+
}
380+
381+
// isJSONString is a quick heuristic (checks for { or [), not a validator.
382+
// Invalid JSON is safely caught below - this just avoids JSON.parse on every string.
383+
if (typeof value === 'string' && isJSONString(value)) {
384+
try {
385+
result[key] = JSON.parse(value.trim())
386+
} catch {
387+
// Not valid JSON, keep original string
388+
result[key] = value
374389
}
375-
result[key] = JSON.parse(value.trim())
376-
} catch {
377-
// Not valid JSON, keep original string
390+
} else {
391+
result[key] = value
378392
}
379393
}
380394

apps/sim/triggers/constants.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ export const SYSTEM_SUBBLOCK_IDS: string[] = [
1010
'webhookUrlDisplay', // Webhook URL display
1111
'samplePayload', // Example payload display
1212
'setupScript', // Setup script code (e.g., Apps Script)
13+
'scheduleInfo', // Schedule status display (next run, last run)
1314
]
1415

1516
/**

0 commit comments

Comments
 (0)