Skip to content

Commit 286e9d7

Browse files
committed
Fix shell var injection
1 parent 36ab581 commit 286e9d7

File tree

1 file changed

+19
-12
lines changed
  • apps/sim/app/api/function/execute

1 file changed

+19
-12
lines changed

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

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -739,18 +739,25 @@ export async function POST(req: NextRequest) {
739739

740740
const lang = isValidCodeLanguage(language) ? language : DEFAULT_CODE_LANGUAGE
741741

742-
const codeResolution = resolveCodeVariables(
743-
code,
744-
executionParams,
745-
envVars,
746-
blockData,
747-
blockNameMapping,
748-
blockOutputSchemas,
749-
workflowVariables,
750-
lang
751-
)
752-
resolvedCode = codeResolution.resolvedCode
753-
const contextVariables = codeResolution.contextVariables
742+
let contextVariables: Record<string, unknown> = {}
743+
if (lang === CodeLanguage.Shell) {
744+
// For shell, env vars are injected as OS env vars via shellEnvs.
745+
// Replace {{VAR}} placeholders with $VAR so the shell can access them natively.
746+
resolvedCode = code.replace(/\{\{([A-Za-z_][A-Za-z0-9_]*)\}\}/g, '$$$1')
747+
} else {
748+
const codeResolution = resolveCodeVariables(
749+
code,
750+
executionParams,
751+
envVars,
752+
blockData,
753+
blockNameMapping,
754+
blockOutputSchemas,
755+
workflowVariables,
756+
lang
757+
)
758+
resolvedCode = codeResolution.resolvedCode
759+
contextVariables = codeResolution.contextVariables
760+
}
754761

755762
let jsImports = ''
756763
let jsRemainingCode = resolvedCode

0 commit comments

Comments
 (0)