Skip to main content
Menu
Advisories

code-graph-rag OS command injection

GHSA-WVXG-744G-6PCGPublished Updated GitHub

Description

The execute_shell_command tool restricts which programs a model-issued shell command may run through two layers: a base-command allowlist (SHELL_COMMAND_ALLOWLIST) and, independently, a regex blacklist that vetoes specific dangerous constructs even for allowlisted commands (SHELL_DANGEROUS_PATTERNS_SEGMENT). xargs is on the allowlist. Neither layer stops xargs from launching an arbitrary interpreter (python3, perl, ruby, node, …) that is itself not on the allowlist, and the one blacklist rule meant to catch exactly this case (python.*-c.*(import os|__import__('os'))) only fires when the Python one-liner imports the os module by name. Using subprocess (or pty, ctypes, etc.) instead of os slips past every check. The result is unconfined code execution — not sandboxed to the project root, not limited to the allowlisted command set — gated only by whichever approval step is in effect (a single human click in default mode, or nothing at all in --yolo mode).

This is the same vulnerability class as two already-fixed and published advisories on this repo, GHSA-4p93-4vf7-4m8r (find -exec bypassing approval) and GHSA-2rr7-8xrw-gmhr (git config planting an RCE backdoor): a benign-looking, allowlisted command that is actually a generic "run anything" primitive the allowlist/blacklist never anticipated. This is a distinct vector (xargs + interpreter, not find or git) that is not covered by either fix.

Details (exact file:line citations, verified against commit 4de119c744976a24f8170817bf4ec866b19432f6, current main, package version 0.0.770 on PyPI)

  • codebase_rag/config.py:231-259 — SHELL_COMMAND_ALLOWLIST includes xargs (line 257) and awk/sed alongside it. python3/python/perl/ruby/node are not in this set — they cannot be run as a shell segment's own base command.
  • codebase_rag/tools/shell_command.py:251-274 (_validate_segment) only checks cmd_parts[0] — the segment's own base command — against the allowlist. Whatever program xargs is told to invoke as its own arguments is never checked against SHELL_COMMAND_ALLOWLIST at all, because it is not cmd_parts[0] of any segment the parser sees.
  • codebase_rag/tools/shell_command.py:176-180 (_check_segment_patterns) and codebase_rag/constants/security.py:267-316 (SHELL_DANGEROUS_PATTERNS_SEGMENT) are the only remaining control. The relevant entries are:
  • security.py:300: r"python.*-c.*(import\s+os|__import__\s*\(\s*['\"]os['\"]\s*\))" — requires the literal substring import os (or __import__('os')) to appear after -c.
  • security.py:313-315: xargs.*(rm|chmod|chown|mv|dd|mkfs), xargs -I.*sh, xargs.*bash — cover a few specific xargs invocation shapes, not arbitrary-interpreter invocation.
  • None of these match a command that runs python3 -c "..." through xargs when the Python code imports subprocess (or any module other than the literal token os) instead of os.
  • codebase_rag/tools/shell_command.py:230-248 (_is_dangerous_command) — the only other gate applied to the segment — checks the blocked-command set (SHELL_DANGEROUS_COMMANDS, none of which is python/xargs), the rm -rf check, the git config exec-key check, and then falls through to _check_segment_patterns above. Nothing else inspects the segment.
  • codebase_rag/tools/shell_command.py:404-517 (ShellCommander.execute) runs the segment with asyncio.create_subprocess_exec(executable, *cmd_parts[1:], cwd=self.project_root, env=env) once validation passes — no seccomp, no container, no path confinement on what the spawned interpreter itself then does. Interpreter code execution is not filesystem I/O the way cat/sed are, so the project-root confinement that other tools enforce (validate_project_path, the noninteractive path-escape checks in the same file) has no relevance here at all.
  • codebase_rag/tools/shell_command.py:285-324 (_requires_approval) returns True for this command (xargs is not in SHELL_READ_ONLY_COMMANDS, config.py:267-271), so in default mode the model must present it via ApprovalRequired (shell_command.py:526-535) and a human must click approve once. In --yolo mode (is_yolo() true, wired at main.py:1808 and checked at shell_command.py:530-531), the approval check is skipped entirely and the command runs unattended the instant the model emits it.
  • The noninteractive wrapper (create_noninteractive_shell_command_tool, shell_command.py:747-768) is NOT vulnerable to this: xargs is absent from SHELL_NONINTERACTIVE_READ_COMMANDS (config.py:281-294), so _noninteractive_denial rejects any segment whose base command isn't in that read-only set before it ever reaches the pattern checks. This report is scoped to the interactive/approval and yolo paths.

