Severity:

HIGH RISK

(7.3)

Command Injection in gpt-researcher WebSocket Endpoint

CVE-2026-5631

Deferred

Vulnerability type

Category:

Command Injection

CWE:

CWE-74, CWE-94

Impact:

Remote Code Execution

Severity:

HIGH RISK

(7.3)

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

gpt-researcher up to version 3.4.3 contains a command injection vulnerability in the extract_command_data function of backend/server/server_utils.py, reachable via the WebSocket (ws) endpoint.

By manipulating the args argument sent over this endpoint, a remote attacker may inject and execute arbitrary code on the server where gpt-researcher is running.

Affected context

The vulnerability occurs in deployments of gpt-researcher (up to 3.4.3) that expose the WebSocket endpoint and accept user-controlled command arguments (args) from clients.

It is relevant where:

  • The ws endpoint is reachable over a network (e.g., Internet, intranet, or internal service mesh).
  • The backend uses extract_command_data to parse or construct commands from incoming args.
  • The resulting command or code paths are executed without adequate sanitization or validation.

In such environments, user-supplied data can cross the trust boundary from WebSocket input into command or code execution logic.

Exploit preconditions

  • Attack surface: The WebSocket (ws) endpoint exposed by the gpt-researcher backend.
  • Required access: Ability to connect to the ws endpoint and submit crafted messages (no additional local access implied by the CVE description).
  • Input control: Attacker must control the args argument passed through the WebSocket payload that is ultimately consumed by extract_command_data.
  • Trigger point: The vulnerable code path is reached when the backend processes the WebSocket message, parses args in extract_command_data, and subsequently executes the resulting command or code.
  • Why exploitation is possible: The implementation appears to interpolate or embed user-controlled args into a command or code context without robust escaping, validation, or strict parsing, enabling injection of additional instructions (CWE-94 / CWE-74).

Why this happens

This issue stems from mixing untrusted, user-controlled input with command or code execution logic.

The extract_command_data function likely takes args values coming from the ws endpoint and transforms them into a structure that is passed directly to interpreters, shells, or dynamic evaluation mechanisms.

Without strict validation, canonicalization, or use of parameterized execution APIs, the application effectively allows attackers to break out of the intended argument structure and inject new code or commands.

Conceptually, this maps to:

  • CWE-94: Improper Control of Generation of Code ('Code Injection') where data is treated as executable instructions.
  • CWE-74: Improper Neutralization of Special Elements in Output Used by a Downstream Component ('Injection') where crafted input alters the behavior of a downstream interpreter.

Potential impact

  • Remote execution of arbitrary code in the context of the gpt-researcher backend process.
  • Unauthorized access to files and data available to the application environment.
  • Exfiltration or tampering with research content, prompts, or API keys used by the service.
  • Pivoting to other internal systems reachable from the compromised host.
  • Service disruption, including denial of service or full takeover of the application instance.

General mitigation guidance

Effective mitigation focuses on preventing untrusted input from influencing executable commands or code:

  • Constrain execution paths: Use fixed, whitelisted commands or operations; represent user choices as enumerated options rather than free-form text merged into commands.
  • Avoid dynamic evaluation: Refrain from using eval, exec, templated shell calls, or dynamic imports based on untrusted data; replace with explicit, parameterized APIs.
  • Normalize and validate arguments: Apply strong schema validation to args (types, ranges, allowed values) and reject messages that do not conform to strict expectations.
  • Use safe command construction: When shelling out is unavoidable, rely on APIs that accept argument lists (e.g., subprocess with shell=False), and avoid concatenating strings to build commands.
  • Reduce privileges: Run the backend with least privileges, using a dedicated low-privilege account and minimal filesystem and network permissions to limit blast radius.
  • Network hardening: Restrict exposure of the ws endpoint (e.g., internal-only access, authentication and authorization on the WebSocket) to reduce who can supply args.

How teams detect issues like this

Detection efforts can focus on both code and runtime behavior:

  • Static analysis: Define rules to flag:
  • Use of eval, exec, dynamic imports, or shell execution functions where user input from WebSocket handlers flows into execution.
  • String concatenation or formatting that mixes WebSocket payload fields (like args) into command strings.
  • Code review: During manual review, pay special attention to:
  • Functions like extract_command_data that transform user-supplied data into executable operations.
  • Any layer where WebSocket message fields are not validated against a rigid schema before being used.
  • Policy enforcement: Incorporate secure coding guidelines and linters into CI pipelines to prevent merging code paths that perform unchecked dynamic execution.
  • Runtime monitoring: Enable logging and anomaly detection for:
  • Unexpected command patterns originating from the gpt-researcher process.
  • Unusual outbound connections or file access correlated with WebSocket activity.

Sources

SourceLink
github.comgithub.com/assafelovic/gpt-researcher/
github.comgithub.com/assafelovic/gpt-researcher/issues/1694
vuldb.comvuldb.com/submit/785858
vuldb.comvuldb.com/vuln/355419
vuldb.comvuldb.com/vuln/355419/cti

Frequently asked

questions

Yes. The issue affects the WebSocket endpoint, and an attacker who can reach this endpoint and send crafted messages controlling args may trigger the vulnerability remotely.

The attacker must be able to establish a WebSocket connection to the gpt-researcher backend and deliver malicious args. Any additional authentication or network controls in front of the endpoint will influence practical exploitability.

Refactor the code so that untrusted args are treated purely as data under strict schema validation and never directly embedded into executable commands or dynamically evaluated code. Use whitelisted operations and parameterized APIs instead of constructing commands from strings.

Establish coding standards prohibiting dynamic code or shell execution based on user input, apply rigorous input validation for all network-exposed endpoints (including WebSockets), and integrate static analysis and code review practices that specifically look for injection patterns and unsafe execution constructs.

Find out what's already
exploitable in your codebase.