# GHSA-57F3-39RR-2MWM: Nginx-UI certificate path validators read arbitrary absolute paths, enabling a file existence oracle and process-crash DoS

- Database: GitHub
- Severity: CVSS 3.8 (Low)
- Published: 2026-11-20
- Modified: 2026-11-20

## Affected versions

- github.com/0xJacky/Nginx-UI (Go): fixed in 2.9.2

## Description

### Summary

The certificate path validators used by `POST /api/certs` and `POST /api/certs/:id` ran `os.Stat` and an unbounded `os.ReadFile` on any supplied path with no containment. An administrator-equivalent credential could learn whether a path outside the nginx config root exists or holds PEM data (one bit per field, no content returned), and reading a device or FIFO such as `/dev/zero` could block requests or exhaust memory until the supervised process restarted.

### Patches

Fixed on `dev` in [e6b9f3a0f5](https://github.com/0xJacky/nginx-ui/commit/e6b9f3a0f5). Released in 2.9.2. Paths outside the config root are no longer touched (they are treated as externally managed), and files inside it must be regular files of at most 1 MiB, read through a bounded reader. Self-signed key reuse uses the same reader.

### Workarounds

Limit `api:write` tokens and cluster node credentials to trusted automation.

---

## Original report

## Summary

Nginx UI exposes an authenticated certificate management endpoint (`POST /api/certs`) whose request validators accept arbitrary filesystem paths without any containment check. The `ssl_certificate_path` and `ssl_certificate_key_path` fields are validated by custom rules that call `cert.IsCertificatePath` and `cert.IsPrivateKeyPath`, which run `os.Stat` and an unbounded `os.ReadFile` directly on the attacker-supplied path. An authenticated user (by default without any second factor) can therefore use these fields as a file existence and content-type oracle for arbitrary absolute paths such as `/etc/passwd`, and can crash the entire service with a single request by pointing a path at a character device like `/dev/zero`.

## Root Cause

Every other file-reading function in the certificate package confines filesystem access to the configured directory via `helper.IsUnderDirectory` before touching the disk. The two path validators omit that guard entirely: they treat any non-empty string as a candidate path and read it unconditionally. The security invariant that certificate paths must resolve inside an authorized directory is thus enforced everywhere except in the input validation layer that is supposed to screen untrusted user input. Additionally, `os.ReadFile` is called with no size limit and no request timeout, so a path that never reaches EOF (a character device) causes the read to allocate memory without bound.

```go
// internal/cert/helper.go:41
func IsCertificatePath(path string) bool {
    if path == "" {
        return false
    }
    _, err := os.Stat(path)            // helper.go:45 - stat on arbitrary absolute path
    if err != nil {
        if os.IsNotExist(err) {
            return true                // nonexistent path passes validation
        }
        return false
    }
    bytes, err := os.ReadFile(path)    // helper.go:54 - unbounded read of arbitrary path
    if err != nil {
        return false
    }
    return IsCertificate(string(bytes))
}
// internal/cert/helper.go:63 - IsPrivateKeyPath is structurally identical
```

## Impact

The attacker must be an authenticated Nginx UI user who can reach the certificate API. In the default configuration no second factor is required, because the secure-session middleware passes the request through when the user has no OTP, two-factor, or passkey enabled. With that access the attacker gains two capabilities:

1. A reliable file existence and content-type oracle for any absolute path readable by the Nginx UI process. The response differs depending on whether the target path exists and whether its content parses as a PEM certificate or private key, so the attacker can probe for the presence of arbitrary files (for example configuration, key material, or application state) even though the file contents are not returned verbatim.
2. A denial of service that terminates the whole service. Because the read is unbounded, pointing a path field at a character device such as `/dev/zero` or `/dev/urandom` makes the request goroutine allocate memory until the process is killed. A single request takes the service down, and the attack is repeatable after each restart.

## Proof of Concept

```text
Prerequisites:
- A running Nginx UI instance (default configuration, no 2FA enrolled for the account).
- A valid session token for any authenticated user.
```

File existence / content-type oracle. Send a certificate path pointing at the probed file and a key path pointing at a guaranteed-nonexistent file to isolate the oracle to the certificate field:

```bash
# Target exists but is not a PEM certificate -> validation fails (HTTP 406)
curl -sS -X POST "https://TARGET/api/certs" \
  -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"ssl_certificate_path":"/etc/passwd","ssl_certificate_key_path":"/nonexistent/key.pem"}' -o /dev/null -w "%{http_code}\n"

# Target does not exist -> certificate_path validator returns true (HTTP 200/201 or a later-stage error)
curl -sS -X POST "https://TARGET/api/certs" \
  -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"ssl_certificate_path":"/nonexistent/cert.pem","ssl_certificate_key_path":"/nonexistent/key.pem"}' -o /dev/null -w "%{http_code}\n"
```

Denial of service. A single request pointing a path field at `/dev/zero` drives an unbounded `os.ReadFile` and exhausts process memory:

```bash
curl -sS -X POST "https://TARGET/api/certs" \
  -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"ssl_certificate_path":"/dev/zero","ssl_certificate_key_path":"/nonexistent/key.pem"}'
```

```text
Expected observations:
- The two oracle requests return distinguishable HTTP status codes (existing non-PEM file -> 406;
  nonexistent path -> validation passes), revealing file existence.
- The /dev/zero request causes the Nginx UI process memory to grow without bound until the process
  is OOM-killed, interrupting service for all users.
```

## Attack Chain

1. **Exposure:** The attacker reaches `POST /api/certs`. The route is registered in `api/certificate/router.go:28` inside a group that applies `middleware.AuthRequired` (`router/routers.go:108`), so a valid session token is required but any authenticated user qualifies.
2. **Control:** The attacker fully controls the JSON body fields `ssl_certificate_path` and `ssl_certificate_key_path`. The raw string values reach validation without normalization or sanitization.
3. **Path:** `AddCert` (`api/certificate/certificate.go:117`) registers the rules `"ssl_certificate_path": "required,certificate_path"` and `"ssl_certificate_key_path": "required,privatekey_path"` (lines 121 and 122). The Cosy `Create` flow runs validation before any other hook, dispatching the `certificate_path` and `privatekey_path` tags to the custom validators registered in `internal/validation/validation.go:25`, which delegate to `cert.IsCertificatePath` and `cert.IsPrivateKeyPath`.
4. **Guard:** The secure-session gate (`middleware.RequireSecureSession`, `api/certificate/router.go:26`) is a no-op for default users: `userNeedsSecureSession` (`internal/middleware/secure_session.go`) returns false unless OTP, two-factor, or passkey is enabled, so the request passes through with no second factor. At the validator itself there is no path containment check of any kind.
5. **Primitive:** `cert.IsCertificatePath` (`internal/cert/helper.go:41`) calls `os.Stat` (line 45) and `os.ReadFile` (line 54) on the attacker-supplied path; `cert.IsPrivateKeyPath` (line 63) does the same.
6. **Result:** The differential validation outcome yields a file existence and content-type oracle for arbitrary paths, and an unbounded `os.ReadFile` against a character device crashes the entire Nginx UI process, denying service to all users.

## Bypass Evidence

The relevant protection is the certificate package's own directory-containment convention: functions that read certificate material call `helper.IsUnderDirectory` before any filesystem access (for example in `internal/cert/cert_info.go`, `internal/cert/write_file.go`, and `internal/cert/download.go`). The two path validators do not. `grep -n 'IsUnderDirectory' internal/cert/helper.go` returns no results, confirming that `IsCertificatePath` and `IsPrivateKeyPath` perform `os.Stat` and `os.ReadFile` with no containment. The strongest disproof attempts (that the Cosy framework, upstream middleware, or the `BeforeExecuteHook` might sanitize the path, or that the secure-session gate would block default users) were each checked against the source and failed: validation runs before `BeforeExecuteHook`, no middleware inspects JSON body values, and the secure-session gate is bypassed when no second factor is enrolled. The DoS was examined against Go's `os.ReadFile` behavior: for a character device whose `Stat` size is zero, the read grows its buffer in a loop that never reaches EOF, and no request timeout or context cancellation bounds the validation call.

## Affected Versions

- **Ecosystem:** `go`
- **Package:** `github.com/0xJacky/Nginx-UI`
- **Confirmed affected range:** `>= 2.8.0, <= 2.9.0`
- **Latest release checked:** `v2.9.0` ([GitHub release](https://github.com/0xJacky/nginx-ui/releases/tag/v2.9.0))
- **Fix status:** not fixed

The unguarded `IsCertificatePath` and `IsPrivateKeyPath` validators have been present since `internal/cert/helper.go` was introduced in the v2.8.0 release line and remain present in the latest published release `v2.9.0`, as well as on the current development branch. No release removes the vulnerable code or adds a containment check to these validators.

## Suggested Fix

Enforce the certificate directory boundary inside the path validators, consistent with the rest of the certificate package. Before calling `os.Stat` or `os.ReadFile`, verify that the supplied path resolves inside the authorized directory using the existing `helper.IsUnderDirectory` check, and reject paths that fall outside it. The validator should also avoid reading unbounded or non-regular files: confirm the target is a regular file and cap the number of bytes read (for example with `io.LimitReader`) so that a character device or very large file cannot exhaust process memory. As an interim mitigation, operators can enroll a second factor for all accounts, which forces the certificate endpoints through the secure-session gate, and restrict network access to the Nginx UI management interface; neither fully removes the underlying path handling defect.

---

Reported by zx.

## References

- https://github.com/0xJacky/nginx-ui/security/advisories/GHSA-57f3-39rr-2mwm

Page: https://cve.now/GHSA-57F3-39RR-2MWM

Wrong or missing data? Send feedback: POST https://cve.now/api/v1/feedback (see https://cve.now/agents#feedback).
