Skip to content

Comments

🛡️ Sentinel: [HIGH] Fix path traversal in telemetry#87

Open
heidi-dang wants to merge 1 commit intofeat/bootstrap-scaffoldfrom
fix/telemetry-path-traversal-11858244760672951706
Open

🛡️ Sentinel: [HIGH] Fix path traversal in telemetry#87
heidi-dang wants to merge 1 commit intofeat/bootstrap-scaffoldfrom
fix/telemetry-path-traversal-11858244760672951706

Conversation

@heidi-dang
Copy link
Owner

Hardened heidi_engine/telemetry.py against path traversal vulnerabilities by sanitizing run_id and validating rotation paths. Added regression tests.


PR created automatically by Jules for task 11858244760672951706 started by @heidi-dang

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.
@google-labs-jules
Copy link
Contributor

👋 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 @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

@gemini-code-assist
Copy link

Summary of Changes

Hello @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 heidi_engine/telemetry.py module by addressing a high-severity path traversal vulnerability. The changes ensure that user-provided inputs for directory creation and log file rotation cannot be exploited to access or modify files outside of intended directories, thereby safeguarding the system against malicious file system operations.

Highlights

  • Path Traversal Prevention in get_run_dir: The get_run_dir function was updated to sanitize the run_id parameter using Path(run_id).name, preventing directory traversal attacks by ensuring only the filename component is used. A fallback to "default_run" is implemented for unsafe extracted names.
  • Secure Log Rotation: The _rotate_events_log function now includes robust path validation, ensuring that log rotation operations are strictly confined within the AUTOTRAIN_DIR/runs directory, thus preventing unauthorized file manipulation outside this scope.
  • New Security Regression Tests: Dedicated regression tests were added in tests/test_telemetry_security.py to verify the effectiveness of the path traversal prevention in get_run_dir and the secure log rotation logic in _rotate_events_log.
  • Vulnerability Documentation: A new markdown file, .jules/sentinel.md, was added to document the identified path traversal vulnerability, the lessons learned, and recommended prevention strategies.
Changelog
  • .jules/sentinel.md
    • Documented a path traversal vulnerability in telemetry, including learning and prevention strategies.
  • heidi_engine/telemetry.py
    • Implemented sanitization for run_id in get_run_dir to prevent path traversal.
    • Added path validation in _rotate_events_log to ensure log rotation stays within the designated runs directory.
  • tests/test_telemetry_security.py
    • Added new regression tests to validate the path traversal fixes in get_run_dir and _rotate_events_log.
Activity
  • PR created automatically by Jules for task 11858244760672951706, initiated by @heidi-dang.
Using Gemini Code Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +53 to +70
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)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

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.

Suggested change
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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant