Skip to content

🛡️ Sentinel: Fix path traversal and telemetry bugs#158

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

🛡️ Sentinel: Fix path traversal and telemetry bugs#158
heidi-dang wants to merge 1 commit intofeat/bootstrap-scaffoldfrom
sentinel-fix-path-traversal-803352304742846814

Conversation

@heidi-dang
Copy link
Copy Markdown
Owner

I have identified and fixed a path traversal vulnerability in the telemetry and dashboard modules. An attacker could previously use a manipulated run_id (e.g., ../secrets) to access files outside the intended runs/ directory.

I have implemented the following improvements:

  1. Security Fix: Sanitized run_id using Path(run_id).name in both heidi_engine/telemetry.py and heidi_engine/dashboard.py to ensure all paths remain within the runs/ subdirectory.
  2. Bug Fix: Resolved a NameError in telemetry.get_state that occurred when attempting to use an undefined variable target_run_id during a cache miss.
  3. Standardization: Standardized the default AUTOTRAIN_DIR to ~/.local/heidi_engine to maintain consistency across the entire pipeline.
  4. Maintenance: Updated deprecated datetime.utcnow() calls to the recommended datetime.now(timezone.utc) for improved compatibility and accuracy in Python 3.12+.
  5. Verification: Added a new test file tests/test_security.py containing regression tests for the path traversal and NameError fixes. All 23 tests in the suite are passing.

I have also updated the Sentinel security journal at .jules/sentinel.md with these findings.


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

This commit addresses a high-severity path traversal vulnerability in
the telemetry and dashboard modules. By sanitizing `run_id` inputs
using `Path(run_id).name`, we ensure that file operations are restricted
to the intended `runs/` directory, preventing unauthorized access to
other parts of the filesystem.

Key changes:
- Sanitized `run_id` in `heidi_engine/telemetry.py` and `heidi_engine/dashboard.py`.
- Fixed a `NameError` in `telemetry.get_state` caused by broken cache logic.
- Standardized `AUTOTRAIN_DIR` default value across modules.
- Modernized `datetime.utcnow()` calls to use `datetime.now(timezone.utc)`.
- Added regression tests in `tests/test_security.py`.
- Documented findings in `.jules/sentinel.md`.
@google-labs-jules
Copy link
Copy Markdown
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
Copy Markdown

Summary of Changes

Hello, 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 and stability of the system by addressing a critical path traversal vulnerability in the telemetry and dashboard modules. It also fixes a NameError bug, standardizes directory configurations, and updates deprecated datetime functions, ensuring a more robust and maintainable codebase. The changes are verified with new dedicated security tests.

Highlights

  • Security Fix: Sanitized run_id using Path(run_id).name in both heidi_engine/telemetry.py and heidi_engine/dashboard.py to prevent path traversal vulnerabilities and ensure all paths remain within the runs/ subdirectory.
  • Bug Fix: Resolved a NameError in telemetry.get_state that occurred when attempting to use an undefined variable target_run_id during a cache miss.
  • Standardization: Standardized the default AUTOTRAIN_DIR to ~/.local/heidi_engine across the codebase for consistency.
  • Maintenance: Updated deprecated datetime.utcnow() calls to the recommended datetime.now(timezone.utc) for improved compatibility and accuracy in Python 3.12+.
  • Verification: Added a new test file tests/test_security.py containing regression tests for the path traversal and NameError fixes.
Changelog
  • .jules/sentinel.md
    • Documented a new security entry detailing a path traversal vulnerability in telemetry run directories.
    • Provided learning and prevention strategies for path sanitization.
  • heidi_engine/dashboard.py
    • Standardized the default AUTOTRAIN_DIR to ~/.local/heidi_engine.
    • Modified get_run_dir to sanitize run_id using Path(run_id).name to prevent path traversal.
    • Updated the docstring for get_run_dir to reflect the security sanitization.
  • heidi_engine/telemetry.py
    • Imported timezone from the datetime module.
    • Modified get_run_dir to sanitize run_id using Path(run_id).name to prevent path traversal.
    • Updated init_telemetry, save_state, and emit_event to use datetime.now(timezone.utc) instead of datetime.utcnow().
    • Removed the _state_cache check in get_state to fix a NameError.
  • tests/test_security.py
    • Added test_path_traversal_prevention to verify get_run_dir correctly handles malicious run_id inputs.
    • Added test_name_error_fixed to ensure get_state no longer raises NameError for non-existent runs.
Activity
  • This pull request was automatically created by Jules for task 803352304742846814, 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
Copy Markdown

@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 telemetry.py and dashboard.py by sanitizing the run_id. It also fixes a NameError in telemetry.get_state, standardizes the AUTOTRAIN_DIR path for consistency, and modernizes the code by replacing deprecated datetime.utcnow() calls. The addition of regression tests in tests/test_security.py is a great step to prevent future issues. I have one suggestion to improve the new test file to align with standard pytest practices.

Comment thread tests/test_security.py
Comment on lines +29 to +32
if __name__ == "__main__":
test_path_traversal_prevention()
test_name_error_fixed()
print("Security verification tests passed!")
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

While this if __name__ == '__main__': block allows for direct execution of the script, it's redundant when using a test runner like pytest, which is already imported. The test runner will automatically discover and execute functions prefixed with test_. Relying solely on the test runner is a best practice that ensures tests are run in a consistent environment with proper setup, teardown, and reporting. I suggest removing this block to encourage the use of pytest for test execution.

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