Skip to content

Security Alert | Two High-Severity Flaws in Bagel MCP — Prompt Injection to Database File R/W and rsync Remote Code Execution

Nov 29, 20266 min
TL;DRBagel MCP's query_messages SQL tool and its rsync file-sync task both let an LLM pass through unconstrained input. A prompt injected into any content the agent reads can make it read/write arbitrary files, SSRF, or execute commands on the server. Fixed in 2.5.5 — upgrade with pip install -U bagel-mcp.

Look up & save

Loading dictionary…

中文版

What Happened

Security researcher Syed Anas Mohiuddin — maintainer of mcp-safeguard, an open-source MCP/agent security scanner — found two flaws in Bagel, an MCP server commonly wired into ROS/MQTT pipelines to control robots, drones, and IoT devices. One lets LLM-generated SQL run against an unrestricted DuckDB connection; the other lets an rsync file-sync task's options be injected with arbitrary flags. Both share the same root cause: the attacker never has to touch the server directly — they only need to poison content the LLM reads. The vendor fixed both in version 2.5.5, and both now have CVE IDs.

Key Facts

ItemValue
TypePrompt injection → arbitrary file read/write / SSRF / remote code execution
ScopeAll bagel-mcp (PyPI) releases before 2.5.5; common in robotics/IoT agent integrations
SeverityCVE-2026-138027 (unsandboxed DuckDB SQL): CVSS 4.0 7.7 High, rated Critical by the reporter; CVE-2026-138028 (rsync argument injection): CVSS 4.0 7.7 High / CVSS 3.1 7.5 High
CVECVE-2026-138027, CVE-2026-138028
SourcesGitHub Security Advisory GHSA-gx2g-3pch-43q5, NVD CVE-2026-138027, OpenCVE CVE-2026-138028, VulnCheck advisory

Attack Surface Analysis

Both paths start the same way — poison content the LLM will read — and then exploit a tool that places no limits on the input it accepts.

The first is the query_messages MCP tool. Its own documentation shows the LLM raw SQL syntax as the expected input, and that string is handed straight to a shared DuckDB connection: no SELECT-only restriction, no external-access lockdown. The reporter verified locally that this alone is enough to read any file with read_csv_auto('/etc/passwd'), write files with COPY ... TO, and even run INSTALL httpfs; LOAD httpfs; to reach internal network endpoints (such as cloud metadata services) and have the response dropped straight into the tool's JSON output — a built-in SSRF channel. An attacker never has to call the tool themselves; they only need to hide an instruction in a log entry, message topic, or other content the agent reads, and let the LLM talk itself into calling it.

The second is the RsyncFilesToLocalDirectory file-sync task. The code blocks only two flags — --quiet and --log-format — but not -e/--rsh (rsync's own "use this program as the transport") or --rsync-path. An LLM steered by prompt injection only has to drop options: ["-e", "sh -c '...'"] into the pipeline config; that value flows straight into the assembled command = ["rsync", *self._options, ...] and executes — two flag names are enough to walk around the entire allowlist and run arbitrary commands with the Bagel server process's privileges.

Mapped to the OWASP LLM Top 10: both flaws are LLM01 Prompt Injection widening the attack surface from "user input" to "anything the LLM reads," compounded by LLM06 Excessive Agency — query_messages was designed to run arbitrary SQL, and the rsync task used a two-keyword denylist instead of a real allowlist. In both cases the tool's granted power far exceeds what "look up a message" or "sync a file" actually requires.

Poisoned content tricks Bagel MCP into running malicious SQL or commands
Poisoned content tricks Bagel MCP into running malicious SQL or commandsAttacker-controlled content hides instructions in logs or message topics the LLM reads, steering it into calling Bagel's tools along two paths — one to arbitrary file read/write and SSRF, the other to command execution on the server. ALT [SQL] [rsync] hidden instruction query_messages file leak -e sh -c ... runs as command Log / message source LLM Agent Bagel MCP Server
  1. A log or message topic carries a hidden instruction the LLM reads
  2. The LLM is steered into calling query_messages with malicious SQL
  3. Bagel returns file contents or SSRF results to the LLM
  4. The LLM is steered into calling run_pipeline with an rsync -e flag
  5. The Bagel server runs the injected argument as a command

Defense

Immediate actions

  • Check your installed version: pip show bagel-mcp; upgrade immediately if below 2.5.5: pip install -U bagel-mcp (or uvx bagel-mcp@latest; Docker users should pull the 2.5.5 image)
  • If you can't upgrade yet, disable or remove the query_messages tool, and manually strip any -e, --rsh, or --rsync-path from every rsync task's options in your pipeline configs
  • Audit past pipeline logs for unexpected SQL (especially read_csv_auto, COPY ... TO, httpfs) or rsync commands carrying -e/--rsh

Long-term architecture

  • Any tool that lets an LLM generate SQL or shell arguments needs a real parser-based allowlist (SELECT-only, a fixed set of flags) — not a "block a few keywords" denylist. Both flaws here slipped past exactly that kind of denylist
  • Run SQL execution and external-command connections under a dedicated, minimally privileged account; keep cloud credentials and SSH keys out of the process environment; extensible engines like DuckDB should have enable_external_access disabled and configuration locked
  • Before deploying, scan MCP server source with Snyk's Agent Scan (formerly Invariant Labs) or Protect AI's supply-chain scanning tools to catch this exact pattern — documentation that demonstrates a dangerous usage the code doesn't actually constrain
  • Log the full argument vector, the triggering user/agent identity, and the source content that drove the decision; for tools that spawn subprocesses like rsync, alert on remote-shell/remote-binary flag combinations

Impact

Bagel is typically deployed on hosts wired to ROS, MQTT, and other robotics/IoT control protocols. Together, the two flaws mean an attacker needs no credentials at all — only the ability to get a poisoned log entry or message topic in front of the LLM driving the agent. From there they could use the SQL flaw to steal connection credentials or scan the internal network, then use the rsync flaw to run commands on the machine running Bagel — a machine that may well be issuing commands to physical devices. Both CVEs were disclosed on 2026-11-27, with the fixed version shipping the same day; neither is in the CISA KEV catalog and there's no evidence of active exploitation. But because the trigger condition is as low as "get the LLM to read it," any deployment running Bagel should check its version immediately.

Today's Takeaway

Neither root cause here is novel — SQL injection and argument injection are old problems. What's new is who can trigger them: these flaws used to require an attacker hitting an API directly; now it's enough to poison any text the agent reads into context — a log line, a message topic, file contents. That's a reminder that reviewing an MCP tool means asking not just "could this tool be misused?" but "does the documentation fed to the LLM itself demonstrate a dangerous usage?" — Bagel's query_messages docs demonstrated raw SQL syntax as the expected input.

References