Skip to content

Commit 602339c

Browse files
committed
fix(function): validate custom tool param keys before code interpolation
1 parent 7b6aa72 commit 602339c

1 file changed

Lines changed: 5 additions & 2 deletions

File tree

  • apps/sim/app/api/function/execute

apps/sim/app/api/function/execute/route.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1089,18 +1089,21 @@ export const POST = withRouteHandler(async (req: NextRequest) => {
10891089

10901090
const executionMethod = 'isolated-vm'
10911091

1092+
const SAFE_IDENTIFIER = /^[a-zA-Z_][a-zA-Z0-9_]*$/
10921093
const wrapperLines = ['(async () => {', ' try {']
10931094
if (isCustomTool) {
10941095
Object.keys(executionParams).forEach((key) => {
1095-
wrapperLines.push(` const ${key} = params.${key};`)
1096+
if (SAFE_IDENTIFIER.test(key)) {
1097+
wrapperLines.push(` const ${key} = params.${key};`)
1098+
}
10961099
})
10971100
}
10981101
userCodeStartLine = wrapperLines.length + 1
10991102

11001103
let codeToExecute = resolvedCode
11011104
let prependedLineCount = 0
11021105
if (isCustomTool) {
1103-
const paramKeys = Object.keys(executionParams)
1106+
const paramKeys = Object.keys(executionParams).filter((key) => SAFE_IDENTIFIER.test(key))
11041107
const paramDestructuring = paramKeys.map((key) => `const ${key} = params.${key};`).join('\n')
11051108
codeToExecute = `${paramDestructuring}\n${resolvedCode}`
11061109
prependedLineCount = paramKeys.length

0 commit comments

Comments
 (0)