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/restoreexposed 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.iniand 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.

