fix: detected calls to child_process from a function... in...#3296
Open
Conversation
Detected calls to child_process from a function argument `command` Addresses javascript.lang.security.detect-child-process.detect-child-process
Contributor
There was a problem hiding this comment.
2 issues found across 1 file
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="apps/api/src/harness.ts">
<violation number="1" location="apps/api/src/harness.ts:250">
P1: String tokenization in `execForward` breaks shell-escaped `docker -e KEY=VALUE` arguments, causing malformed env var args.</violation>
<violation number="2" location="apps/api/src/harness.ts:265">
P1: Refactor to non-shell `spawn` breaks existing shell-form commands (`cd ... && ...`), causing harness install/build command failures.</violation>
</file>
Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review, or fix all with cubic.
| const tokenRegex = /[^\s"']+|"([^"]*)"|'([^']*)'/g; | ||
| let match: RegExpExecArray | null; | ||
| while ((match = tokenRegex.exec(processArgs)) !== null) { | ||
| argv.push(match[1] ?? match[2] ?? match[0]); |
Contributor
There was a problem hiding this comment.
P1: String tokenization in execForward breaks shell-escaped docker -e KEY=VALUE arguments, causing malformed env var args.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At apps/api/src/harness.ts, line 250:
<comment>String tokenization in `execForward` breaks shell-escaped `docker -e KEY=VALUE` arguments, causing malformed env var args.</comment>
<file context>
@@ -237,31 +237,37 @@ function execForward(
+ const tokenRegex = /[^\s"']+|"([^"]*)"|'([^']*)'/g;
+ let match: RegExpExecArray | null;
+ while ((match = tokenRegex.exec(processArgs)) !== null) {
+ argv.push(match[1] ?? match[2] ?? match[0]);
}
} else {
</file context>
| // shell is explicitly disabled; executable is a resolved argv token, not a | ||
| // raw shell string — command injection via shell metacharacters is not possible. | ||
| // nosemgrep: javascript.lang.security.detect-child-process.detect-child-process | ||
| child = spawn(executable, execArgs, { |
Contributor
There was a problem hiding this comment.
P1: Refactor to non-shell spawn breaks existing shell-form commands (cd ... && ...), causing harness install/build command failures.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At apps/api/src/harness.ts, line 265:
<comment>Refactor to non-shell `spawn` breaks existing shell-form commands (`cd ... && ...`), causing harness install/build command failures.</comment>
<file context>
@@ -237,31 +237,37 @@ function execForward(
+ // shell is explicitly disabled; executable is a resolved argv token, not a
+ // raw shell string — command injection via shell metacharacters is not possible.
+ // nosemgrep: javascript.lang.security.detect-child-process.detect-child-process
+ child = spawn(executable, execArgs, {
+ env: { ...process.env, ...env },
+ shell: false,
</file context>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fix high severity security issue in
apps/api/src/harness.ts.Vulnerability
javascript.lang.security.detect-child-process.detect-child-processapps/api/src/harness.ts:258Description: Detected calls to child_process from a function argument
command. This could lead to a command injection if the input is user controllable. Try to avoid calls to child_process, and if it is needed ensure user input is correctly sanitized or sandboxed.Changes
apps/api/src/harness.tsVerification
Automated security fix by OrbisAI Security
Summary by cubic
Prevents command injection in
apps/api/src/harness.tsby removing shell-based execution and safely spawning processes with argv. Addresses Semgrep rulejavascript.lang.security.detect-child-process.detect-child-process(HIGH).Bug Fixes
processArgsinto argv; removessh -c/cmd /c.shell: false; updatesdisplayCommand.nosemgrepcomment to avoid false positives.Migration
string[]of args instead.Written for commit f1ada7f. Summary will update on new commits.