Summary
php-censor versions up to 2.1.6 contain an OS command injection vulnerability in the Webhook Endpoint logic for GitBuild, where the commitId argument is incorporated into shell commands.
A remote attacker who can trigger the webhook with crafted input may execute arbitrary system commands with the privileges of the php-censor process.
Affected context
The vulnerability occurs in php-censor's Webhook Endpoint, specifically within the Git-based build handling in src/Model/Build/GitBuild.php.
It is relevant when:
- php-censor is configured to accept webhook requests (e.g., from Git hosting services)
- The
commitIdparameter from the webhook is used to construct shell commands without robust sanitization or escaping - The underlying environment allows execution of system commands for repository operations (e.g., git checkout, fetch, or clone)
In such setups, hostile input in the commitId field can be propagated into a shell context.
Exploit preconditions
- Attack surface: HTTP(S) Webhook Endpoint exposed to external or internal networks.
- Required access: Ability to send requests to the php-censor webhook URL (often unauthenticated or weakly authenticated in CI/CD setups).
- Trigger point: Submission of a specially crafted
commitIdvalue in a webhook payload that causes the backend to execute a shell command involving that value. - Why exploitation is possible: The application constructs and executes OS commands using untrusted
commitIdinput without consistently applying strict validation, escaping, or safe APIs that avoid invoking a shell.
Why this happens
This is a classic OS command injection issue where user-controlled data is incorporated directly into shell commands.
In GitBuild's webhook processing, the commitId argument influences the construction of command strings passed to the operating system (e.g., through functions that spawn a shell).
Because the input is not adequately constrained to expected formats (such as strict commit hashes) and is not safely parameterized or escaped, attackers can inject additional shell metacharacters and arbitrary commands.
This maps to CWE-78: Improper Neutralization of Special Elements used in an OS Command, and also relates to CWE-77, where command syntax elements are not neutralized before being passed to the interpreter.
Potential impact
- Execution of arbitrary system commands with the privileges of the php-censor service user
- Compromise of the CI/CD environment, including access to build artifacts and environment secrets
- Tampering with source code checkouts and build outputs, leading to supply-chain attacks
- Pivoting to other internal systems reachable from the compromised host
- Exfiltration or destruction of sensitive configuration, logs, and cached credentials
General mitigation guidance
Effective mitigation centers on avoiding direct shell invocation with untrusted data and strictly constraining inputs:
- Prefer high-level, parameterized APIs (e.g., language-native Git libraries or functions that do not invoke a shell) instead of building shell command strings.
- Enforce strict validation on
commitIdand related parameters (e.g., whitelisting hexadecimal SHA-1/SHAx patterns and rejecting anything else). - If shell execution is unavoidable, use APIs that bypass the shell and pass arguments as separate parameters, and apply robust escaping of any user-influenced values.
- Run the CI/CD service with least-privilege OS accounts and minimal filesystem and network permissions to limit blast radius.
- Isolate build runners or workers in separate, constrained environments (containers, VMs) to reduce cross-project impact if a build context is compromised.
- Treat webhook endpoints as semi-trusted at best, and apply authentication or signing (e.g., shared secret, HMAC) to reduce exposure to arbitrary senders.
How teams detect issues like this
Detection typically relies on a combination of code-level analysis and runtime monitoring:
- Static analysis: Configure rules or linters to flag dynamic shell command construction using variables derived from HTTP request parameters or webhook payloads.
- Code review signals: Look for
exec,shell_exec,system, backtick operators, or similar OS command APIs in webhook handling paths, especially where Git operations are implemented. - Security testing: Use targeted fuzzing or dynamic application security testing (DAST) on webhook endpoints, with payloads designed to reveal command injection behavior (e.g., benign command separators that alter responses).
- Operational monitoring: Monitor application and system logs for unexpected command patterns, anomalous Git operations, or processes spawned by the php-censor runtime that do not align with normal build workflows.
- Policy enforcement: Integrate security checks into CI to block new uses of shell-based command execution in network-exposed request handlers.