Proof of Concept

Ran directly against the checked-out repo's own ShellCommander.execute() coroutine (not a mock), from a Python REPL with codebase_rag on sys.path:

from codebase_rag.tools.shell_command import _validate_segment
from codebase_rag.config import settings
_validate_segment(
    'xargs python3 -c "import subprocess;subprocess.call([\'id\'])"',
    ", ".join(sorted(settings.SHELL_COMMAND_ALLOWLIST)),
    bypass_allowlist=False,
)
# -> None   (i.e. VALIDATION PASSES — the segment is accepted)

End-to-end against the real ShellCommander:

import asyncio
from codebase_rag.tools.shell_command import ShellCommander, _requires_approval

cmd = 'echo x | xargs python3 -c "import subprocess;subprocess.call([\'id\'])"'
print(_requires_approval(cmd))   # True — the model must request approval

sc = ShellCommander(project_root=".", timeout=10)
result = asyncio.run(sc.execute(cmd))
print(result.return_code, result.stdout)

Output:

requires_approval: True
return_code: 0
stdout: uid=501(mr.syedanas) gid=20(staff) groups=20(staff),12(everyone),...

id ran and returned the real invoking user's identity, proving arbitrary code execution through a fully "validated" (allowlist-passed, blacklist-passed) shell segment. id here stands in for anything subprocess.call(...) can run — reading ~/.ssh, ~/.aws/credentials, writing outside the project root, or reaching the network — none of it confined by any check in this file.

Impact

Any orchestrator model call to execute_shell_command with a segment shaped like xargs <interpreter> -c "<code avoiding the literal token 'os'>" passes every safety check this tool applies and reaches full, unconfined code execution as the code-graph-rag process user. In default mode this needs one human approval click on a command that reads as an ordinary batch-processing invocation (the exact "looks legitimate enough to approve" framing the two prior published advisories on this repo call out as the realistic path: a mistaken model tool call, or prompt injection from analysed repository/web content coaxing the model into presenting and justifying the command). In --yolo mode it needs no human step at all — the model can trigger it unattended the moment it decides to (e.g., steered by prompt injection encountered while indexing or researching). Because the executing payload is interpreter code rather than a shell built-in, the project-root confinement that protects every other tool in this codebase (file read/write/edit, directory listing, structural search/replace) simply does not apply: this is not a path-traversal bug, it is a full command-execution sandbox escape from inside the one tool whose entire design purpose is to keep model-issued commands confined.

Suggested Fix

The allowlist-of-first-token design cannot be made safe for commands like xargs, awk, and sed that are themselves general-purpose program launchers — a denylist of "known bad" invocation patterns will always be incomplete (this report demonstrates the existing import os pattern is trivially evaded by module choice alone, without touching xargs at all). Two independent fixes are both warranted:

  1. For xargs specifically: parse its own arguments and validate the command it will invoke (everything after -I/-n/-L/etc., or the trailing positional command) against SHELL_COMMAND_ALLOWLIST the same way the segment's own base command is validated, the same way _option_carries_file_input already does targeted argument-level inspection for sort/wc/rg. Treat a xargs invocation with no explicit trailing command (bare xargs, which defaults to echo) as the only unconditionally safe form.
  2. Drop or tighten the python.*-c.*import os pattern's premise: it cannot be fixed by adding more module names to a blacklist (perl/ruby/node/php one-liners, python -c with subprocess/pty/ctypes, or simply piping to python - are all equally unmatched). Either deny interpreter one-liners (-c/-e) entirely regardless of import content when reached through an allowlisted launcher like xargs, or remove interpreters as viable xargs-launched targets altogether and require them to go through the allowlist directly (where they are currently, correctly, absent).

Note on prior contact

This finding was originally sent by email on 30 Aug 2026 to eheva87@gmail.com (Vitali Avagyan, repo owner and verified commit author) because GitHub Security Advisory reporting appeared unreachable at the time. Re-filing here through the proper GHSA channel now that it's accessible; no reply was received on the email.

