A branch name beginning with a hyphen is parsed as a git option by add-and-commit, allowing a forced overwrite of remote history
Description
Improper Neutralization of Argument Delimiters in a Command (CWE-88) in add-and-commit, in src/main.ts, from 5.0.0 before 11.0.0. A party who controls the branch name a workflow passes to the action can make it run git checkout and git push with an option of their choosing.
The new_branch input, called branch before 8.0.0, is used as a single positional value. It is never passed through matchGitArgs() and never validated, unlike add, remove, commit, fetch, pull, push, tag and tag_push, which the README documents as taking raw git arguments. action.yml describes new_branch only as the name of the branch to create.
src/main.ts hands the value to simple-git's checkout(), which builds the argument vector ['checkout', value], and on the default push path to push(), which builds ['push', 'origin', value, '--set-upstream']. Nothing goes through a shell, but git parses every element of its own argument vector for a leading hyphen wherever that element appears, so a value of --force is taken as the option and not as a branch name.
The two commands that actually run are git checkout --force, which discards the staged changes the action was about to commit, and git push origin --force --set-upstream, which overwrites the remote branch with the runner's local state. Any commit pushed to that branch since the runner's checkout is removed from its reachable history.
A branch whose name begins with a hyphen can be created. git's reference name rules permit it, and only the git branch porcelain refuses such a name, so one ordinary command with explicit refspec syntax is enough. A workflow that derives new_branch from a head branch name therefore takes the value from whoever opened the pull request.
Nothing in the output says what happened. The action logs that the branch already existed and reports committed and pushed as true, while its own commit was discarded before it was made.
Vulnerability type (CWE)
- CWE-88: Improper Neutralization of Argument Delimiters in a Command (Argument Injection)
Affected versions
add-and-commit from 5.0.0 before 11.0.0. Default status: unaffected.
5.0.0, released 27 September 2020, is the first version with a branch input and the first in which that input reaches git checkout and git push as a positional value. 4.4.0 and everything before it have no such input. 11.0.0, released 9 August 2026, is the first version that validates it.
Checked by reading every one of the 51 semantic version tags. The unvalidated positional use is continuous from 5.0.0 to 10.0.0 across the rename of the input from branch to new_branch at 8.0.0, and assertValidBranchName first appears at 11.0.0.
The three git behaviours the finding rests on were confirmed locally rather than taken from the report. git check-ref-format refs/heads/--force exits 0, so the reference name rules accept it. git branch -- --force fails with "'--force' is not a valid branch name", so only the porcelain refuses it. git push origin HEAD:refs/heads/--force creates refs/heads/--force on the remote.
Score (CVSS 4.0)
Medium (6.3)
CVSS:4.0/AV:N/AC:L/AT:P/PR:N/UI:N/VC:N/VI:L/VA:N/SC:L/SI:L/SA:N
The attack vector is Network because the branch name arrives as repository event data. The attack complexity is Low, since there is nothing to defeat: the value is a literal option string. The attack requirements are Present because the workflow has to pass an attacker-influenceable value into the input, which is a configuration outside the attacker's control. The privileges required are None, as opening a pull request from a fork grants no privilege over the target repository. The user interaction is None because the workflow runs on the event with nobody acting.
Confidentiality on the vulnerable system is None: nothing is read. Integrity on the vulnerable system is Low because the action's own staged work is discarded and its reported outputs no longer describe what it did. On the subsequent system, the repository the job holds a token for, confidentiality is Low and integrity is Low for the change to the branch's history. Availability is None on both.
Solution
Upgrade to add-and-commit 11.0.0 or later.
On an affected version, do not derive new_branch from a value an outside contributor controls, such as a head branch name. Where it has to be dynamic, reject any value beginning with a hyphen in a preceding step.
Patch
Commit b4a01347, through pull request #755, released in 11.0.0.
An assertValidBranchName() function is added to src/util.ts and runs before the value is used. It rejects an empty value, a value beginning with a hyphen, and any value containing C0 or C1 controls, DEL or Unicode whitespace, then defers to git check-ref-format --branch for the rest.
The call sites change shape as well. checkout() receives the value inside an array, branch creation becomes checkout(['-b', targetBranch]) rather than checkoutLocalBranch(), and the default push path no longer passes the branch name positionally.
Credits
- Lois del Río Somoza - finder
- Xoán M. Otero Jorge - analyst
- Darío Rivas - analyst
- Secur0 CNA - coordinator
- Federico Grandi @EndBug - remediation developer Discovery source: External
Official record: CVE-2026-142541
Related records
- CVE-2026-142525 - user-controlled inputs written to the job log unescaped in the same action