Skip to content

Commit

Permalink
Fix code scanning alert no. 33: Uncontrolled data used in path expres…
Browse files Browse the repository at this point in the history
…sion (#1513)

Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
  • Loading branch information
DoroWolf and github-advanced-security[bot] authored Jan 1, 2025
1 parent afc7598 commit 819872b
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions bots/api/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,9 @@ async def get_config_file(cfg_filename: str):
raise HTTPException(status_code=404, detail="not found")
if not cfg_filename.endswith(".toml"):
raise HTTPException(status_code=400, detail="bad request")
cfg_file_path = os.path.join(config_path, cfg_filename)
cfg_file_path = os.path.normpath(os.path.join(config_path, cfg_filename))
if not cfg_file_path.startswith(config_path):
raise HTTPException(status_code=400, detail="bad request")

try:
with open(cfg_file_path, 'r', encoding='UTF-8') as f:
Expand All @@ -260,7 +262,9 @@ async def edit_config_file(cfg_filename: str, request: Request):
raise HTTPException(status_code=404, detail="not found")
if not cfg_filename.endswith(".toml"):
raise HTTPException(status_code=400, detail="bad request")
cfg_file_path = os.path.join(config_path, cfg_filename)
cfg_file_path = os.path.normpath(os.path.join(config_path, cfg_filename))
if not cfg_file_path.startswith(config_path):
raise HTTPException(status_code=400, detail="bad request")
try:
body = await request.json()
content = body["content"]
Expand Down

0 comments on commit 819872b

Please sign in to comment.