Summary
A command injection flaw in the wrangler pages deploy command allows arbitrary shell command execution when the --commit-hash parameter is attacker-controlled.
In CI/CD or automated deployment pipelines that pass untrusted or indirectly controlled values into --commit-hash, an attacker could execute commands on the system running Wrangler and compromise build or deployment infrastructure.
Affected context
The vulnerability occurs in environments where Cloudflare Wrangler is used to deploy Pages applications via the wrangler pages deploy command and the --commit-hash argument is set dynamically.
It is most relevant in CI/CD pipelines, deployment scripts, or shared tooling where:
- The
--commit-hashvalue may come from external systems (e.g., webhooks, PR metadata, user-controlled refs, or other automation). - The pipeline assumes commit identifiers are safe and does not sanitize them before invoking Wrangler.
Local, manually run deployments are generally less exposed, unless a user copies or passes untrusted values directly into the --commit-hash flag.
Exploit preconditions
- Attack surface: Systems that execute
wrangler pages deploy(CI runners, build agents, deployment servers, or developer machines). - Required access: Ability to influence or control the value passed to the
--commit-hashparameter (e.g., via manipulated repository state, configuration, environment variables, or pipeline inputs). - Trigger point: Execution of
wrangler pages deploy --commit-hash "<attacker-controlled value>", where the value is propagated into the vulnerable shell command. - Why exploitation is possible: The
commitHashvariable is interpolated directly into a shell command template (e.g.,execSync(\git show -s --format=%B ${commitHash}\)) without validation or escaping.
Shell metacharacters in the commit-hash string are interpreted by the underlying shell, enabling arbitrary command execution.
Why this happens
This issue stems from unsafe construction of shell commands from user-influenced input.
The commitHash value, derived from the --commit-hash CLI argument, is inserted directly into a shell command string executed via execSync (or equivalent).
Because the input is neither validated nor safely escaped, shell metacharacters (such as command separators, redirection operators, or subshell syntax) are treated as part of the command line rather than as data.
Conceptually, this is a case of improper input validation (CWE-20) that manifests as command injection, closely aligned with CWE-78: Improper Neutralization of Special Elements used in an OS Command.
The insecure pattern is: user-controlled or externally sourced text is concatenated into shell commands rather than passed as separate arguments to a non-shell API.
Potential impact
- Execute arbitrary shell commands on the CI runner or machine running Wrangler.
- Read and exfiltrate environment variables, including secrets, API tokens, and credentials used in the pipeline.
- Modify, replace, or backdoor build artifacts before deployment.
- Install persistent tooling or backdoors on build or deployment hosts.
- Pivot to other internal resources accessible from the compromised runner.
- Disrupt deployments, cause denial of service in the pipeline, or corrupt application releases.
General mitigation guidance
Effective mitigation focuses on preventing user-controlled data from being interpreted as shell syntax and tightening trust boundaries around deployment parameters.
Pattern-based mitigations include:
- Avoiding shell interpretation: Use APIs that execute commands without invoking a shell, passing arguments as arrays rather than interpolated strings.
- Strict input validation: Treat commit hashes and similar identifiers as opaque tokens and validate them against a strict pattern (e.g., allowed characters and length).
- Escaping and neutralization: Where shell usage is unavoidable, consistently escape all user-influenced input using well-reviewed escape utilities, and avoid mixing trusted and untrusted segments in a single command line.
- Configuration hardening: In CI/CD pipelines, ensure variables feeding
--commit-hashcome only from trusted sources and are not directly derived from user input or unreviewed metadata. - Least privilege: Run CI runners and deployment agents with minimal permissions, restricting access to secrets, file systems, and networks so that any command execution has constrained impact.
- Defensive defaults: Prefer deployment workflows that do not require explicit commit-hash overrides unless strictly necessary, reducing the exposed attack surface.
How teams detect issues like this
Detection is best approached through a mix of code analysis, configuration review, and runtime monitoring.
Potential strategies:
- Static analysis: Configure rules to flag direct string interpolation of CLI or environment variables into
exec,execSync,spawnwithshell: true, or comparable APIs. - Code review signals: Treat any shell command construction involving user-supplied or externally derived values (CLI arguments, environment variables, configuration fields) as high risk and require explicit validation and escaping.
- Policy enforcement: Enforce internal guidelines that prohibit shell invocation from deployment tooling unless necessary, and require the use of safer child process APIs with structured arguments.
- Pipeline configuration scanning: Periodically review CI configuration files (e.g., GitHub Actions, GitLab CI, CircleCI configs) to identify workflows where untrusted inputs are fed into
wrangler pages deploywith--commit-hash. - Runtime monitoring: Monitor CI runners for anomalous command patterns, unexpected network connections, or access to sensitive files during deploy jobs, using logs and EDR tooling to catch suspicious activity.

