Skip to content

SEC: SSH Private Key and Password Transmitted Plaintext in API Response #175

Closed

Description

@vybe

Pentest Finding 3.1.4 — High (CVSS 8.5)

CVSS Vector: CVSS:4.0/AV:L/AC:L/AT:N/PR:L/UI:N/VC:H/VI:H/VA:H/SC:N/SI:N/SA:N

Location: POST /api/agents/{name}/ssh-access — services/ssh_service.py lines 56–83, routers/agents.py line 1368

Impact

When SSH access is enabled with auth_method=key, the server generates an SSH key pair entirely server-side and returns the private key in plaintext in the HTTP response body. The private key is:

  • Transmitted over HTTP (unencrypted by default)
  • Potentially logged by reverse proxies
  • Stored in browser history
  • Accessible in any intermediate system between client and server

Exploitation consequences:

  • Docker network MitM — compromise of any container on the same Docker network yields the private key
  • Host-level attacker — nsenter or tcpdump on the host captures all internal Docker HTTP traffic
  • Key impersonation — server retains every private key ever issued without client knowledge
  • Container takeover — SSH key grants developer shell access to agent containers with credentials, .env files, .mcp.json
  • Credential pivot — once inside a container, injected credentials are directly accessible at /home/developer/.env

Root Cause

services/ssh_service.py lines 56–83 generate the keypair server-side with NoEncryption() and return the private key bytes directly. routers/agents.py line 1368 includes private_key verbatim in the JSON response.

Steps to Reproduce

POST /api/agents/shared/ssh-access
Authorization: Bearer {USER_TOKEN}
# Response includes full unencrypted private key in "private_key" field

Remediation

  • Remove server-side keypair generation entirely — change the API to accept a client-supplied public_key parameter
  • Server only calls inject_ssh_key(public_key) to append to authorized_keys; private key never leaves the client
  • If server-side generation must be kept for UX reasons, mandate TLS-only deployment and suppress logging of the response body
  • Enforce owner-only (not just can_user_access_agent) access on the endpoint

References

Source: UnderDefense Web Pentest Report, March 2026

Activity

  1. added
    priority-p0
    security
    pentest
    severity-high
    on Mar 26, 2026
  2. vybe commented on Mar 26, 2026

    @vybe
    ContributorAuthor

    Fixed in upcoming PR. Changes:

    Root cause: Server-side keypair generation returned private key in plaintext API response.

    Fix:

    • Removed server-side keypair generation entirely (generate_ssh_keypair() and cryptography dependency deleted)
    • Key-based SSH access now requires client-supplied public_key parameter — private key never leaves the client
    • Enforced owner-only access (can_user_delete_agent — admin/owner only, not shared users)
    • Removed private_key field from API response and MCP types
    • Added public key format validation (ssh-ed25519, ssh-rsa, ecdsa-sha2-, etc.)

    Files changed: agent_ssh.py, ssh_service.py, agents.ts, client.ts, types.ts, test_ssh_service.py

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

    pentestpriority-p0securityseverity-high

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions