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 28 forks source link

Fix code scanning alert no. 41: Uncontrolled data used in path expression #2171

Closed Killklli closed 1 week ago

Killklli commented 1 week ago

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

To fix the problem, we need to ensure that the constructed file path is securely validated before being used. This involves normalizing the path and ensuring it is contained within a safe root directory. We will use os.path.realpath to resolve the absolute path and then check that it starts with the intended directory.

  1. Normalize the path using os.path.realpath to remove any ".." segments.
  2. Check that the normalized path starts with the generated_seeds/ directory.
  3. Update the code to use the validated path for file operations.

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