Skip to content

🛡️ Sentinel: [MEDIUM] Fix shell injection vulnerability in fix_env.py#112

Merged
abhimehro merged 1 commit intomainfrom
sentinel-fix-env-injection-993354469762369574
Jan 18, 2026
Merged

🛡️ Sentinel: [MEDIUM] Fix shell injection vulnerability in fix_env.py#112
abhimehro merged 1 commit intomainfrom
sentinel-fix-env-injection-993354469762369574

Conversation

@google-labs-jules
Copy link

🛡️ Sentinel: [MEDIUM] Fix shell injection vulnerability in fix_env.py

🚨 Severity: MEDIUM
💡 Vulnerability: The fix_env.py script was writing values to .env without escaping internal double quotes. If a value contained ", it would result in invalid shell syntax (e.g., TOKEN="foo"bar"). If the .env file were sourced by a shell, this could lead to syntax errors or, in malicious cases, command injection.
🎯 Impact: Potential shell injection or configuration corruption when sourcing the generated .env file.
🔧 Fix: Implemented an escape_val function that properly escapes backslashes and double quotes before writing to the file.
✅ Verification: Verified with a reproduction script that injection attempts are now safely escaped (e.g., TOKEN="foo\"bar").


PR created automatically by Jules for task 993354469762369574 started by @abhimehro

- Added `escape_val` helper to securely escape double quotes and backslashes when writing `.env` files.
- Prevents potential shell injection or syntax errors if the generated `.env` file is sourced.
- Standardized quote handling for `TOKEN` and `PROFILE` values.

This addresses a security risk where malicious or malformed values in `.env` could lead to command execution or configuration corruption.
@google-labs-jules
Copy link
Author

👋 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.

@trunk-io
Copy link

trunk-io bot commented Jan 18, 2026

Merging to main in this repository is managed by Trunk.

  • To merge this pull request, check the box to the left or comment /trunk merge below.

return val.replace('\\', '\\\\').replace('"', '\\"')

lines = content.splitlines()
parsed = {}

Check warning

Code scanning / Pylint (reported by Codacy)

Missing function docstring Warning

Missing function docstring

lines = content.splitlines()
parsed = {}

Check warning

Code scanning / Pylint (reported by Codacy)

More than one statement on a single line Warning

More than one statement on a single line
@abhimehro abhimehro marked this pull request as ready for review January 18, 2026 21:16
Copilot AI review requested due to automatic review settings January 18, 2026 21:16
@abhimehro abhimehro merged commit 8a51184 into main Jan 18, 2026
22 of 24 checks passed
@abhimehro abhimehro deleted the sentinel-fix-env-injection-993354469762369574 branch January 18, 2026 21:17
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR addresses a shell injection vulnerability in fix_env.py by adding proper escaping of values before writing them to the .env file. Previously, values containing double quotes could break shell syntax or enable command injection when the .env file was sourced.

Changes:

  • Added escape_val() helper function to escape backslashes and double quotes in environment variable values
  • Applied escaping to both TOKEN and PROFILE values before writing to .env file
Comments suppressed due to low confidence (1)

fix_env.py:1

  • Import of 'os' is not used.
import os

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +23 to +24
# Escape backslashes first, then double quotes
return val.replace('\\', '\\\\').replace('"', '\\"')
Copy link

Copilot AI Jan 18, 2026

Choose a reason for hiding this comment

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

The escape_val function does not escape dollar signs ($) or backticks (). When the .env file is sourced by a shell, values containing these characters within double quotes can still trigger variable expansion or command substitution, potentially leading to security issues. Consider escaping $ as \$ and as ` to prevent unintended shell interpretation.

Suggested change
# Escape backslashes first, then double quotes
return val.replace('\\', '\\\\').replace('"', '\\"')
# Escape backslashes first, then double quotes, dollar signs, and backticks
return (
val.replace('\\', '\\\\')
.replace('"', '\\"')
.replace('$', '\\$')
.replace('`', '\\`')
)

Copilot uses AI. Check for mistakes.
Comment on lines +21 to +24
def escape_val(val):
if not val: return ""
# Escape backslashes first, then double quotes
return val.replace('\\', '\\\\').replace('"', '\\"')
Copy link

Copilot AI Jan 18, 2026

Choose a reason for hiding this comment

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

The escape_val function and its security-critical escaping logic lack test coverage. Given that this fix addresses a shell injection vulnerability, it would be valuable to add tests that verify the escaping works correctly for various edge cases including values with double quotes, backslashes, dollar signs, backticks, and newlines. Consider adding a test file like test_fix_env.py with test cases for the escape_val function.

Copilot uses AI. Check for mistakes.
Comment on lines +23 to +24
# Escape backslashes first, then double quotes
return val.replace('\\', '\\\\').replace('"', '\\"')
Copy link

Copilot AI Jan 18, 2026

Choose a reason for hiding this comment

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

The escape_val function does not handle newline characters or other control characters. If real_token or real_profiles contain newlines (e.g., from malicious input or data corruption), the generated .env file will be malformed. Consider escaping newlines as \n, carriage returns as \r, and tabs as \t to ensure the .env file remains valid.

Suggested change
# Escape backslashes first, then double quotes
return val.replace('\\', '\\\\').replace('"', '\\"')
# Escape backslashes first, then control characters, then double quotes
val = val.replace('\\', '\\\\')
val = val.replace('\n', '\\n').replace('\r', '\\r').replace('\t', '\\t')
return val.replace('"', '\\"')

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants