fix uncontrolled data used in path expression
https://github.com/microsoft/OmniParser/blob/efbb1f4518462c3b6f581f39d558b0fbfe840678/omnitool/gradio/app_new.py#L317-L319
https://github.com/microsoft/OmniParser/blob/efbb1f4518462c3b6f581f39d558b0fbfe840678/omnitool/gradio/app_new.py#L423-L423
Accessing files using paths constructed from user-controlled data can allow an attacker to access unexpected resources. This can result in sensitive information being revealed or deleted, or an attacker being able to influence behavior by modifying unexpected files. werkzeug.utils.secure_filename.
Fix the issue we need to validate the file_path to ensure it is safe before using it in file operations. The best approach is to:
- Define a safe root directory where all file operations are allowed.
- Normalize the
file_pathusingos.path.normpathoros.path.realpathto remove any..segments or symbolic links. - Verify that the normalized path is within the safe root directory.
This ensures that even if a user provides a malicious path, it will not escape the designated safe directory.