Skip to content

Commit c4c23c9

Browse files
qchappCopilot
andauthored
Update src/mmirage/cli_utils/slurm.py
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent ce41693 commit c4c23c9

1 file changed

Lines changed: 10 additions & 0 deletions

File tree

src/mmirage/cli_utils/slurm.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff 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

0 commit comments

Comments
 (0)