GitHub Actions Command Injection via Unsanitized Issue Comment Input
GitHub Actions workflows that directly embed `issue_comment.body` into shell commands without sanitization allow unauthenticated attackers to inject arbitrary shell commands and execute code on runners. This PoC demonstrates escape-and-execute techniques that bypass basic quoting.
CVE References
Affected
Vulnerability Analysis
Class & Root Cause:
This is a shell command injection vulnerability stemming from unsafe variable interpolation in GitHub Actions. The workflow uses ${{ github.event.comment.body }} directly within a run: shell context without escaping or input validation. GitHub Actions evaluates context expressions (${{ }}) before shell execution, inserting attacker-controlled strings directly into the command line. The grep/cut pipeline does not sanitize the output before reuse, creating a second-order injection risk.
Impact: Successful exploitation grants arbitrary command execution on the GitHub Actions runner with the permissions of the workflow environment, potentially allowing attackers to: exfiltrate secrets, modify repository state, trigger malicious builds, compromise dependent projects, or pivot to the hosting infrastructure.
PoC Significance for Defenders
The PoC demonstrates that simple comment payloads can break out of quoted contexts and execute shell commands. The significance lies in proving that: (1) no authentication beyond issue-comment posting is required, (2) the injection occurs before any filtering logic, and (3) the vulnerability is reliably exploitable across standard CI/CD runners. The PoC confirms that basic bash quoting does not protect against context-expression injection.
Detection Guidance
Workflow Code Review Signals:
- Workflows using
github.event.issue_comment.body,github.event.pull_request.body, or similar untrusted inputs inrun:steps - Use of
${{ }}context expressions directly in shell commands without::set-outputor environment variable isolation - Absence of input validation, regex escaping, or shell-safe libraries (e.g.,
shlex.quote())
Log Indicators:
Monitor GitHub Actions run logs for: unexpected command execution, shell metacharacters in workflow output, failed grep/cut commands with unusual input, or errors suggesting command parsing failures.
YARA/Pattern Detection: Flag workflow files (YAML) containing patterns:
run:.*\$\{\{.*github\.event\.(issue_)?comment\.body.*\}\}
Mitigation Steps
Immediate Actions:
-
Input Sanitization: Use
env:to isolate untrusted input before shell execution:env: COMMENT_BODY: ${{ github.event.comment.body }} run: echo "${COMMENT_BODY}" | grep -oE '@njzjz-bot .*' # safer, but still validate -
Workflow Permissions: Restrict
GITHUB_TOKENpermissions to minimum scope; use separate secrets with limited access. -
Input Validation: Explicitly whitelist expected comment formats using strict regex anchors before any command execution.
-
Shell Safety: Use
set -eandset -o pipefail; consider Python/JavaScript steps with proper escaping libraries instead of raw shell. -
Patch/Upgrade: Apply any vendor patches; use GitHub's official actions instead of custom shell scripts where possible.
Risk Assessment
Likelihood in the Wild: High. Many CI/CD pipelines naively interpolate user input; this is a well-known anti-pattern. Public repositories with issue-comment automation are exposed.
Threat Actor Interest: High. Command injection in CI/CD is a critical supply-chain attack vector. Nation-state and financial threat actors directly target CI/CD infrastructure.
Timeline: Exploitation is trivial and requires no special tools; mass scanning for vulnerable workflows is feasible.
Sources