Skip to content

fix(security): Prevent arbitrary executable execution via VIRTUAL_ENV#242

Open
pranav-cholleti wants to merge 2 commits into
siddu-k:mainfrom
pranav-cholleti:issueres/fix-236-1781282089501
Open

fix(security): Prevent arbitrary executable execution via VIRTUAL_ENV#242
pranav-cholleti wants to merge 2 commits into
siddu-k:mainfrom
pranav-cholleti:issueres/fix-236-1781282089501

Conversation

@pranav-cholleti

Copy link
Copy Markdown
Contributor

🛠️ Related Issue

Closes: #236

📌 Description

This PR addresses a critical security vulnerability (CWE-73) in main.js where the application was susceptible to arbitrary executable execution. The resolvePythonCmd function previously used the VIRTUAL_ENV environment variable to locate the Python executable without sufficient validation. This allowed an attacker to potentially control VIRTUAL_ENV and point it to a malicious executable, leading to arbitrary code execution when child_process.spawn was invoked.

To mitigate this, the resolvePythonCmd function has been updated to prioritize a securely bundled Python interpreter when the Electron application is running in a packaged (production) environment. The use of the VIRTUAL_ENV environment variable is now strictly confined to development mode, preventing its exploitation in production deployments and ensuring that only trusted Python executables are launched by the application.

✨ Changes Made

  • Modified main.js: Updated the resolvePythonCmd function to differentiate between packaged (production) and development environments. In packaged applications, it now explicitly resolves the Python interpreter to a securely bundled version located within process.resourcesPath. In development mode, it retains the existing logic for VIRTUAL_ENV and system Python, but this path is no longer used in production builds.

…ution via Environment Variable in `main.js`

The `resolvePythonCmd` function currently relies on the `VIRTUAL_ENV` environment variable to locate the Python executable. This unchecked dependency allows an attacker to control the `VIRTUAL_ENV` variable, pointing it to a malicious executable. When `startFlaskServer` subsequently uses this `pythonCmd` in `child_process.spawn`, it executes the attacker-controlled program, leading to arbitrary code execution. The fix involves modifying `resolvePythonCmd` to prioritize a securely bundled Python interpreter in packaged Electron applications and only permit `VIRTUAL_ENV` usage during development, thus preventing malicious environment variable injection in production.

Changes:
- main.js: Replaced resolvePythonCmd with a secure version that checks app.isPackaged and bundles Python in production, preventing arbitrary executable execution via VIRTUAL_ENV.
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.

[Security] Arbitrary Executable Execution via Environment Variable in main.js

1 participant