Summary
A command injection flaw in WebdriverIO's Git metadata helper allows Git branch names to be interpolated directly into shell commands used by execSync() without sanitization.
If an attacker can supply or influence the Git repository used for smart test selection, they can craft a malicious branch name that results in remote code execution on CI/CD servers or developer machines.
Affected context
This vulnerability appears in WebdriverIO environments that:
- Use versions prior to 9.24.0
- Enable or rely on test orchestration with smart selection (
testOrchestrationOptions.runSmartSelection) - Invoke
getGitMetadataForAISelection()to collect Git-related metadata - Run tests in Git repositories where branch names may contain shell metacharacters
The risk is especially relevant for shared CI/CD workers, ephemeral build agents, or developer machines that execute WebdriverIO commands against repositories cloned from semi-trusted or untrusted sources.
Exploit preconditions
- Attack surface: WebdriverIO test runs that call into
getGitMetadataForAISelection()as part of test orchestration, typically in CI/CD pipelines or local dev workflows. - Required access:
- Ability to provide or control the Git repository used for smart selection, either via:
testOrchestrationOptions.runSmartSelection.sourcepointing to an attacker-controlled repository, or- The current working directory being a repository the attacker can influence (e.g., via a compromised or malicious project clone).
- Ability to create or select a Git branch whose name contains shell metacharacters and payload.
- Trigger point: Execution of WebdriverIO's Git metadata retrieval logic, which builds a shell command with the branch name and passes it to
execSync()without proper escaping or validation. - Why exploitation is possible: Branch names are treated as trusted input and directly interpolated into shell commands, enabling arbitrary command execution when the shell parses metacharacters contained in the branch name.
Why this happens
The underlying issue is a classic shell command injection pattern, mapped to CWE-78: Improper Neutralization of Special Elements used in an OS Command ('OS Command Injection').
WebdriverIO's getGitMetadataForAISelection() collects Git metadata by constructing shell commands that include the current branch name. Git itself permits branch names with spaces and shell metacharacters. Instead of treating the branch name as untrusted data, the implementation interpolates it directly into a command string passed to execSync(), relying on the system shell for execution. Because there is no escaping, quoting, or validation of these values, any embedded shell syntax in the branch name is interpreted as part of the command, allowing arbitrary OS-level commands to be injected and executed within the test runner's process.
Potential impact
- Remote code execution on CI/CD servers running WebdriverIO-based test suites
- Remote code execution on developer machines executing tests against compromised repositories
- Theft of environment credentials, API tokens, and other secrets from build environments
- Exfiltration of source code, SSH keys, and configuration from affected hosts
- Tampering with build artifacts, leading to downstream supply chain compromise
- Persistence or lateral movement within the CI/CD or developer infrastructure
General mitigation guidance
Mitigation centers on eliminating command construction patterns that treat user- or environment-controlled strings as shell syntax:
- Prefer API-based Git access (e.g., library calls) over spawning shell commands, especially when including branch names, tags, or commit messages.
- When OS commands are unavoidable, use argument-vector execution (e.g.,
execFile/spawnwith an array) rather than passing a single command string to a shell. - Apply strict input neutralization to any value that can be influenced by repository state:
- Reject or safely encode branch names containing shell metacharacters where they must be used in commands.
- Normalize or whitelist expected patterns for branch names in orchestration logic.
- Run test orchestration under least-privilege accounts and with minimal environment secrets to reduce blast radius if command injection occurs.
- Isolate CI/CD jobs (containerization, ephemeral runners, restricted network access) so that compromise of one job does not easily lead to broader system access.
- Incorporate defensive defaults in configuration: disable or constrain features that automatically consume repository metadata in high-risk contexts unless they are strictly needed and properly hardened.
How teams detect issues like this
Potential detection and assessment techniques include:
- Static analysis:
- Scan for uses of
execSync,exec, or equivalent APIs where arguments are assembled via string concatenation or template literals that include variables derived from Git metadata (branch names, tags, commit messages). - Flag patterns where repository-derived values are passed to shell commands without explicit escaping or validation.
- Code review cues:
- Look for utility functions that wrap Git commands and accept dynamic input from configuration or runtime repository state.
- Pay special attention to new orchestration, AI-selection, or metadata-gathering features that tie into CI/CD pipelines.
- Policy and tooling:
- Enforce development guidelines that prohibit direct shell invocation with untrusted data and require safer alternatives.
- Integrate automated code review tools or linters with rules around command execution APIs and user-controlled inputs.
- Runtime monitoring:
- Enable logging of unusual or unexpected shell commands launched during CI/CD runs.
- Monitor for test jobs invoking commands that do not align with standard WebdriverIO test execution patterns.

