Summary
OpenClaw versions prior to 2026.2.15 contain a command option injection flaw in the git-hooks/pre-commit script, where filenames are passed through xargs to git add without a -- separator.
An attacker who can create files whose names begin with dashes can inject git flags, causing ignored files such as .env or other sensitive artifacts to be staged and committed into repository history.
Affected context
This vulnerability appears in development environments that use OpenClaw's provided git pre-commit hook.
The issue is triggered when the hook:
- Collects filenames and pipes them through xargs
- Invokes git add without a protective -- argument
- Operates in repositories where sensitive files are intentionally ignored (e.g., via .gitignore)
It primarily affects workflows where developers routinely rely on the pre-commit hook to control what gets staged and trust it to exclude ignored or sensitive files.
Exploit preconditions
- Attack surface: Local development repository using OpenClaw's git-hooks/pre-commit script
- Required access: Ability to create or rename files in the repository working directory (e.g., a contributor, malicious dependency writing files, or a shared workspace user)
- Trigger point: Running git commit (or any workflow that executes the OpenClaw pre-commit hook)
- Why exploitation is possible: The hook passes filenames directly to xargs and into git add without a -- separator, so filenames beginning with - are interpreted as additional git add options instead of literal paths. This allows crafted filenames to alter git's behavior and stage files that should remain ignored.
Why this happens
At its core, this is an argument/option injection bug in a shell-based workflow, mapping to CWE-77: Command Injection via improper command invocation.
The pre-commit hook composes a shell pipeline where untrusted filenames are treated as part of the command line:
- Filenames are collected and piped through xargs without robust quoting/escaping.
- git add is invoked without the conventional -- separator that signals the end of options.
When filenames start with dash characters, command-line parsers treat them as flags, not data.
This pattern is a common pitfall in shell scripting: failing to distinguish between user-controlled data (filenames) and command options, leading to unintended behavior or security-sensitive side effects.
Potential impact
- Sensitive environment files (e.g., .env) could be staged and committed into the repository history.
- Secrets, API keys, credentials, or tokens stored in ignored files may be exposed to all repository users.
- Internal configuration, debug logs, or temporary artifacts that were meant to stay local could be committed.
- Regulatory or compliance issues if confidential data or personal information is accidentally checked into version control.
- Increased risk of downstream compromise if leaked secrets are reused in production systems or other services.
General mitigation guidance
Effective mitigation focuses on robust command construction and defensive handling of filenames inside scripts:
- Treat filenames as untrusted input and ensure they are passed to tools as data, not parsed as options.
- Use -- to terminate option parsing when calling git add and similar commands, so subsequent tokens are always interpreted as paths.
- Prefer safe invocation patterns such as:
- Using null-delimited filenames with xargs -0 (paired with find -print0 or similar producers).
- Avoiding complex shell pipelines where quoting and escaping are hard to reason about.
- Reduce reliance on hooks for security boundaries; assume that pre-commit automation can fail and back it up with additional review policies.
- Encourage developers to externalize secrets from working directories entirely (e.g., environment managers, secure secret stores) to minimize damage if staging controls fail.
These patterns help ensure that automation scripts behave safely even in the presence of unexpected or adversarial filenames.
How teams detect issues like this
Detection typically combines code-centric review with repository analysis:
- Static analysis / script review:
- Scan shell scripts and hooks for uses of xargs, git add, rm, mv, or similar commands that lack a -- terminator.
- Flag patterns where filenames are piped or expanded directly into command lines without robust quoting or null-delimited handling.
- Use linters or custom CI checks focused on shell safety (e.g., enforcing safe xargs usage).
- Policy enforcement:
- Enforce repository policies that require manual review of changes to git hooks or automation scripts.
- Maintain security baselines for pre-commit hooks and reject scripts that violate safe command-construction rules.
- Repository monitoring:
- Periodically scan git history for sensitive file patterns (e.g., .env, private keys, secrets) and alert on newly introduced sensitive content.
- Use secret-scanning tools in CI/CD to catch leaked credentials early.
Automated code review and security tooling can help surface these issues before they make it into widely adopted hooks or templates.

