Fix/process execution security - #915
Open
icy000z wants to merge 2 commits into
Open
Conversation
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.
Security Audit & Hardening Report
Overview
During our security audit of the PrimeIntellect
prime-agentrepository, we identified several vulnerabilities centered around process execution, shell injection risks, and inadequate process lifecycle management. We performed a comprehensive system hardening to eliminate these flows.1. Process Lifecycle & Teardown Weaknesses
The Flaw
The
IPythonkernel and itsKernelManagerhandled process disposal without strong cancellation propagation. When subagents or external tools were executed through the host bridge (e.g.,rlm.run), there was no reliable way to forcibly interrupt and cancel these long-running subprocesses if the kernel was abruptly shut down. This could lead to zombie processes, resource leaks, or unpredictable behaviors persisting in the background.The Fix
We introduced robust
AbortSignalplumbing throughout the lifecycle chain:KernelManager: Added a_disposeControllerusingAbortController. Whendispose()ordisposeSync()is invoked, this controller is aborted.HostRequestHandlerInterface: Updated the bridge's type signature to accept an optionalAbortSignal.agent-session.ts&rlm-runtime.ts: We propagated this signal throughcreateRlmRunHostHandlerdown torunRlmChild. Now, if a kernel disposal timeout is triggered, theAbortSignaldirectly callsrun.abort(), cascading the cancellation to safely terminate the running agent process tree.2. Shell Injection Risks in Clipboard Utilities
The Flaw
The
packages/coding-agent/src/utils/clipboard.tsfile extensively relied onchild_process.execSyncto interact with OS clipboard utilities (xclip,pbcopy,wl-copy,clip).execSyncdefaults to executing the command inside a spawned sub-shell (e.g.,/bin/sh -c). When arbitrary or unexpected input is piped, relying on a sub-shell creates an attack surface for shell injection or argument parsing errors.The Fix
We systematically removed all instances of
execSync.spawnSyncandspawnmethods.spawnSync("xclip", ["-selection", "clipboard"])), completely bypassing shell evaluation.3. Insecure
execFileSync/execSyncUsage in Test SuitesThe Flaw
Our audit of the
packages/coding-agent/test/directory revealed a reliance onexecFileSyncacross multiple integration tests (agent-session-autonomous.test.ts,session-manager-git-state.test.ts,git-context.test.ts, andbash-close-hang-windows.test.ts). While less risky thanexecSync(as it avoids a shell), usingexecFileSyncfailed to follow the repository's centralized executable shell configuration and execution patterns.The Fix
spawnSyncinvocations.execFileSync("git", ...)andexecFileSync("mkdir", ...)operations to use these sanitized wrappers, bringing the test environment into alignment with production security standards and ensuring all arguments are strictly delimited.Note
Fix process execution security by replacing
execSync/execFileSyncwithspawnSyncacross clipboard and test utilitiesexecSync/execFileSynccalls withspawnSyncin clipboard.ts and several test helpers, adding explicit status/error checks to catch silent failures and avoid shell injection.AbortSignalsupport toAgentSession.runRlmChildandRlmRunHandler, allowing RLM child runs to be cancelled mid-execution.ctrl+c,shift+ctrl+d) with configurable keybindings (app.clear,tui.debug) in interactive TUI components.Macroscope summarized 8b8ce55.