Skip to content

Fix shell injection vulnerability in env_updater#5

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

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

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 special characters, enabling command injection.

Changes:

  • Added escape_shell_value() to escape backslash, double quotes, dollar signs, backticks, and newlines
  • Applied escaping in update_in_file() and append_to_file() before writing values to .bashrc, .zshrc, etc.
  • Added tests for individual special characters, combined edge cases, and injection attempts

Example:

// Before: vulnerable to injection
updater.update_env_var("SECRET", r#""; rm -rf /"#)?;
// Writes: export SECRET=""; rm -rf /"  ← executes command!

// After: properly escaped
updater.update_env_var("SECRET", r#""; rm -rf /"#)?;
// Writes: export SECRET="\"; rm -rf /"  ← safely stored as literal

💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Co-authored-by: kelleyblackmore <16111250+kelleyblackmore@users.noreply.github.com>
Copilot AI changed the title [WIP] WIP addressing feedback on minor features in PR #3 Fix shell injection 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