An attack where a crafted Git branch name containing shell metacharacters or expression syntax is interpolated into a CI/CD script or workflow, causing arbitrary command execution. It can expose pipeline secrets or tokens. Defenders pass untrusted values through environment variables rather than inline interpolation, validate names, and restrict token permissions.
How Branch Name Injection Works
Branch name injection happens when a CI/CD pipeline treats a branch name as trusted text and drops it into a shell command, script expression, or workflow interpolation. Because branch names can be attacker-controlled in pull requests or repository events, the unsafe join point is often the build script itself, not the Git branch object.
The core issue is context confusion. A name that should be handled as data gets interpreted as executable syntax, so characters such as semicolons, quotes, backticks, dollar signs, or expression delimiters can change command flow. That is why this pattern is often grouped with poisoned pipeline execution and other pipeline-injection problems.
Why This Is Dangerous in CI/CD
CI/CD systems usually have access to source code, build artifacts, deployment credentials, and sometimes cloud or package publishing tokens. If an injected branch name reaches a shell with elevated workflow permissions, the attacker may execute arbitrary commands, read secrets, modify artifacts, or pivot into later stages of the delivery chain.
The danger increases when pipeline logic uses privileged triggers, shared runners, or broad default token scopes. A single malformed branch reference can become a route from ordinary pull-request activity to code execution inside trusted automation. That makes the flaw especially important in repositories that accept contributions from outside the core team.
NHIMG’s GitHub Actions Script Injection Guide explains the common GitHub Actions patterns behind this issue, including untrusted event fields, environment-variable isolation, token scoping, and detection approaches.
How Organisations Check Exposure and Reduce Blast Radius
Exposure review starts with identifying every workflow that references branch names, pull-request metadata, or other untrusted event fields in inline shell, expressions, or generated scripts. Teams should also check whether those workflows run on public pull requests, self-hosted runners, or contexts that inherit deployment-level credentials.
The most effective reduction is to keep untrusted values out of executable syntax. Pass them through environment variables or equivalent safe parameters, validate the branch-name format before use, and avoid letting workflow text expand directly into shell commands. Just as importantly, restrict the permissions of the automation token so a successful injection does not inherit unnecessary repository or package rights.
External reviewers can use the baseline guidance in the OWASP Top 10 to anchor the broader principle that untrusted input must never be allowed to alter program behaviour.
Detection, Review, and Related Attack Paths
Detection is about finding where untrusted context fields flow into commands before an attacker does. Static review, workflow linting, and CI rule checks are useful because the risky pattern is usually visible in source: direct interpolation, shell evaluation, or command construction from event data. Code review should pay special attention to any branch-name handling that looks harmless in testing but executes inside a privileged runner.
If exploitation is suspected, review job logs, artifact contents, and any secrets or tokens the job could access. Branch name injection is closely related to poisoned pipeline execution, so post-incident review should look for adjacent abuse paths such as artifact poisoning, privileged pull-request triggers, or follow-on deployment tampering.
The attack path is often short, but the consequences can extend beyond a single build. Once an injected command runs, the pipeline may leak credentials, publish a malicious artifact, or create a trusted foothold for later compromise.
Risk and Threat Considerations
Branch name injection is dangerous because it turns a routine repository label into code execution in a trusted automation context. The main risk is not just build failure, but secret exposure, artifact tampering, and downstream compromise of systems that trust pipeline output.
Failure mechanism: An attacker supplies a branch name that contains shell metacharacters or expression syntax, and the workflow concatenates it into an executable command instead of treating it as inert data.
Impact: The pipeline may run attacker-controlled commands, disclose secrets or tokens, alter build artefacts, or provide a stepping stone into release and deployment infrastructure.
Standards & Framework Alignment
This section maps relevant standards and security frameworks to the operational risks and controls described in this guidance.
MITRE ATT&CK and OWASP Non-Human Identity Top 10 address the attack and risk surface, while CIS Controls v8, NIST SP 800-53 Rev 5 and OWASP ASVS set the governance and control requirements practitioners need to meet.
| Framework | Control / Reference | Relevance |
|---|---|---|
| MITRE ATT&CK | T1190 — Exploit Public-Facing Application | Covers exploitation of exposed workflow paths via attacker-controlled input |
| Recommendation — Hunt for injected workflow input paths and harden exposed CI entry points against command execution. | ||
| CIS Controls v8 | CIS-16 — Application Software Security | Supports secure coding and review of pipeline scripts that process untrusted input |
| Recommendation — Review workflow code for unsafe interpolation and enforce secure script handling patterns. | ||
| NIST SP 800-53 Rev 5 | SA-11 — Developer Testing and Evaluation | Applies when CI/CD code paths need validation against injection defects before release |
| Recommendation — Test pipeline scripts for command injection and verify controls before allowing privileged execution. | ||
| OWASP ASVS | V15 — Secure Coding and Architecture | Directly addresses safe handling of untrusted data in executable code paths |
| Recommendation — Apply secure coding rules that keep branch names and other inputs out of shell interpolation. | ||
| OWASP Non-Human Identity Top 10 | NHI-02 — Secret Leakage | Relevant because successful injection can expose pipeline secrets or tokens |
| Recommendation — Reduce secret exposure in pipelines by separating untrusted input from secret-bearing jobs. | ||
Practitioner Guidance
What to watch for: Any workflow step that combines branch names or other event fields with inline shell, especially in jobs that run on pull requests or inherited credentials. If the branch value must be used, keep it in an environment variable or similarly non-executable channel, and validate it before any downstream use.
Governance implication: Repository owners should treat workflow authorship and token scope as part of delivery security, not just developer convenience. Privileged triggers and broad defaults are where a small input-handling mistake becomes a material pipeline compromise.
Related resources from NHI Mgmt Group
- How should security teams test whether prompt injection telemetry can name the compromised agent?
- How should security teams prevent command injection when an API needs to use a file name or system command on the server side?
- How should teams prevent view name injection in Spring MVC applications that use Thymeleaf?
- Branch Target Injection
Deepen Your Knowledge
Free weekly newsletter
Subscribe to the NHI & AI Identity Journal
The latest on NHI and Agentic AI security – articles, research, breaches, news and events every week.
Bonus 33% off our NHI Course when you subscribe.
Reviewed and updated by the NHIMG editorial team on November 26, 2026.
NHI Mgmt Group — the #1 independent authority on Non-Human Identity, IAM, and Agentic AI security. nhimg.org