-
Notifications
You must be signed in to change notification settings - Fork 0
🛡️ Sentinel: [HIGH] Fix path traversal validation logic and SafeStaticFiles exceptions #97
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| 1. Modify `src/audioformation/utils/security.py` using `replace_with_git_merge_diff` to rewrite `validate_path_within` to use `Path.resolve().is_relative_to()` and catch `(TypeError, ValueError, RuntimeError, AttributeError, OSError)`. | ||
| 2. Verify the changes to `src/audioformation/utils/security.py` by using `run_in_bash_session` with `cat src/audioformation/utils/security.py`. | ||
| 3. Modify `src/audioformation/server/app.py` using `replace_with_git_merge_diff` to add `path is not None` check and `try...except` wrapper in `SafeStaticFiles.get_response` method. | ||
| 4. Verify the changes to `src/audioformation/server/app.py` by using `run_in_bash_session` with `cat src/audioformation/server/app.py`. | ||
| 5. Run the required tests by using `run_in_bash_session` with `uv run pytest tests/ -k 'not test_e2e_pipeline and not test_server and not test_xtts'`. | ||
| 6. Run code style checks by using `run_in_bash_session` with `uv run ruff check` and `uv run ruff format`. | ||
| 7. Update `.jules/sentinel.md` by using `run_in_bash_session` to run `cat << 'EOF' >> .jules/sentinel.md` with the new learning entry. | ||
| 8. Complete pre-commit steps to ensure proper testing, verification, review, and reflection are done. | ||
| 9. Submit PR using the `submit` tool with branch name `sentinel-fix-path-traversal` and title `🛡️ Sentinel: [HIGH] Fix path traversal validation logic and SafeStaticFiles exceptions`. | ||
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -24,11 +24,19 @@ class SafeStaticFiles(StaticFiles): | |||||||||
|
|
||||||||||
| async def get_response(self, path: str, scope) -> Response: | ||||||||||
| # Normalize path for check | ||||||||||
| p = Path(str(path).lower()) | ||||||||||
| if "00_config" in p.parts or p.name.startswith(".env") or ".git" in p.parts: | ||||||||||
| raise HTTPException( | ||||||||||
| status_code=403, detail="Access denied to sensitive resource" | ||||||||||
| ) | ||||||||||
| if path is None: | ||||||||||
| raise HTTPException(status_code=400, detail="Invalid path") | ||||||||||
|
|
||||||||||
| try: | ||||||||||
| p = Path(str(path).lower()) | ||||||||||
| if "00_config" in p.parts or p.name.startswith(".env") or ".git" in p.parts: | ||||||||||
| raise HTTPException( | ||||||||||
| status_code=403, detail="Access denied to sensitive resource" | ||||||||||
| ) | ||||||||||
| except HTTPException: | ||||||||||
| raise | ||||||||||
| except Exception: | ||||||||||
| raise HTTPException(status_code=400, detail="Invalid path format") | ||||||||||
|
Comment on lines
+38
to
+39
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For better precision and consistency with the implementation in
Suggested change
|
||||||||||
|
|
||||||||||
| return await super().get_response(path, scope) | ||||||||||
|
|
||||||||||
|
|
||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| 1. **Fix path validation in `src/audioformation/utils/security.py`** | ||
| - Replace string-based manipulation (`os.path.abspath` and `startswith`) with strict `Path.resolve().is_relative_to()`. | ||
| - Update the exception catching to handle `(TypeError, ValueError, RuntimeError, AttributeError, OSError)` to fail closed securely on malformed inputs. | ||
| 2. **Hardening `SafeStaticFiles` in `src/audioformation/server/app.py`** | ||
| - Explicitly validate that `path` is not None. | ||
| - Wrap the path normalization in a `try...except` block, raising `HTTPException(status_code=400)` to ensure it fails closed securely on malformed inputs. | ||
| 3. **Verify code changes** | ||
| - Run `uv run pytest tests/` with the required flags to ensure no tests break. | ||
| - Run `uv run ruff check` and `uv run ruff format` to ensure code style is maintained. | ||
| 4. **Update `.jules/sentinel.md`** | ||
| - Add a journal entry documenting the learning about replacing `os.path.abspath` checks with strict `Path.resolve()` for symlink handling, and failing closed on exceptions. | ||
| 5. **Complete pre-commit steps** | ||
| - Complete pre-commit steps to ensure proper testing, verification, review, and reflection are done. | ||
| 6. **Submit PR** | ||
| - Submit the PR with the title `🛡️ Sentinel: [HIGH] Fix path traversal validation logic`. | ||
|
Comment on lines
+1
to
+15
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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.
This file appears to be an internal execution plan for the automated agent and should not be committed to the repository. Please remove it before merging to keep the codebase clean.