Multi-Hoster-Upload/gateway
Administrator 8d757a99dd fix(diagnostics): harden read-only agent — grep ReDoS, prototype-chain whitelist bypass, redaction gaps
Intensive end-to-end testing (a live gateway-MCP <-> agent integration harness +
an adversarial redaction/abuse probe + an independent security audit) surfaced
three real issues in the shipped read-only diagnostic agent. All run in lib/**,
which is packaged in the app.

1. grep ReDoS froze the Electron main process. read_log compiled the
   client-supplied grep into `new RegExp(grep, 'i')` and ran it synchronously over
   the log tail IN the main process. A catastrophic pattern (e.g. "(a+)+$" against
   a long line) hangs the whole app — empirically confirmed (8s timeout, killed).
   JS regex is synchronous and uncancellable, so grep is now a case-insensitive
   literal substring filter with "|" alternation ("error|timeout|502"). Provably
   linear-time; covers the real diagnostic need.

2. Prototype-chain whitelist bypass. The op table was a plain object literal, so
   handle("constructor" | "toString" | "valueOf", ...) resolved an inherited
   Object.prototype function, passed the `typeof fn === 'function'` guard and
   returned {ok:true}. Harmless functions today, but a whitelist-integrity hole.
   Now guarded with a string check + Object.prototype.hasOwnProperty.

3. Redaction defense-in-depth gaps. redactLogText now also scrubs: basic-auth URL
   passwords (scheme://user:pass@host), Authorization: Basic, JWTs (eyJ...x.y.z),
   and bare/JSON session= values. Mostly theoretical in today's readable logs
   (secret-bearing bodies go to the excluded doodstream-debug.log; other hosters
   throw static strings) but matters as the verbose-logging surface grows.

Verified: 383 app tests (incl. new regression tests for all three), the live
gateway-MCP integration harness (all 14 tools, zero leaks, error paths), the
adversarial probe (14/14+ secret shapes scrubbed, ReDoS 1ms, lockout, malformed
args), e2e gate, lint 0 errors. Only residual: a standalone high-entropy blob with
zero key/Bearer/URL context — inherent to any denylist, acknowledged.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-19 18:40:57 +02:00
..
test fix(diagnostics): harden read-only agent — grep ReDoS, prototype-chain whitelist bypass, redaction gaps 2026-06-19 18:40:57 +02:00
verify fix(diagnostics): harden read-only agent — grep ReDoS, prototype-chain whitelist bypass, redaction gaps 2026-06-19 18:40:57 +02:00
.gitignore feat(diagnostics): MCP gateway + harden redaction so no secret ever leaves the box 2026-06-19 17:39:31 +02:00
agent-client.js feat(diagnostics): MCP gateway + harden redaction so no secret ever leaves the box 2026-06-19 17:39:31 +02:00
code.js feat(diagnostics): MCP gateway + harden redaction so no secret ever leaves the box 2026-06-19 17:39:31 +02:00
index.js feat(diagnostics): MCP gateway + harden redaction so no secret ever leaves the box 2026-06-19 17:39:31 +02:00
package-lock.json feat(diagnostics): MCP gateway + harden redaction so no secret ever leaves the box 2026-06-19 17:39:31 +02:00
package.json feat(diagnostics): MCP gateway + harden redaction so no secret ever leaves the box 2026-06-19 17:39:31 +02:00
README.md feat(diagnostics): MCP gateway + harden redaction so no secret ever leaves the box 2026-06-19 17:39:31 +02:00
registry.example.json feat(diagnostics): MCP gateway + harden redaction so no secret ever leaves the box 2026-06-19 17:39:31 +02:00
registry.js fix(gateway): write the token registry with owner-only permissions (0600) 2026-06-19 17:57:39 +02:00

mhu-diagnostics-gateway

A standalone local stdio MCP gateway for remote, read-only diagnostics of the Multi-Hoster-Uploader app.

It is two things at once:

  • an MCP server to Claude Code (stdio transport), exposing read-only diagnostic tools, and
  • a plain WebSocket client to a diagnostic agent running inside the Electron app on a remote Windows server.

The operator enables "Diagnose-Zugriff" on a server, copies the connection code, and tells Claude server <name> at <host>, code <CODE>. Claude calls connect_server(code, host) and then the read-only diagnostic tools. After the first successful connect the server is remembered under its label, so later you can just say connect_server(label:"prod-3") with no code.

This package is fully self-contained. It does not import anything from the parent Electron app and is not part of the app build.

Install

cd gateway
npm install

Requires Node >= 18.

Register with Claude Code (one time)

claude mcp add --transport stdio mhu-diag -- node "C:\Users\ploet\Desktop\Claude Projekte\multi-hoster-uploader\gateway\index.js"

Adjust the absolute path if you cloned the repo elsewhere.

Usage

In Claude Code, tell Claude:

server prod-3 at 127.0.0.1, code mhu1_<...>

Claude will call connect_server and then diagnostic tools such as server_health (the one-shot "what's wrong" hub), read_log, list_errors, get_queue_state, get_rotation_state, and so on.

Security

  • Read-only. No screen access, no input injection, no writes. Only reads logs, errors, queue/history/config (redacted), rotation and system info.
  • The code is a secret — it carries the auth token. Do not paste it anywhere public.
  • The safe default is to reach the agent over 127.0.0.1 via an SSH local port-forward or WireGuard. See docs/remote-diagnostics-setup.md.
  • registry.json stores tokens and is git-ignored — never commit it.