Skip to content

execSSH buffers unbounded output and mis-decodes multibyte UTF-8 #98

Closed

Description

@TMHSDigital

Summary

execSSH buffers stdout and stderr with no size limit and decodes each chunk on its own, and some lines params have no maximum. Large outputs are held in memory and pushed whole into the MCP response and the model context.

Where

  • mcp-server/src/utils/ssh-api.ts:107-108,138-143 (stdout += data.toString())
  • mcp-server/src/tools/logSearch.ts (lines is .int().positive() with no .max())
  • mcp-server/src/tools/serviceLogs.ts:9-15
  • mcp-server/src/utils/ssh-api.ts:132 (code === null resolves as success)
  • mcp-server/src/utils/ssh-api.ts:98 (any HOMELAB_DRY_RUN value other than "false" enables dry-run, including "0")

Details

  • homelab_serviceLogs {lines: 1000000} or a Trivy table across all images can return tens of MB.
  • Decoding chunk by chunk corrupts multibyte UTF-8 characters that are split across chunks.
  • A remote process killed by a signal (for example the OOM killer) exits with code null and is treated as success with partial output.

Suggested fix

  • Collect raw Buffers and decode once at the end, or use StringDecoder.
  • Cap the buffered output (for example 1 MB), keep the tail, and append a [truncated] marker.
  • Add .max() to every lines param.
  • Treat a signal exit as a failure.
  • Parse HOMELAB_DRY_RUN as a boolean (true/1/yes).

Acceptance criteria

  • Output larger than the cap is truncated with a marker
  • Unit tests with a mocked ssh2 client cover the cap, the signal exit, and multibyte data

Getting started

  • Relevant files: mcp-server/src/utils/ssh-api.ts, logSearch.ts, serviceLogs.ts
  • How to run tests: cd mcp-server && npm test

Filed by repo-audit/full-audit at 9cfe5e3. Severity: medium. Effort: S. audit-key: performance|mcp-server/src/utils/ssh-api.ts|execSSH stdout buffer

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    performanceseverity: medium

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions