Skip to content

Commit eed5c2a

Browse files
authored
Potential fix for code scanning alert no. 29: Uncontrolled data used in path expression (#2363)
Signed-off-by: ZePan110 <[email protected]>
1 parent aef896b commit eed5c2a

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

CodeGen/ui/gradio/codegen_ui_gradio.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,13 @@ def generate_code(query, index=None, use_agent=False):
164164

165165
def ingest_file(file, index=None, chunk_size=100, chunk_overlap=150):
166166
headers = {}
167-
file_input = {"files": open(file, "rb")}
167+
# Restrict file access to UPLOAD_ROOT directory
168+
UPLOAD_ROOT = os.path.abspath("./")
169+
normalized_path = os.path.normpath(os.path.join(UPLOAD_ROOT, file))
170+
# Ensure the constructed path is still within the upload root
171+
if not normalized_path.startswith(UPLOAD_ROOT):
172+
raise Exception("Access to the specified file is not allowed.")
173+
file_input = {"files": open(normalized_path, "rb")}
168174

169175
if index:
170176
data = {"index_name": index, "chunk_size": chunk_size, "chunk_overlap": chunk_overlap}

0 commit comments

Comments
 (0)