Potential fix for code scanning alert no. 58: Uncontrolled data used in path expression #310
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Potential fix for https://github.com/intel/AI-PC-Samples/security/code-scanning/58
The best way to fix this problem is to validate the path supplied by the user before using it with any file system operations, such as
os.walk. You should define an application-level root directory (a "safe root folder") into which user-provided paths must be confined. Before proceeding with traversal, the code should:os.path.abspath(os.path.join(BASE_ROOT, user_input))(or similar).os.path.normpathto remove any..or redundant segments.Specifically for this file:
SAFE_DATASET_ROOTat the top of the file (near other constants), pointing to a directory intended for safe storage of datasets, such as'./datasets'. Ensure the directory exists (create it if not).get_video_paths, combine the folder argument from the user input with the safe root, normalize it, and validate it.os.walkif validation passes, otherwise raise/log a warning or error.You'll need to:
osif not present (already present).SAFE_DATASET_ROOT(e.g.,./datasets) at the top.get_video_paths, implement the normalization and safety check.Suggested fixes powered by Copilot Autofix. Review carefully before merging.