Skip to content

Commit

Permalink
fix: 解决CI告警问题
Browse files Browse the repository at this point in the history
  • Loading branch information
hanxi committed Jul 14, 2024
1 parent 34bfbee commit 861999f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
3 changes: 3 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
FROM python:3.10 AS builder
ENV DEBIAN_FRONTEND=noninteractive
WORKDIR /app
RUN curl https://sh.rustup.rs -sSf | \
sh -s -- --default-toolchain stable -y
ENV PATH=/root/.cargo/bin:$PATH
COPY requirements.txt .
RUN python3 -m venv .venv && .venv/bin/pip install --upgrade pip && .venv/bin/pip install --no-cache-dir -r requirements.txt
COPY install_dependencies.sh .
Expand Down
13 changes: 6 additions & 7 deletions xiaomusic/httpserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,19 +88,18 @@ def HttpInit(_xiaomusic):

@app.get("/music/{file_path:path}")
async def read_music_file(file_path: str):
base_dir = Path(config.music_path).resolve()
base_dir = os.path.abspath(config.music_path)
real_path = os.path.normpath(os.path.join(base_dir, file_path))
file_location = Path(real_path).resolve()
log.info(f"read_music_file. file_path:{file_path} real_path:{real_path}")
if not file_location.exists() or not file_location.is_file():
raise HTTPException(status_code=404, detail="File not found")

# 确保请求的文件在我们的基础目录下
if base_dir not in file_location.parents:
if not real_path.startswith(base_dir):
raise HTTPException(
status_code=403, detail="Access to this file is not permitted"
)

file_location = Path(real_path).resolve()
if not file_location.exists() or not file_location.is_file():
raise HTTPException(status_code=404, detail="File not found")

return FileResponse(file_location)


Expand Down

0 comments on commit 861999f

Please sign in to comment.