GSA / FedRAMP-OllaLab-Lean

The OllaLab-Lean project is designed to help both novice and experienced developers rapidly set up and begin working on LLM-based projects.
Creative Commons Zero v1.0 Universal
17 stars 5 forks source link

Fix code scanning alert no. 7: Uncontrolled data used in path expression #10

Closed Cybonto closed 4 weeks ago

Cybonto commented 4 weeks ago

Fixes https://github.com/GSA/FedRAMP-OllaLab-Lean/security/code-scanning/7

To fix the problem, we need to ensure that the constructed file path is contained within a safe root folder. This can be achieved by normalizing the path using os.path.normpath and then checking that the normalized path starts with the BASE_DIR. This approach will prevent path traversal attacks by ensuring that the user cannot escape the intended directory.

  1. Normalize the folder_path using os.path.normpath.
  2. Check that the normalized folder_path starts with BASE_DIR.
  3. If the check fails, raise an exception or show an error message.

Suggested fixes powered by Copilot Autofix. Review carefully before merging.