File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -21,7 +21,17 @@ def _bash_double_quote(value: str) -> str:
2121
2222 We intentionally do NOT escape '$' so that $VARS from config can expand on
2323 compute nodes (e.g. $SCRATCH). This matches typical SLURM job scripts.
24+
25+ To avoid command injection, we reject values containing shell command
26+ substitution syntax such as ``$(...)`` or backticks. Variable expansion
27+ using ``$VAR`` or ``${VAR}`` is still allowed.
2428 """
29+ # Disallow command substitution while still allowing $VAR expansion.
30+ if "`" in value or "$(" in value :
31+ raise ValueError (
32+ "Config value contains unsupported shell command substitution "
33+ "(` or '$('). Command substitution is not allowed in SLURM-generated scripts."
34+ )
2535 escaped = value .replace ("\\ " , "\\ \\ " ).replace ('"' , '\\ "' )
2636 return f'"{ escaped } "'
2737
You can’t perform that action at this time.
0 commit comments