Potential fix for code scanning alert no. 427: Uncontrolled data used in path expression#2362
Merged
Potential fix for code scanning alert no. 427: Uncontrolled data used in path expression#2362
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 path traversal security vulnerability (code scanning alert #427) by implementing input validation for user-supplied template paths in the get_prompt_template function.
Key changes:
- Adds path validation logic to restrict file access to a safe root directory (
/templates) - Implements path normalization and bounds checking before reading template files
- Adds explicit error handling for invalid paths and missing files
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
chensuyue
approved these changes
Dec 15, 2025
lvliang-intel
approved these changes
Dec 15, 2025
cogniware-devops
pushed a commit
to Cogniware-Inc/GenAIExamples
that referenced
this pull request
Dec 19, 2025
… in path expression (opea-project#2362) Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.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#2362) Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.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#2362) Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.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/427
#2352
test pass https://github.com/opea-project/GenAIExamples/actions/runs/20253422487
How to, in general terms, fix the problem:
Paths provided by untrusted users must be checked before use. A common solution is to restrict file access to a known-safe directory. This is typically implemented by joining the user-supplied path to a safe root, normalizing the path, and ensuring the result still points inside the intended directory.
Detailed description of the single best way to fix the problem without changing existing functionality:
get_prompt_template, before usingPath(template_path).read_text, validate or restricttemplate_path.QnAGenerator.prompt_handler: define a trusted root (e.g.,/templates), join and normalize the path, and verify that the resulting path starts with the root.EdgeCraftRAG/edgecraftrag/utils.pyin theget_prompt_templatemethod, surrounding or replacing the existing read logic fortemplate_path.What is needed:
os.pathif not present (already present).get_prompt_template.Suggested fixes powered by Copilot Autofix. Review carefully before merging.