mirror of
https://github.com/finmars-platform/finmars-vue-portal.git
synced 2026-04-26 23:05:57 +03:00
[PR #36] Command Injection Vulnerability in Environment Variable Substitution Script #37
Labels
No labels
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/finmars-vue-portal#37
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/finmars-platform/finmars-vue-portal/pull/36
Author: @Moltivie
Created: 1/21/2026
Status: 🔄 Open
Base:
main← Head:main📝 Commits (1)
5558679fix command injection vulnerability in environment substitution📊 Changes
1 file changed (+70 additions, -16 deletions)
View changed files
📝
docker/substitute_environment_variables.sh(+70 -16)📄 Description
Vulnerability Description
A Remote Code Execution (RCE) vulnerability existed in the Docker environment variable substitution script (
docker/substitute_environment_variables.sh). The script usedsedcommands to replace placeholder values with environment variables in production.mjsfiles. By injecting malicious content into environment variables, an attacker could execute arbitrary shell commands during container startup.Root Cause
The vulnerable code concatenated environment variables directly into
sedcommands without proper escaping:When the shell expands
${PROD_API_HOST}, if the variable contains the delimiter character|, the attacker can terminate the substitution command and inject a newsedcommand with the/eflag to execute arbitrary code.Proof of Concept (PoC)
Attack Vector:
Set the environment variable to include a delimiter and malicious sed command:
What happens:
The resulting sed command becomes:
Breakdown:
s|==PROD_API_HOST==||- Replaces placeholder with empty string;- Ends the first commands/^/echo "HACKED" > \/tmp\/pwned/e- The/eflag executes the shell commandecho "HACKED" > /tmp/pwned;- Additional command separator|ggets absorbed as garbageResult: The command
echo "HACKED" > /tmp/pwnedis executed on the host system with the container's privileges.Solution Implemented
Replaced the vulnerable
sed-based approach with a secure Node.js script that:String.split().join()- Safe replacement method without regex metacharacter issues&,\,|, and other special characters common in URLsnode:22-alpinecontainerImplementation
The script now generates a temporary Node.js module that reads environment variables via
process.env(already isolated) and performs string replacement using safe methods:This approach is immune to command injection because:
|,;, etc.) have special meaningAdditional Fixes
PROD_FRONT_URL→PROD_FRONT_HOSTto match the actual placeholder innuxt.config.tsROOT_DIRvariable consistently throughout the script🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.