Potential fix for code scanning alert no. 29: Uncontrolled data used in path expression#2363
Merged
Potential fix for code scanning alert no. 29: Uncontrolled data used in path expression#2363
Conversation
…in path expression Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
Dependency Review✅ No vulnerabilities or license issues found.Scanned FilesNone |
Contributor
There was a problem hiding this comment.
Pull request overview
This PR addresses a security vulnerability (code scanning alert #29) by implementing path traversal protection in the file upload functionality. The fix restricts file access to a predefined upload directory and validates that user-supplied paths cannot escape this boundary.
Key Changes:
- Added path normalization and validation before opening user-supplied file paths
- Implemented security checks to prevent directory traversal attacks
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
for more information, see https://pre-commit.ci
lvliang-intel
approved these changes
Dec 16, 2025
yao531441
approved these changes
Dec 16, 2025
cogniware-devops
pushed a commit
to Cogniware-Inc/GenAIExamples
that referenced
this pull request
Dec 19, 2025
…in path expression (opea-project#2363) Signed-off-by: ZePan110 <ze.pan@intel.com> Signed-off-by: cogniware-devops <ambarish.desai@cogniware.ai>
cogniware-devops
pushed a commit
to Cogniware-Inc/GenAIExamples
that referenced
this pull request
Dec 19, 2025
…in path expression (opea-project#2363) Signed-off-by: ZePan110 <ze.pan@intel.com> Signed-off-by: cogniware-devops <ambarish.desai@cogniware.ai>
cogniware-devops
pushed a commit
to Cogniware-Inc/GenAIExamples
that referenced
this pull request
Dec 19, 2025
…in path expression (opea-project#2363) Signed-off-by: ZePan110 <ze.pan@intel.com> Signed-off-by: cogniware-devops <ambarish.desai@cogniware.ai>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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/opea-project/GenAIExamples/security/code-scanning/29
To fix uncontrolled path usage, restrict file access to a predefined and safe upload directory. Normalize and validate the user-supplied path before using it, ensuring that it does not escape the intended directory via path traversal or absolute paths.
Specifically:
UPLOAD_ROOT, set to a directory dedicated to file uploads (e.g.,"./uploads").os.path.normpathto normalize the path.os.path.All these changes must be done within the context of the provided file. The main change is in
ingest_file, adding a check beforeopen(file, "rb")and rewriting the use of the user input path.Suggested fixes powered by Copilot Autofix. Review carefully before merging.