File tree Expand file tree Collapse file tree
apps/sim/app/api/function/execute Expand file tree Collapse file tree Original file line number Diff line number Diff 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 - z A - Z _ ] [ a - z A - Z 0 - 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
You can’t perform that action at this time.
0 commit comments