Skip to content

🛡️ Sentinel: Fix path traversal and environment leakage vulnerabilities#172

Open
heidi-dang wants to merge 1 commit intofeat/bootstrap-scaffoldfrom
sentinel-security-fixes-path-env-leak-7801631284483336633
Open

🛡️ Sentinel: Fix path traversal and environment leakage vulnerabilities#172
heidi-dang wants to merge 1 commit intofeat/bootstrap-scaffoldfrom
sentinel-security-fixes-path-env-leak-7801631284483336633

Conversation

@heidi-dang
Copy link
Copy Markdown
Owner

I have identified and fixed two critical security vulnerabilities and one functional bug:

  1. Path Traversal Mitigation: The get_run_dir function in both heidi_engine/telemetry.py and heidi_engine/dashboard.py previously used raw run_id strings to construct file paths. This allowed an attacker (or accidental misconfiguration) to provide an absolute path as run_id, escaping the intended runs/ directory and potentially reading/writing sensitive files elsewhere on the system. I sanitized this by using Path(run_id).name, which extracts only the final component of the path.

  2. Environment Variable Isolation: The scripts/03_unit_test_gate.py script was passing the entire host environment (os.environ) to subprocesses running untrusted (synthetic) code. This could leak sensitive credentials like OPENAI_API_KEY. I implemented a safe_env whitelist that only provides necessary variables (PATH, PYTHONPATH, HOME, LANG, and PYTHONDONTWRITEBYTECODE) to the subprocess.

  3. NameError Bug Fix: In heidi_engine/telemetry.py, a redundant cache check in the get_state function was referencing an undefined variable target_run_id, which would cause a NameError and potentially a Denial of Service for telemetry clients. I removed this redundant check.

  4. Journaling: I've documented these findings and their preventions in the Sentinel security journal (.jules/sentinel.md).

All changes were verified with targeted reproduction scripts and the full pytest suite.


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

- Mitigate path traversal risk in `heidi_engine/telemetry.py` and `heidi_engine/dashboard.py` by sanitizing `run_id` with `Path(run_id).name`.
- Secure untrusted code execution in `scripts/03_unit_test_gate.py` by using a restricted `safe_env` (PATH, PYTHONPATH, HOME, LANG, PYTHONDONTWRITEBYTECODE) to prevent secret leakage from `os.environ`.
- Fix `NameError` in `heidi_engine/telemetry.py` by removing a redundant and broken cache check in `get_state`.
- Improve robustness of `save_jsonl` in `scripts/03_unit_test_gate.py` to handle paths without directory components.
- Document vulnerabilities and preventions 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 addresses critical security vulnerabilities related to path traversal and environment variable leakage, along with a functional bug causing a NameError. It enhances the security posture of the application by sanitizing user inputs and restricting environment access for subprocesses. The changes also include documentation of the vulnerabilities and their mitigations in the security journal.

Highlights

  • Path Traversal Mitigation: Sanitized the run_id in get_run_dir function in heidi_engine/telemetry.py and heidi_engine/dashboard.py to prevent path traversal vulnerabilities by extracting only the filename component.
  • Environment Variable Isolation: Implemented a safe_env whitelist in scripts/03_unit_test_gate.py to prevent leakage of sensitive environment variables to subprocesses.
  • Bug Fix: Removed a redundant cache check in heidi_engine/telemetry.py that was causing a NameError due to referencing an undefined variable.
  • Journaling: Documented the identified vulnerabilities and their preventions in the Sentinel security journal (.jules/sentinel.md).
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 several security vulnerabilities and a bug. The path traversal fix in heidi_engine/dashboard.py and heidi_engine/telemetry.py is correctly implemented by sanitizing the run_id. The environment variable leakage in scripts/03_unit_test_gate.py is also well-handled by using a whitelisted safe_env. However, the fix for the NameError in heidi_engine/telemetry.py's get_state function, while solving the immediate crash, has introduced a performance regression by removing the caching layer entirely. I've provided a comment with a suggestion to reintroduce the caching logic in a correct and more efficient way.

Comment thread heidi_engine/telemetry.py
Comment on lines 736 to 738
try:
with open(state_file) as f:
state = json.load(f)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

high

While removing the buggy code block fixed the NameError, it also removed the caching mechanism entirely. This will cause a performance regression as get_state will now read from the disk on every call. The caching logic should be restored.

The original code was also redundant. A correct and efficient implementation should first check the cache, and if that fails, return a default state, as the cache's get method already attempts to read from the file. The logic after the if not state_file.exists(): check could be simplified to:

    # Check thread-safe state cache. The .get() method will handle loading from file.
    cached = _state_cache.get(run_id, state_file)
    if cached:
        return cached

    # If cache is empty (file exists but is corrupt), return default state.
    return get_default_state(run_id)

This would replace the entire try...except block that currently starts here.

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