Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Path Traversal issue #9

Merged
merged 1 commit into from
Nov 12, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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