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. 24: Uncontrolled data used in path expression #2174

Closed Killklli closed 2 weeks ago

Killklli commented 2 weeks ago

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

To fix the problem, we need to ensure that the constructed file path is securely validated. This involves normalizing the path and ensuring it remains within the intended directory. We will use os.path.normpath to normalize the path and then check that the normalized path starts with the intended base directory. This approach will prevent directory traversal attacks by ensuring that any ".." segments are resolved and the path remains within the allowed directory.

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