Skip to content

Commit b57e767

Browse files
authored
fix: escape user input before shelling out command (#17953)
1 parent 2c00a1d commit b57e767

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

llama-index-cli/llama_index/cli/rag/base.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import asyncio
22
import os
3+
import shlex
34
import shutil
45
from argparse import ArgumentParser
56
from glob import iglob
@@ -14,8 +15,8 @@
1415
from llama_index.core.base.embeddings.base import BaseEmbedding
1516
from llama_index.core.base.response.schema import (
1617
RESPONSE_TYPE,
17-
StreamingResponse,
1818
Response,
19+
StreamingResponse,
1920
)
2021
from llama_index.core.bridge.pydantic import BaseModel, Field, field_validator
2122
from llama_index.core.chat_engine import CondenseQuestionChatEngine
@@ -159,7 +160,7 @@ def chat_engine_from_query_pipeline(
159160
if chat_engine is not None:
160161
return chat_engine
161162

162-
if values.get("query_pipeline", None) is None:
163+
if values.get("query_pipeline") is None:
163164
values["query_pipeline"] = cls.query_pipeline_from_ingestion_pipeline(
164165
query_pipeline=None, values=values
165166
)
@@ -231,7 +232,8 @@ async def handle_cli(
231232

232233
# Append the `--files` argument to the history file
233234
with open(f"{self.persist_dir}/{RAG_HISTORY_FILE_NAME}", "a") as f:
234-
f.write(str(files) + "\n")
235+
for file in files:
236+
f.write(str(file) + "\n")
235237

236238
if create_llama:
237239
if shutil.which("npx") is None:
@@ -289,7 +291,7 @@ async def handle_cli(
289291
"none",
290292
"--engine",
291293
"context",
292-
f"--files {path}",
294+
f"--files {shlex.quote(path)}",
293295
]
294296
os.system(" ".join(command_args))
295297

llama-index-cli/pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ disallow_untyped_defs = true
1414
# Remove venv skip when integrated with pre-commit
1515
exclude = ["_static", "build", "examples", "notebooks", "venv"]
1616
ignore_missing_imports = true
17-
python_version = "3.8"
17+
python_version = "3.9"
1818

1919
[tool.poetry]
2020
authors = ["llamaindex"]
@@ -32,7 +32,7 @@ maintainers = [
3232
name = "llama-index-cli"
3333
packages = [{include = "llama_index/"}]
3434
readme = "README.md"
35-
version = "0.4.0"
35+
version = "0.4.1"
3636

3737
[tool.poetry.dependencies]
3838
python = ">=3.9,<4.0"

0 commit comments

Comments
 (0)