I'd appreciate being credited by name (Syed Anas Mohiuddin) if this results in a fix, changelog entry, or advisory — happy to provide any additional detail needed for that.

Reported by: Syed Anas Mohiuddin, independent security researcher

---

Addendum: additional vectors of the same class found while fixing this (added during triage)

Fixing the reported xargs <interpreter> -c vector required confining the allowlisted launchers generally. That work surfaced seven further bypasses of the same confinement, each verified executing end-to-end against the real ShellCommander — not a mock — with is_yolo=lambda: True. Two of them are arbitrary command execution and reproduce on unpatched main (c6d28ed0, version 0.0.819), so they are in scope for this advisory rather than being introduced by the fix.

The two that affect shipped code

1. git --git-dir=DIR / -C DIR / --work-tree=DIR — arbitrary command execution.

Git reads the target repository's config and executes what it finds there: alias.* = !cmd, core.fsmonitor, core.pager. Pointing git at any directory the caller can write is therefore RCE, not merely a read escape outside the project root.

Verified against unpatched main (c6d28ed0), with an alias.pwn = "!touch MARKER" planted in a scratch repo outside the project root:

sc = ShellCommander(project_root=str(base/'proj'), is_yolo=lambda: True)
asyncio.run(sc.execute(f'git --git-dir={base}/evil/.git pwn'))
# -> rc = 0,  MARKER created

Reachability matches the originally reported vector exactly: _validate_segment returns None in both modes, and _requires_approval returns True — so it is one human approval click in default mode, and nothing at all under --yolo.

2. git --exec-path=DIR — arbitrary command execution.

--exec-path relocates the directory git resolves subcommands in, so any non-builtin name execs DIR/git-<name>. A planted git-pwn ran with rc=0. Only the attached form redirects; bare and space-separated --exec-path print git's own libexec path and ignore the operand (checked against git itself), so only --exec-path=VALUE needs refusing.

The five in the launcher-confinement fix itself

These were introduced or left open by the in-progress fix on fix/shell-launcher-rce, and are recorded here because they illustrate the failure mode rather than because they affect a release:

SpellingEffect
sed -ne p -e 'w FILE' inwrote 6584 bytes outside the working directory, rc=0
sed -nf script.sed inran a script file the validator cannot read, rc=0
sed -ni bak 'w FILE' inwrote outside the project root, rc=0 (180 spellings)
sed -li bak 'w FILE' inwrote outside the project root, rc=0 (103 spellings)
xargs git --git-dir=DIR pwnvector 1 above, nested behind the launcher (7 spellings)

The four sed cases are one defect seen four times: bundled short-flag clusters were not decomposed when collecting scripts, so -ne read its own tail letter e as the script and the real payload in the following slot was never scanned. Each successive fix closed one tail of the gap and left another open.

Why this matters for the fix design

This reinforces the reporter's original argument in the Impact section. Two observations from the fix work:

  • Spelling-based reasoning loses to a second valid reading of the same bytes. BSD and GNU sed disagree about whether -i and -l take an operand; -l is value-taking under GNU and a pure boolean under BSD. Any scanner that commits to one manual's reading steps over the script under the other. The guard has to scan both readings, unconditionally — every attempt to pick one by inspecting a token's shape became a bypass.
  • A guard placed outside the launcher recursion is not a guard. The first version of the --git-dir fix ran only on the top-level segment, so xargs git --git-dir=EVIL pwn executed while the direct spelling was refused. The repository already carries a regression test for this invariant (test_nesting_under_xargs_never_weakens_the_decision) whose comment records two earlier rounds breaking it; this made three. Every new guard must live inside _validate_segment so the nested-command recursion re-applies it.

Suggested scope decision

The two git vectors above are the same severity class as the vector this advisory was filed for, present in shipped code, and not covered by GHSA-4p93-4vf7-4m8r or GHSA-2rr7-8xrw-gmhr (which cover find -exec and git config respectively). They should either be folded into this advisory's affected-version and patch metadata, or filed as a separate advisory that references this one. Flagging for the maintainer's decision rather than assuming either.

Affected versions

References

GitHub · vitali87/code-graph-rag