Skip to content

🔒 Fix command injection vulnerability in subprocess shell=True usage#473

Open
IAmSoThirsty wants to merge 5 commits intomainfrom
fix-subprocess-shell-injection-11088542195727080879
Open

🔒 Fix command injection vulnerability in subprocess shell=True usage#473
IAmSoThirsty wants to merge 5 commits intomainfrom
fix-subprocess-shell-injection-11088542195727080879

Conversation

@IAmSoThirsty
Copy link
Copy Markdown
Owner

🎯 What: Fixed command injection vulnerability in src/app/infrastructure/vpn/backends.py and src/app/infrastructure/networking/wifi_controller.py caused by the use of shell=True in subprocess.run().
⚠️ Risk: Allowing subprocess.run() to execute commands with shell=True using untrusted input enables shell command injection, allowing arbitrary code execution.
🛡️ Solution: Replaced shell=True with shell=False in all cases where subprocess.run executes standard binaries/executables (e.g., where, wireguard, openvpn, rasdial, netsh). shell=False is inherently secure as it bypasses the shell entirely and uses the list-based argument passing mechanism directly, preventing injection. A new test suite was added in tests/test_subprocess_shell_fix.py to continuously verify these changes.


PR created automatically by Jules for task 11088542195727080879 started by @IAmSoThirsty

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

@codacy-production
Copy link
Copy Markdown
Contributor

codacy-production Bot commented Apr 8, 2026

Not up to standards ⛔

🔴 Issues 2 high · 10 medium

Alerts:
⚠ 12 issues (≤ 0 issues of at least minor severity)

Results:
12 new issues

Category Results
ErrorProne 4 medium
Security 6 medium
2 high

View in Codacy

🟢 Metrics 5 complexity

Metric Results
Complexity 5

View in Codacy

TIP This summary will be updated as you push new changes. Give us feedback

Copy link
Copy Markdown
Contributor

@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 improves security by replacing shell=True with shell=False in subprocess.run calls across the WiFi controller and VPN backends, and introduces a new test suite to verify these changes. Feedback suggests maintaining consistency in backends.py by either explicitly setting shell=False or relying on the default value across all subprocess.run calls in the file to improve maintainability.

Comment thread src/app/infrastructure/vpn/backends.py Outdated
if self.platform == "Windows":
cmd = ["where", "openvpn"]
result = subprocess.run(cmd, capture_output=True, timeout=5, shell=True)
result = subprocess.run(cmd, capture_output=True, timeout=5, shell=False)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

While replacing shell=True with shell=False is a significant security improvement, there is now an inconsistency in how subprocess.run is called within this file. In the else block (line 250), shell=False is implicit, whereas here it is explicit. For better maintainability and clarity of security intent, it is recommended to either make it explicit everywhere or rely on the default False consistently when no shell features are required.

google-labs-jules Bot and others added 3 commits April 8, 2026 15:20
…shell=True with shell=False

Co-authored-by: IAmSoThirsty <[email protected]>
…shell=True with shell=False

Co-authored-by: IAmSoThirsty <[email protected]>
…shell=True with shell=False

Co-authored-by: IAmSoThirsty <[email protected]>
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