2dos / DK64-Randomizer

Python script that randomizes various things in DK64. See the readme for current options that are available to be randomized as well as other features.
https://dk64randomizer.com/
MIT License
52 stars 29 forks source link

Fix code scanning alert no. 40: Uncontrolled data used in path expression #2172

Closed Killklli closed 2 weeks ago

Killklli commented 2 weeks ago

Fixes https://github.com/2dos/DK64-Randomizer/security/code-scanning/40

To fix the problem, we need to ensure that the constructed file path is contained within a safe root folder. We can achieve this by normalizing the path using os.path.normpath and then checking that the normalized path starts with the root folder. Additionally, we should use werkzeug.utils.secure_filename to sanitize the hash parameter to eliminate any special characters.

  1. Import secure_filename from werkzeug.utils.
  2. Use secure_filename to sanitize the hash parameter.
  3. Normalize the constructed file path using os.path.normpath.
  4. Check that the normalized path starts with the root folder.

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