Skip to content

Fix path traversal and unit test gate stability#162

Open
heidi-dang wants to merge 1 commit intofeat/bootstrap-scaffoldfrom
sentinel-path-traversal-and-stability-fixes-3327075848239083014
Open

Fix path traversal and unit test gate stability#162
heidi-dang wants to merge 1 commit intofeat/bootstrap-scaffoldfrom
sentinel-path-traversal-and-stability-fixes-3327075848239083014

Conversation

@heidi-dang
Copy link
Copy Markdown
Owner

Implemented path traversal protection in heidi_engine/telemetry.py and heidi_engine/dashboard.py by using Path(run_id).name to sanitize user-provided run identifiers. This prevents malicious actors from reading or writing files outside the intended runs/ directory.

Additionally, fixed a critical bug in scripts/03_unit_test_gate.py where multi-line Python code samples would fail to execute due to incorrect indentation within the execution wrapper. The wrapper now uses textwrap.indent to ensure proper nesting.

Finally, modernized heidi_engine/telemetry.py by replacing deprecated datetime.utcnow() calls with datetime.now(timezone.utc) and removed a broken redundant cache check that incorrectly referenced an undefined variable.

All changes were verified with targeted scripts and existing project tests (21 passed). Temporary artifacts were removed before submission.


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

This commit addresses several security and stability issues:
1. Fixes a path traversal vulnerability in telemetry and dashboard by sanitizing `run_id` inputs.
2. Fixes a SyntaxError in the unit test gate caused by improper indentation of multi-line code blocks.
3. Modernizes UTC timestamp generation to avoid deprecation warnings in Python 3.12+.
4. Removes a redundant and broken cache check in the telemetry module.
5. Standardizes the default AUTOTRAIN_DIR to ~/.local/heidi_engine for consistency across tools.
@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. It addresses potential path traversal vulnerabilities by sanitizing user inputs, preventing unauthorized file access. Furthermore, it improves the reliability of the unit test gate by correcting an indentation bug that affected multi-line code execution. The changes also include modernizing datetime handling and cleaning up faulty cache logic in the telemetry module, contributing to overall code quality and maintainability.

Highlights

  • Path Traversal Protection: Implemented robust path traversal protection in heidi_engine/telemetry.py and heidi_engine/dashboard.py by sanitizing user-provided run identifiers using Path(run_id).name.
  • Unit Test Gate Stability: Fixed a critical bug in scripts/03_unit_test_gate.py that caused multi-line Python code samples to fail due to incorrect indentation, now resolved by using textwrap.indent.
  • Telemetry Modernization: Updated heidi_engine/telemetry.py to use datetime.now(timezone.utc) instead of the deprecated datetime.utcnow() for better timezone awareness.
  • Cache Logic Refinement: Removed a broken and redundant cache check in heidi_engine/telemetry.py that incorrectly referenced an undefined variable.
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.

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 addresses path traversal vulnerabilities, improves unit test stability, and updates deprecated datetime functions. I've reviewed the changes and have one suggestion in heidi_engine/telemetry.py to improve the efficiency and clarity of the get_run_id function. The security fixes and other updates appear correct.

Comment thread heidi_engine/telemetry.py
Comment on lines 448 to 457
global RUN_ID
if not RUN_ID:
RUN_ID = os.environ.get("RUN_ID", "")
if not RUN_ID:
RUN_ID = str(uuid.uuid4())[:8]
RUN_ID = f"run_{datetime.now().strftime('%Y%m%d_%H%M%S')}_{RUN_ID}"

# SECURITY: Sanitize RUN_ID to prevent path traversal
RUN_ID = Path(RUN_ID).name
return RUN_ID
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

The current implementation of get_run_id re-evaluates and re-sanitizes the global RUN_ID on every call, which is inefficient. A better approach is to check for the existence of the global RUN_ID at the beginning and return it if it's already set. The generation and sanitization logic should only run once when the RUN_ID is first requested.

Suggested change
global RUN_ID
if not RUN_ID:
RUN_ID = os.environ.get("RUN_ID", "")
if not RUN_ID:
RUN_ID = str(uuid.uuid4())[:8]
RUN_ID = f"run_{datetime.now().strftime('%Y%m%d_%H%M%S')}_{RUN_ID}"
# SECURITY: Sanitize RUN_ID to prevent path traversal
RUN_ID = Path(RUN_ID).name
return RUN_ID
global RUN_ID
if RUN_ID:
return RUN_ID
run_id_val = os.environ.get("RUN_ID", "")
if not run_id_val:
run_id_val = str(uuid.uuid4())[:8]
run_id_val = f"run_{datetime.now().strftime('%Y%m%d_%H%M%S')}_{run_id_val}"
# Sanitize, set global, and return
RUN_ID = Path(run_id_val).name
return RUN_ID

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