Staging rebase#41
Merged
Merged
Conversation
…n path expression Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
…n path expression Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
Potential fix for code scanning alert no. 8: Uncontrolled data used in path expression
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR enhances security by validating output file paths in the interview API and overhauls the README for improved structure, clarity, and user guidance.
- Added a
.resolve()call and path traversal check incomplete_interviewto restrict output files toOUTPUT_DIR - Fully rewrote and reorganized
README.mdwith new sections (mission, features, setup) and streamlined content
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| src/digital_persona/api.py | Added absolute resolution of out_path and a security check to prevent path traversal |
| README.md | Reorganized documentation, added new sections, updated examples |
| ) | ||
| out_path = OUTPUT_DIR / (Path(req.file).stem + ".json") | ||
| out_path = (OUTPUT_DIR / (Path(req.file).stem + ".json")).resolve() | ||
| if not str(out_path).startswith(str(OUTPUT_DIR)): |
There was a problem hiding this comment.
Instead of a string prefix check, resolve OUTPUT_DIR and use out_path.is_relative_to(resolved_output_dir) to robustly verify that out_path is inside OUTPUT_DIR, preventing bypasses via symlinks or similar prefixes.
| import json | ||
|
|
||
| data = """Email: I'm looking forward to the team retreat next month. | ||
| data = """Email: I'm looking forward to the team retreat next month.\n |
There was a problem hiding this comment.
[nitpick] The triple-quoted string preserves line breaks, so the explicit "\n" is redundant; consider removing it to simplify the example.
Suggested change
| data = """Email: I'm looking forward to the team retreat next month.\n | |
| data = """Email: I'm looking forward to the team retreat next month. |
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.
This pull request updates the
README.mdfile to improve clarity, structure, and user guidance while also adding a security check in thesrc/digital_persona/api.pyfile to validate file paths. Below is a summary of the most important changes:Documentation Improvements:
README.mdfile has been rewritten for better readability and organization. It now includes clearer descriptions of the project, its mission, features, architecture, and development setup. New sections such as "What is a Digital Persona?" and "Features and Architecture" have been added to provide a more comprehensive overview.Security Enhancements:
complete_interviewfunction insrc/digital_persona/api.pyto ensure that output file paths are restricted to theOUTPUT_DIRdirectory. This prevents potential path traversal vulnerabilities.