🛡️ Sentinel: [CRITICAL/HIGH] Fix environment leakage and path traversal vulnerabilities - #462
Conversation
- Restrict environment variables in unit test gate to prevent secret leakage. - Implement sanitize_run_id to prevent path traversal in telemetry and dashboard. - Use textwrap.indent for safe code injection in unit tests. - Fix NameError in telemetry cache logic. - Update Sentinel journal with new learnings.
|
👋 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. |
There was a problem hiding this comment.
Code Review
This pull request introduces path traversal protection by adding and applying a sanitize_run_id helper function in both heidi_engine/dashboard.py and heidi_engine/telemetry.py. It also enhances the security of the unit test gate script by properly indenting executed code and restricting environment variables passed to subprocesses to prevent credential leaks. The review feedback suggests raising a ValueError instead of returning a fallback string in sanitize_run_id to prevent silent failures and state collisions, and recommends importing the helper function to eliminate code duplication.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
| def sanitize_run_id(run_id: str) -> str: | ||
| """ | ||
| Sanitize run_id to prevent path traversal. | ||
|
|
||
| SECURITY: | ||
| - Uses Path(run_id).name to isolate filename | ||
| - Rejects '..' or empty strings | ||
| """ | ||
| if not run_id: | ||
| return "invalid_run_id" | ||
|
|
||
| # Get only the last component of the path | ||
| safe_id = Path(run_id).name | ||
|
|
||
| # Check for dangerous or empty results | ||
| if safe_id in ("..", ".", ""): | ||
| return "invalid_run_id" | ||
|
|
||
| return safe_id |
There was a problem hiding this comment.
Returning a fallback string like "invalid_run_id" instead of raising an exception is a security and correctness issue. If an invalid or malicious RUN_ID is provided via the environment, get_run_id() will set RUN_ID to "invalid_run_id". Since "invalid_run_id" is truthy, the fallback UUID generation block is bypassed, and the application will silently run using a shared, static directory (runs/invalid_run_id). This can lead to state collision, data corruption, or unauthorized data sharing between different invalid runs.
Instead, raise a ValueError to fail-fast and prevent running under an invalid configuration.
| def sanitize_run_id(run_id: str) -> str: | |
| """ | |
| Sanitize run_id to prevent path traversal. | |
| SECURITY: | |
| - Uses Path(run_id).name to isolate filename | |
| - Rejects '..' or empty strings | |
| """ | |
| if not run_id: | |
| return "invalid_run_id" | |
| # Get only the last component of the path | |
| safe_id = Path(run_id).name | |
| # Check for dangerous or empty results | |
| if safe_id in ("..", ".", ""): | |
| return "invalid_run_id" | |
| return safe_id | |
| def sanitize_run_id(run_id: str) -> str: | |
| """ | |
| Sanitize run_id to prevent path traversal. | |
| SECURITY: | |
| - Uses Path(run_id).name to isolate filename | |
| - Rejects '..' or empty strings | |
| """ | |
| if not run_id: | |
| raise ValueError("Run ID cannot be empty") | |
| # Get only the last component of the path | |
| safe_id = Path(run_id).name | |
| # Check for dangerous or empty results | |
| if safe_id in ("..", ".", ""): | |
| raise ValueError(f"Invalid run ID: {run_id}") | |
| return safe_id |
| def sanitize_run_id(run_id: str) -> str: | ||
| """ | ||
| Sanitize run_id to prevent path traversal. | ||
|
|
||
| SECURITY: | ||
| - Uses Path(run_id).name to isolate filename | ||
| - Rejects '..' or empty strings | ||
| """ | ||
| if not run_id: | ||
| return "invalid_run_id" | ||
|
|
||
| # Get only the last component of the path | ||
| safe_id = Path(run_id).name | ||
|
|
||
| # Check for dangerous or empty results | ||
| if safe_id in ("..", ".", ""): | ||
| return "invalid_run_id" | ||
|
|
||
| return safe_id |
There was a problem hiding this comment.
To avoid code duplication of a security-critical function, import sanitize_run_id directly from heidi_engine.telemetry instead of redefining it here. This ensures consistent sanitization behavior across both modules and simplifies future maintenance.
from heidi_engine.telemetry import sanitize_run_id
🚨 Severity: CRITICAL
💡 Vulnerability:
scripts/03_unit_test_gate.pyleaked the full host environment (includingOPENAI_API_KEY) to untrusted code being tested.heidi_engine/telemetry.pyanddashboard.pywere vulnerable to path traversal via therun_idparameter.🎯 Impact:
run_idcould be used to read or write files anywhere on the system accessible to the user, potentially compromising the host.🔧 Fix:
subprocess.runto a safe whitelist.sanitize_run_idusingPath(run_id).namewith explicit checks for..and empty strings.NameErrorintelemetry.pycache logic and cleaned up redundant blocks.textwrap.indentto ensure proper nesting of injected code in unit test wrappers.✅ Verification:
run_idinputs like../.PR created automatically by Jules for task 10764456563853644933 started by @heidi-dang