-
Notifications
You must be signed in to change notification settings - Fork 332
Potential fix for code scanning alert no. 427: Uncontrolled data used in path expression #2362
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
… 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>
… 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>
… 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>
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.