/

CVE-2026-39862

Severity:

HIGH RISK

(8.8)

OS Command Injection in Tophat macOS Test Harness

CVE-2026-39862

Analyzed

Vulnerability type

Category:

OS Command Injection

CWE:

CWE-78

Impact:

Remote Code Execution on developer workstations via malicious URLs

Severity:

HIGH RISK

(8.8)

CVSS version:

3.1

Catch this CVE while code is being written

Detect vulnerable code directly in pull requests, so CVEs are fixed before merge.

Summary

Tophat's URL handling logic allows attacker-controlled arguments from crafted tophat:// or http://localhost:29070 URLs to be passed directly into /bin/bash -c without sanitization.

When a vulnerable Tophat version is installed on a macOS developer workstation, visiting a malicious link or triggering the local URL handler can result in arbitrary command execution with the developer's user privileges.

Affected context

This vulnerability arises in macOS environments where Tophat is installed and registered as a handler for tophat:// URLs or is listening on http://localhost:29070.

It becomes relevant when:

  • A developer opens or is redirected to a crafted tophat:// URL, or
  • An HTTP request is made to the local Tophat port with attacker-controlled query parameters.

The risk is elevated on previously trusted build hosts where no confirmation dialog is shown before command execution is triggered.

Exploit preconditions

  • Attack surface:
  • Custom URL scheme handler (tophat://) registered in macOS
  • Local HTTP listener on http://localhost:29070
  • Required access:
  • Ability to cause the developer's machine to open or follow a crafted URL
  • This may occur via links in browsers, messaging apps, IDE integrations, or embedded HTML content
  • Trigger point:
  • Tophat parses the incoming URL
  • The arguments query parameter is propagated into a shell command that is executed as /bin/bash -c
  • Why exploitation is possible:
  • User-supplied URL parameters are concatenated or interpolated into a command string without escaping, validation, or allowlisting
  • The command is executed with the developer's user privileges and, for trusted build hosts, without an intervening confirmation dialog

Why this happens

The core issue is classic OS Command Injection (CWE-78) in Tophat's URL handling logic.

Attacker-controlled data from the arguments query parameter is treated as part of a shell command and passed directly to /bin/bash -c.

Instead of treating the URL parameter as opaque data and safely passing it as arguments to a process, the application constructs a shell command string, allowing the attacker to inject arbitrary shell metacharacters and commands.

This pattern reflects a failure to separate data from control, and an over-reliance on a general-purpose shell as a command dispatcher.

Potential impact

  • Execution of arbitrary shell commands with the developer's user privileges
  • Theft or modification of source code and sensitive project files
  • Exfiltration of credentials stored on the workstation (e.g., SSH keys, API tokens)
  • Installation of backdoors, keyloggers, or other persistent malware
  • Lateral movement into internal build systems, CI infrastructure, or source repositories
  • Tampering with build artifacts, leading to supply-chain compromise

General mitigation guidance

Effective mitigation targets both the command construction pattern and the trust boundary around URL inputs:

  • Avoid using shells like /bin/bash -c for executing dynamically built command strings; instead invoke binaries directly with parameterized argument lists.
  • Treat URL components, including query parameters, as untrusted input and validate them against strict schemas and allowlists (e.g., permitted commands, flags, and formats).
  • Normalize and constrain the arguments parameter to a safe, typed representation (enums, booleans, numeric IDs) rather than free-form strings.
  • Where shell usage is unavoidable, apply robust escaping and quoting routines, while still enforcing allowlists on permitted values.
  • Introduce explicit confirmation or consent dialogs for actions triggered via external URLs, especially on systems designated as trusted build hosts.
  • Run the application with least privilege and avoid granting access to unnecessary files, developer tooling, or network resources.

How teams detect issues like this

Detection generally involves identifying risky command execution flows and unsafe URL input handling:

  • Static analysis:
  • Flag uses of /bin/bash, sh, or generic shell interpreters where arguments are constructed via string concatenation or interpolation of request/URL data.
  • Detect paths where URL query parameters (e.g., arguments) reach command execution APIs without validation or normalization.
  • Code review signals:
  • Handlers for custom URL schemes (tophat://) or local HTTP endpoints that translate request parameters into shell commands.
  • Any logic that uses system(), popen(), exec() variants, or equivalent language-specific wrappers with untrusted input.
  • Policy enforcement:
  • Enforce secure coding guidelines that prohibit shell-based command construction from network or URL inputs.
  • Integrate automated checks into CI to block merges when unsafe patterns or missing validation in URL handlers are detected.
  • Runtime monitoring:
  • Monitor for unusual shell invocations spawned from Tophat processes, especially those including URL-like patterns or unexpected arguments.

Sources

SourceLink
github.comgithub.com/Shopify/tophat/pull/139
github.comgithub.com/Shopify/tophat/security/advisories/GHSA-8x8g-6rv5-mgg2

Frequently asked

questions

The code execution occurs on the developer's local macOS workstation, but an attacker can trigger it remotely by causing the system to open a crafted tophat:// URL or by reaching the local HTTP endpoint. There is no need for direct login access to the machine, only the ability to influence what URLs are opened.

No explicit authentication is required within Tophat for the vulnerable path. Exploitation relies on the developer having Tophat installed and the attacker being able to induce the application to handle a malicious URL, which can occur through normal browsing, link-clicking, or interacting with untrusted content.

The safest pattern is to remove shell-based command construction entirely, passing only validated, typed arguments to subprocess APIs that do not involve a shell. Additionally, aggressively constrain and validate URL parameters against strict schemas and predefined allowed values.

Treat all data arriving from URLs, local HTTP endpoints, or inter-app communication channels as untrusted; eliminate or strictly limit shell usage; adopt secure coding standards for command execution; and use static analysis and security-focused code review to flag any flows where untrusted input influences system commands.

Find out what's already
exploitable in your codebase.