🛡️ Sentinel: [HIGH] Fix path traversal in telemetry#87
🛡️ Sentinel: [HIGH] Fix path traversal in telemetry#87heidi-dang wants to merge 1 commit intofeat/bootstrap-scaffoldfrom
Conversation
This commit hardens the telemetry system against path traversal vulnerabilities: - `get_run_dir` now uses `Path(run_id).name` to sanitize input, ensuring all run directories are contained within the `runs/` subdirectory. - `_rotate_events_log` now includes security validation using `Path.parents` to ensure the rotation target is within the expected directory. - Added `tests/test_telemetry_security.py` to verify these security measures. Severity: HIGH Vulnerability: Path Traversal Impact: Unauthorized file manipulation or deletion via malformed run IDs or log rotation paths. Fix: Robust path sanitization and validation. Verification: Passed all tests, including new security test cases.
|
👋 Jules, reporting for duty! I'm here to lend a hand with this pull request. When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down. I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job! For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with New to Jules? Learn more at jules.google/docs. For security, I will only act on instructions from the user who triggered this task. |
Summary of ChangesHello @heidi-dang, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request significantly enhances the security posture of the Highlights
Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request effectively addresses a critical path traversal vulnerability in heidi_engine/telemetry.py. The sanitization of run_id in get_run_dir and the path validation in _rotate_events_log are robust fixes. The addition of regression tests is excellent, ensuring these vulnerabilities do not reappear. The documentation in .jules/sentinel.md is also a great addition for tracking security learnings. I have one suggestion to improve the cleanup logic in the new tests for better test hygiene.
| try: | ||
| # Create a file outside of dummy_dir/runs | ||
| outside_file = Path("/tmp/outside_events_test.jsonl") | ||
| outside_file.touch() | ||
|
|
||
| _rotate_events_log(outside_file) | ||
|
|
||
| # Check that an error was printed to stderr | ||
| captured = capsys.readouterr() | ||
| assert "Security violation" in captured.err | ||
|
|
||
| # Verify no rotation occurred | ||
| assert not Path("/tmp/outside_events_test.jsonl.1").exists() | ||
|
|
||
| outside_file.unlink() | ||
| finally: | ||
| heidi_engine.telemetry.AUTOTRAIN_DIR = original_autotrain_dir | ||
| shutil.rmtree(dummy_dir) |
There was a problem hiding this comment.
This test creates a temporary file at /tmp/outside_events_test.jsonl. To ensure this file is always cleaned up, even if an assertion within the try block fails, it's best practice to move the outside_file.unlink() call into the finally block. This improves the test's robustness and prevents leaving orphaned files in the test environment.
| try: | |
| # Create a file outside of dummy_dir/runs | |
| outside_file = Path("/tmp/outside_events_test.jsonl") | |
| outside_file.touch() | |
| _rotate_events_log(outside_file) | |
| # Check that an error was printed to stderr | |
| captured = capsys.readouterr() | |
| assert "Security violation" in captured.err | |
| # Verify no rotation occurred | |
| assert not Path("/tmp/outside_events_test.jsonl.1").exists() | |
| outside_file.unlink() | |
| finally: | |
| heidi_engine.telemetry.AUTOTRAIN_DIR = original_autotrain_dir | |
| shutil.rmtree(dummy_dir) | |
| try: | |
| # Create a file outside of dummy_dir/runs | |
| outside_file = Path("/tmp/outside_events_test.jsonl") | |
| outside_file.touch() | |
| _rotate_events_log(outside_file) | |
| # Check that an error was printed to stderr | |
| captured = capsys.readouterr() | |
| assert "Security violation" in captured.err | |
| # Verify no rotation occurred | |
| assert not Path("/tmp/outside_events_test.jsonl.1").exists() | |
| finally: | |
| if "outside_file" in locals() and outside_file.exists(): | |
| outside_file.unlink() | |
| heidi_engine.telemetry.AUTOTRAIN_DIR = original_autotrain_dir | |
| shutil.rmtree(dummy_dir) |
Hardened
heidi_engine/telemetry.pyagainst path traversal vulnerabilities by sanitizingrun_idand validating rotation paths. Added regression tests.PR created automatically by Jules for task 11858244760672951706 started by @heidi-dang