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_datato parse or construct commands from incomingargs. - 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
argsargument passed through the WebSocket payload that is ultimately consumed byextract_command_data. - Trigger point: The vulnerable code path is reached when the backend processes the WebSocket message, parses
argsinextract_command_data, and subsequently executes the resulting command or code. - Why exploitation is possible: The implementation appears to interpolate or embed user-controlled
argsinto 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.,
subprocesswithshell=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_datathat 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.

