Repository navigation
fix(install): block git option injection via --git-dir / OPENCLAW_GIT_DIR - #118927
wjc2821296948 wants to merge 5 commits into
Conversation
P0 — runs `git clone $repo_url $repo_dir`
where $repo_dir is set from the user-facing `--git-dir` (or
`OPENCLAW_GIT_DIR`) argument. git's CLI parses any positional argument
that starts with `-` as a flag, so a caller can pass
`--git-dir '--upload-pack=touch /tmp/pwned'` and have git execute the
specified upload-pack binary during the install.
Steps to reproduce:
curl -fsSL https://openclaw.ai/install-cli.sh | bash -s -- --install-method git --git-dir '--upload-pack=touch /tmp/pwned'
After the fix:
- `parse_args` rejects leading-dash values for `--prefix` and
`--git-dir` (the two path-shaped CLI flags) with an explicit
"Invalid value" error.
- `install_openclaw_from_git` re-checks the resolved repo_dir at the
sink (defense in depth against OPENCLAW_GIT_DIR env-var bypasses).
- `git clone -- "$repo_url" "$repo_dir"` adds an end-of-options
marker so git treats the destination as a positional path even if a
future regression lets a leading-dash value through.
Co-authored-by: cgsdn <[email protected]>
P0 — same vulnerability as the install-cli.sh fix, in the full `install.sh`. `install_openclaw_from_git` runs `git clone $repo_url $repo_dir` and `git -C $repo_dir status` where $repo_dir is sourced from the user-facing `--git-dir` (or `OPENCLAW_GIT_DIR`) argument. Any value that starts with `-` is parsed by git as a flag, e.g. `--git-dir --upload-pack=evil`, giving the installer the ability to execute arbitrary commands during the `git clone` step. After the fix: - `parse_args` rejects leading-dash values for `--git-dir`. - `install_openclaw_from_git` re-checks the resolved repo_dir at the actual sink, so an OPENCLAW_GIT_DIR env override can't bypass the arg parser. - `git clone -- $repo_url $repo_dir` adds an end-of-options marker so git treats the destination as a positional path. Co-authored-by: cgsdn <[email protected]>
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
This comment was marked as spam.
This comment was marked as spam.
|
Codex review: needs real behavior proof before merge. Reviewed August 8, 2026, 10:46 AM ET / 14:46 UTC. ClawSweeper reviewWhat this changesThe branch adds Bash Regression provenancePossible regression — suspected (reviewed change). No predecessor PR is attributed. Merge readiness⛔ Blocked until stronger real behavior proof is added - 12 items remain Do not merge yet: the Bash clone terminator is correct, but the equivalent PowerShell installer path remains unprotected and the new Bash checks reject previously supported dash-prefixed paths. Priority: P0 Review scores
Verification
How this fits togetherOpenClaw installers accept checkout locations from flags and environment variables, then clone or update a Git checkout before launching OpenClaw. Those public inputs cross into Git command execution and must remain compatible with existing checkout paths. flowchart LR
A[Installer flag or environment] --> B[Checkout path handling]
B --> C[Git clone or update]
C --> D[Installed command wrapper]
D --> E[OpenClaw CLI]
Before merge
Findings
Agent review detailsSecurityNeeds attention: The Bash clone protection follows Git's contract, but the equivalent PowerShell public installer boundary remains unprotected. PR surfaceTests 0, Other +76. Total +76 across 3 files. View PR surface stats
Review metrics
Merge-risk optionsMaintainer options:
Technical reviewBest possible solution: Apply one compatible Git-destination policy across Bash and PowerShell, normalize supported relative dash paths before guarding them, remove the unrelated prefix restriction, and add behavior tests plus exact-head proof. Do we have a high-confidence way to reproduce the issue? Yes, source-reproducible: the PowerShell GitDir input reaches an unprotected Is this the best way to solve the issue? No: protecting only Bash is incomplete, and rejecting all dash-prefixed paths breaks existing behavior rather than canonicalizing supported relative paths first. Full review comments:
Overall correctness: patch is incorrect AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against 1e004151c618. LabelsLabel changes:
Label justifications:
EvidenceSecurity concerns:
What I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (20 earlier review cycles; latest 8 shown)
|
P1 — regression from the prior `git clone --` hardening. `git -C`
takes its next token as the directory operand, so
`git -C -- "$repo_dir" status --porcelain` makes git try to change
into a directory literally named `--`. The error
`fatal: cannot change to '--': No such file or directory` is then
swallowed by `|| true`, producing empty stdout — which the existing
test treats as a clean working tree, so a previously dirty checkout
would silently enter the update path. The git-clone boundary still
needs `--` (`git clone -- "$repo_url" "$repo_dir"`), but the
`-C` form needs to keep the path as the immediate operand.
Repro:
$ git init -q /tmp/dirty-test && touch /tmp/dirty-test/modified.txt
$ git -C -- /tmp/dirty-test status --porcelain
fatal: cannot change to '--': No such file or directory
$ git -C /tmp/dirty-test status --porcelain
?? modified.txt
After this fix the dirty-checkout skip path on `main` is preserved
(`git -C "$repo_dir" status --porcelain` again returns the
untracked-file marker), and the option-injection hardening from the
earlier commits still rejects leading-dash `--git-dir` values at
both `parse_args` and the `install_openclaw_from_git` sink.
Co-authored-by: cgsdn <[email protected]>
This comment was marked as spam.
This comment was marked as spam.
This comment was marked as spam.
This comment was marked as spam.
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
This comment was marked as spam.
This comment was marked as spam.
This comment was marked as spam.
This comment was marked as spam.
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
This comment was marked as spam.
This comment was marked as spam.
This comment was marked as spam.
This comment was marked as spam.
|
🦞🧹 I asked ClawSweeper to review this item again. |
This comment was marked as spam.
This comment was marked as spam.
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
This comment was marked as spam.
This comment was marked as spam.
|
🦞👀 Command router queued. I will update this comment with the next step. |
…mmand The test was searching for the old literal 'git clone $repo_url $repo_dir' but the implementation now uses 'git clone -- $repo_url $repo_dir' with the option terminator. Updated the test to match the actual implementation. Co-authored-by: cgsdn <[email protected]>
This comment was marked as spam.
This comment was marked as spam.
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
|
This pull request has been automatically marked as stale due to inactivity. |
|
🦞👀 Command router queued. I will update this comment with the next step. |
|
🦞👀 Command router queued. I will update this comment with the next step. |
What Problem This Solves
scripts/install-cli.shandscripts/install.shboth runwhere
$repo_diris set from the user-facing--git-dir(orOPENCLAW_GIT_DIR) argument. Git's CLI parses any positionalargument starting with
-as a flag, so a user (or any pipeline thattrusts unvalidated input to land in
--git-dir) can pass--git-dir '--upload-pack=touch /tmp/pwned'and have git executethe specified
git-upload-packbinary during the install. This is aclassic option-injection -> RCE pattern (think CVE-2017-1000117,
CVE-2018-17480) and is exploitable directly via
curl … | bash -s -- --install-method git --git-dir ….Reproduction on a clean checkout:
This PR also addresses:
(Windows regression on an existing relative
-namecheckout, astale PowerShell clone assertion, and a test that shadowed the
OPENCLAW_GIT_DIRenv var it claimed to exercise).(caller-supplied
--prefix/OPENCLAW_GIT_DIRwith metacharacterscould inject into the generated
openclaw/pnpmwrappers).with write to
${PREFIX}/bin/redirect the install into asensitive file.
Why This Change Was Made
OpenClaw's install scripts are distributed as
curl -fsSL …/install.sh | bash, so the install surface isinherently public. Any caller-controlled value that lands in an argv
position where git will parse it as an option is a remote-code-execution
sink. The same issue exists in both scripts and needs to be fixed in
both places. The wrapper generator runs after the install completes
but still touches the user's
$PATHand other shared locations, soits inputs need the same hardening.
User Impact
--git-dir '/abs/path/to/repo'(the normalcase) sees no behavior change.
value now gets a clear "Invalid value" error instead of a silent
RCE.
-namecheckout now stays updateable insteadof being refused as a fake flag.
--prefixvalue containing shell metacharacters ($, backticks,\) no longer injects into the generatedopenclaw/pnpmwrapper scripts.
install instead of silently following it into a sensitive target.
Evidence
bash scripts/install-cli.sh --git-dir '-upload-pack=touch /tmp/x'exits with "Invalid value for --git-dir" and
/tmp/xis notcreated.
bash scripts/install-cli.sh --helpstill prints usage.bash -n scripts/install-cli.sh && bash -n scripts/install.shbothpass syntax check.
'$(touch /tmp/pwn)'no longer expands insidethe generated
openclawwrapper (%qtest intest/scripts/install-cli.test.ts).${PREFIX}/bin/openclawor$HOME/.local/bin/openclawpointing at a sensitive file aborts the install with
"Refusing to overwrite symlink at …" and leaves the target intact
(new tests in
test/scripts/install-cli.test.tsandtest/scripts/install-sh.test.ts).test/scripts/install-ps1.test.tsasserts the newIsPathRooted/Join-Pathordering.Findings (severity order)
P0 — git option injection in install scripts
Location:
scripts/install-cli.sh(install_openclaw_from_git,parse_argsfor--git-dir/--prefix) andscripts/install.sh(same functions).
Issue:
git clone <url> <dir>andgit -C <dir> <subcmd>parsea leading-dash
<dir>as a flag (--upload-pack,--exec,--git-dir, etc.). The--git-diruser-facing argument flowsdirectly into both calls with no validation, so
curl … | bash -s -- --install-method git --git-dir '--upload-pack=evil'runs
evilduring install.Fix: reject leading-dash values in
parse_argsfor--git-dirand
--prefix, re-checkrepo_dirat the actual git sink insideinstall_openclaw_from_git(defense in depth againstOPENCLAW_GIT_DIRenv bypasses), and append--to the gitinvocations so the destination is always treated as a positional path.
P1 — Windows Git-install breaks on an existing
-namecheckoutLocation:
scripts/install.ps1:1500-1503.Issue: The original PowerShell hardening only canonicalized the
relative
$RepoDirwhenTest-Path -LiteralPathreturned false. Anexisting relative checkout whose name starts with
-thereforeskipped canonicalization and was immediately refused by the new
leading-dash guard, breaking the Git update path that current
mainserves.
Fix: Canonicalize any leading-dash relative path with
[System.IO.Path]::IsPathRooted($RepoDir)before the existencecheck, then
Join-Path (Get-Location) $RepoDirto produce anabsolute path. The leading-dash guard now only fires if the
canonicalized absolute path still begins with
-. New structuraltest in
test/scripts/install-ps1.test.tsasserts the newordering.
P2 — Stale PowerShell clone assertion
Location:
test/scripts/install-ps1.test.ts:910(original line).Issue: The hardening switched the implementation to
git clone -- $repoUrl $RepoDir, but the existing test stillsearched for
git clone $repoUrl $RepoDir.indexOfreturned-1,which silently passed the ordering comparison and let the regression
go unnoticed.
Fix: Update the literal searched for to
"git clone -- $repoUrl $RepoDir"so the assertion actuallyexercises the real contract.
P2 — OPENCLAW_GIT_DIR test shadowed by a literal argument
Location:
test/scripts/install-sh.test.ts:1071(original line).Issue: The env-var probe named
OPENCLAW_GIT_DIR=-namebutcalled
install_openclaw_from_git '-name'with a literal positionalargument, so the env var never flowed into the function and the test
did not prove what its name claimed.
Fix: Read
OPENCLAW_GIT_DIRintoGIT_DIRinside the testshell (matching the real installer entry path) so the env var value
actually flows through the canonicalization contract.
P2 — Heredoc shell-injection in generated wrapper scripts
Location:
scripts/install-cli.sh:1146-1150,1262-1266, and696-700(npm wrapper, git wrapper, and pnpm-corepack shim).Issue: All three wrappers wrote a heredoc that interpolated
${PREFIX},${repo_dir}, and${PNPM_CMD[0]}unescaped. A callerpassing
--prefix '$(touch /tmp/pwned)'(orOPENCLAW_GIT_DIR/corepack path with shell metacharacters) would have those characters
expanded at install time and embedded in the generated wrapper,
executing arbitrary commands the next time the user ran the CLI.
Fix: Use
printf -v _var '%q' "$value"to shell-escape eachvalue before writing it into the heredoc, matching the existing
pattern in
scripts/install.sh:2978-2979. Added a structural testin
test/scripts/install-cli.test.tsthat fails if a future changere-introduces unescaped interpolation.
P2 — Symlink-following wrapper overwrite
Location:
scripts/install-cli.sh(npm wrapper, git wrapper,pnpm-corepack shim) and
scripts/install.sh(git wrapper).Issue:
cat > filefollows symlinks. A pre-existing symlink atthe wrapper destination (e.g.
${PREFIX}/bin/openclawor$HOME/.local/bin/openclaw) pointing to a sensitive file wouldredirect the heredoc into that target, silently overwriting the
target during install.
Fix:
scripts/install-cli.sh: explicit-Ltest before eachcat >;any symlink at the wrapper destination triggers
fail "Refusing to overwrite symlink at …".rm -falready removes only thesymlink, so the subsequent write creates a fresh regular file in
the intended location.
scripts/install.sh: check the symlink target; only remove it ifit points inside
*/node_modules/openclaw/*(a stale OpenClawupgrade symlink). Any other target aborts the install.
New tests plant a hostile symlink, run the wrapper generator, and
assert both that the install aborts and that the sensitive target
is unchanged.
P2 — Parser-rejection assertions were silent under
set +eLocation:
test/scripts/install-cli.test.ts:95-97andtest/scripts/install-sh.test.ts:1019-1021(original line numbers).Issue: ClawSweeper flagged that the wrapper script ran with
set +e(so the stubbed git's 99 exit would not abort it), whichalso meant the
[[ "$parse_rc" -eq 0 ]]assertion after the parsersubshell could silently fail to terminate the wrapper. A future
regression that made
parse_argsreject a valid relative pathwould pass through the assertion and into the clone checks,
hiding the bug.
Fix: Replace the silent
[[ ]]with an explicit terminatingif [[ ... ]] then echo ... exit 1 fiso a parser rejection failsloudly.
AI-assisted
This PR was prepared with assistance from Claude. The vulnerabilities
were identified by manual review of the installer scripts, the
patches are hand-written, and the install scripts have been
syntax-checked (
bash -n).Co-authored-by: cgsdn [email protected]