Skip to content

Fix shell escaping vulnerability in env_updater#6

Closed
Copilot wants to merge 2 commits into
env-updates-gen-passfrom
copilot/sub-pr-3-again
Closed

Fix shell escaping vulnerability in env_updater#6
Copilot wants to merge 2 commits into
env-updates-gen-passfrom
copilot/sub-pr-3-again

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Nov 12, 2025

Addresses security issue where environment variable values were written to shell config files without escaping, enabling command injection via special characters.

Changes

  • Added escape_shell_value() - Escapes \, ", $, `, and \n before writing to shell files
  • Updated update_in_file() and append_to_file() - Both now escape values before insertion
  • Added security tests - Verify escaping behavior and command injection prevention

Example

Before:

// Vulnerable to injection
content.push_str(&format!("export {}=\"{}\"\n", var_name, new_value));
// Input: test`whoami`test → export SECRET="test`whoami`test"  (executes whoami)

After:

let escaped_value = Self::escape_shell_value(new_value);
content.push_str(&format!("export {}=\"{}\"\n", var_name, escaped_value));
// Input: test`whoami`test → export SECRET="test\`whoami\`test"  (safe literal)

Additional Fix

Restored proper skip_next_comment logic in remove_from_file() that was broken in previous commit.


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Co-authored-by: kelleyblackmore <16111250+kelleyblackmore@users.noreply.github.com>
Copilot AI changed the title [WIP] WIP address feedback from review on minor features PR Fix shell escaping vulnerability in env_updater Nov 12, 2025
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.

2 participants