Skip to content

Commit

Permalink
Merge pull request #9 from jxfzzzt/main
Browse files Browse the repository at this point in the history
Fix Path Traversal issue
  • Loading branch information
vemonet authored Nov 12, 2024
2 parents 84b9288 + d450629 commit dbb8e34
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/libre_chat/router.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from dataclasses import dataclass
from typing import Any, Dict, List, Optional, Union

import werkzeug
from fastapi import APIRouter, Body, File, HTTPException, Request, UploadFile, WebSocket
from fastapi.responses import JSONResponse
from langchain.callbacks.base import AsyncCallbackHandler
Expand Down Expand Up @@ -123,7 +124,13 @@ def upload_documents(
)
for uploaded in files:
if uploaded.filename: # no cov
file_path = os.path.join(self.conf.vector.documents_path, uploaded.filename)
file_path = werkzeug.utils.safe_join(self.conf.vector.documents_path, uploaded.filename)
if file_path is None:
raise HTTPException(
status_code=403,
detail=f"Invalid file name: {uploaded.filename}",
)

with open(file_path, "wb") as file:
file.write(uploaded.file.read())
# Check if the uploaded file is a zip file
Expand Down

0 comments on commit dbb8e34

Please sign in to comment.