/

CVE-2026-42238

Severity:

CRITICAL RISK

(9.8)

Code Injection in nginx-ui

CVE-2026-42238

Analyzed

Vulnerability type

Category:

Code Injection

CWE:

CWE-94

Impact:

Remote Code Execution

Severity:

CRITICAL RISK

(9.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

nginx-ui exposes an unauthenticated backup restore endpoint for the first 10 minutes after startup on fresh installations, allowing remote attackers to upload crafted archives.

By overwriting the application's configuration and injecting commands into the TestConfigCmd setting, an attacker can achieve remote code execution once the application restarts and a follow-up request is made.

Affected context

This vulnerability affects nginx-ui deployments that:

  • Are on versions prior to 2.3.8
  • Run in environments where the application is freshly installed and restarted
  • Expose the nginx-ui HTTP interface over a reachable network (e.g., internet or internal networks)
  • Rely on default or similar configurations where the initial startup "bootstrap" period is used

During the first 10 minutes after process startup on a fresh installation, the backup restore endpoint is left unauthenticated, creating a temporary but highly exposed configuration and database restoration window.

Exploit preconditions

  • Attack surface: HTTP REST API endpoint POST /api/restore exposed by nginx-ui
  • Required access: Network-level access to the nginx-ui interface; no authentication required during the initial startup window
  • Temporal condition: Exploitation must occur within the first 10 minutes after process startup on a fresh installation or a similar bootstrap state
  • Trigger point: Uploading a crafted backup archive that overwrites app.ini and the SQLite database, followed by allowing the application to restart and issuing a request that executes the configured TestConfigCmd
  • Why exploitation is possible: The restore endpoint does not enforce authentication during the bootstrap window, and restored configuration values are trusted and executed as system commands without sufficient validation or restriction.

Why this happens

The core issue is a combination of insecure initialization behavior and command injection via configuration.

During the initial startup phase, the backup restore endpoint is intentionally left unauthenticated, which broadens the attack surface by treating all callers as trusted.

The restore operation overwrites critical configuration (including app.ini) and the SQLite database directly from untrusted input, and the application later executes values from TestConfigCmd as operating system commands.

This maps to CWE-94: Improper Control of Generation of Code ('Code Injection'), as user-controlled configuration values are transformed into executable commands without adequate validation or confinement.

Potential impact

  • Remote execution of arbitrary OS commands as the nginx-ui process user (often root in Docker-based deployments)
  • Complete compromise of the host container or underlying system, depending on privileges and isolation
  • Modification or destruction of nginx-ui configuration and data via the restored SQLite database
  • Use of the compromised instance as a foothold for further lateral movement within the network
  • Deployment of backdoors or persistence mechanisms via configuration and script changes

General mitigation guidance

Effective mitigation focuses on tightening trust boundaries around initialization and configuration execution paths:

  • Require authentication and authorization for all administrative endpoints, including backup restore, regardless of startup phase or installation state
  • Treat backup archives and configuration files as untrusted; validate, sanitize, and restrict their contents before applying them
  • Avoid direct execution of configuration-derived strings as system commands; prefer fixed command templates with parameterized, validated inputs or avoid shell invocation entirely
  • Apply least-privilege principles so the nginx-ui process does not run as root and has minimal filesystem and system access
  • Isolate nginx-ui within hardened containers or sandboxes, limiting the impact of any command execution that does occur
  • Introduce secure-by-default bootstrap flows, such as forcing initial administrator setup behind a temporary secret or out-of-band mechanism instead of unauthenticated endpoints.

How teams detect issues like this

Potential detection and assurance strategies include:

  • Static analysis and code review:
  • Flag endpoints or controllers that bypass authentication or authorization checks, especially those performing high-risk actions such as restore, backup, or configuration changes.
  • Identify code paths where configuration values are passed to shell interpreters, command runners, or APIs that spawn processes (e.g., exec, system, popen).
  • Search for patterns where user-controlled or file-derived strings are concatenated into command lines or scripts.
  • Configuration and policy checks:
  • Enforce policies requiring authentication on administrative HTTP paths, verified via integration tests or automated policy-as-code tools.
  • Mandate non-root runtime users for web management services and verify via deployment manifests and infrastructure-as-code scans.
  • Runtime monitoring:
  • Monitor process activity from nginx-ui containers or hosts for unusual command executions, especially shortly after service startup.
  • Inspect logs for unexpected calls to /api/restore, particularly from external or untrusted IP ranges.
  • Automated tooling:
  • Integrate security linters and SAST tools into CI pipelines to detect command injection patterns and unguarded admin endpoints.

Sources

SourceLink
github.comgithub.com/0xJacky/nginx-ui/releases/tag/v2.3.8
github.comgithub.com/0xJacky/nginx-ui/security/advisories/GHSA-4pvg-prr3-9cxr

Frequently asked

questions

It can be exploited remotely by any attacker who can reach the nginx-ui HTTP interface during the first 10 minutes after process startup on a fresh installation or similar bootstrap state, without needing credentials.

The attacker only needs network access to the nginx-ui service; no prior authentication or local access is required during the vulnerable window, making this suitable for unauthenticated remote exploitation.

The safest pattern is to require strict authentication and authorization for all administrative and configuration-changing endpoints, ensure that configuration data cannot be directly turned into executable commands, and run the service under a non-privileged account with minimal capabilities.

Future designs should avoid unauthenticated bootstrap flows for sensitive actions, treat all configuration and backup inputs as untrusted, enforce strong separation between data and code, apply least-privilege principles to service accounts, and incorporate security reviews or automated checks that specifically look for command execution driven by user-controlled configuration.

Find out what's already
exploitable in your codebase.