# GHSA-C2CQ-7453-7XPJ: Read-only service tokens still receive stored secrets (incomplete fix of GHSA-pw4f-pq6v-x57r)

- Database: GitHub
- Severity: CVSS 6.5 (Medium)
- Published: 2026-11-20
- Modified: 2026-11-20

## Affected versions

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

## Description

### Summary

`api:read` service tokens are meant to be read-only and must not receive stored secrets. The fix for GHSA-pw4f-pq6v-x57r redacted credentials only on the DNS credential, ACME account and S3 auto-backup endpoints. A token with `api:read` but without `api:write` still received stored secrets on other read paths:

- certificate private keys from `GET /api/certs/:id`, from `GET /api/config` reads of key files, and from configuration history
- notifier configuration values (SMTP passwords, bot tokens, webhook secrets) from `GET /api/external_notifies` and `/:id`
- site health-check header values, request bodies and URL credentials from `GET /api/site_navigation`, `/site_navigation/health_check/:id` and the `site_navigation_ws` feed
- DNS provider credentials nested in `GET /api/dns/domains` and `/:id`
- files Nginx reads secrets from (password files, session ticket keys, `auth_basic_user_file`) through `GET /api/config`
- the same content through the MCP `nginx_config_get` and `nginx_config_history` tools for tokens with `mcp:read` but without `mcp:write`, and through the cluster proxy

Interactive administrators and `api:write` tokens are trusted management credentials and are not affected by this advisory.

### Impact

A holder of a read-only service token could obtain reusable third-party credentials and TLS private keys. The downstream impact depends on what those credentials grant.

### Patches

Fixed on `dev` in [1f08595a9f](https://github.com/0xJacky/nginx-ui/commit/1f08595a9f) and [f531af6e45](https://github.com/0xJacky/nginx-ui/commit/f531af6e45). Released in 2.9.2. Read-only tokens now receive these values as `__NGINX_UI_REDACTED__`, and reads of secret files are refused with error 40019.

### Workarounds

Issue `api:read` tokens only to automation you would trust with the stored credentials, or revoke them until you can upgrade.

### Credits

Reported independently by several researchers; the earlier reports were consolidated here.

---

## Original report

#### Summary

Read-scoped service tokens disclose live TLS private keys via GET /api/certs/:id. Nginx-UI redacts DNS, ACME and S3 secrets for api:read tokens but omits the check here, so a read-only token returns the private key of every certificate nginx serves.

### Details

# Summary

Nginx-UI ships a scoped service-token mechanism. A token minted with the `api:read` scope is meant to read operational data without being able to mutate anything. The codebase enforces that boundary with a redaction pattern: on the read paths for DNS credentials, ACME users and auto-backup configurations, the handler checks `internalmcp.IsServiceTokenRequest(c)` and, when true, swaps the record for a redacted copy that omits the secret fields.

The certificate detail endpoint does not participate in that pattern. `GET /api/certs/:id` returns the on-disk private key PEM verbatim.

An attacker who holds any `api:read` service token - a token an administrator may have issued for a read-only monitoring integration, a status page, or a CI job - can therefore read the private key of any certificate the gateway actually serves.

# Affected code

`api/certificate/certificate.go`, `Transformer()`:

```go
if certModel.SSLCertificateKeyPath != "" &&
    helper.IsUnderDirectory(certModel.SSLCertificateKeyPath, nginx.GetConfPath()) {
    if _, err := nginx.Stat(certModel.SSLCertificateKeyPath); err == nil {
        sslCertificationKeyBytes, _ = nginx.ReadFile(certModel.SSLCertificateKeyPath)
        if !cert.IsPrivateKey(string(sslCertificationKeyBytes)) {
            sslCertificationKeyBytes = []byte{}
        }
    }
}

return &APICertificate{
    Cert:              certModel,
    SSLCertificate:    string(sslCertificationBytes),
    SSLCertificateKey: string(sslCertificationKeyBytes),
    ...
}
```

`api/certificate/certificate.go`, `GetCert()`:

```go
func GetCert(c *gin.Context) {
    q := query.Cert
    id := cast.ToUint64(c.Param("id"))
    ...
    certModel, err := q.FirstByID(id)
    if err != nil {
        cosy.ErrHandler(c, err)
        return
    }
    c.JSON(http.StatusOK, Transformer(certModel))
}
```

There is no `IsServiceTokenRequest` branch, so the same payload is returned to a service token and to a full administrator session.

The `IsUnderDirectory(..., nginx.GetConfPath())` guard is what makes this severe rather than cosmetic: `nginx.GetConfPath()` resolves to the directory nginx is actually configured with (`internal/nginx/resolve_path.go:108`), so the file that is read back is the live private key that nginx presents for the corresponding `server` block, not a stale or unused copy.

# Why this is a scope violation and not an intended capability

The redaction pattern is applied consistently to the other three credential-bearing read endpoints:

- `api/certificate/dns_credential.go:42` and `:67` - `redactDnsCredential`
- `api/certificate/acme_user.go:45` and `:100` - `redactAcmeUser`
- `api/backup/auto_backup.go:70` and `:121` - `redactAutoBackup`

For example:

```go
func GetDnsCredential(c *gin.Context) {
    ...
    if internalmcp.IsServiceTokenRequest(c) {
        c.JSON(http.StatusOK, redactDnsCredential(dnsCredential))
        return
    }
    ...
}
```

The redaction field map used by the cluster proxy, `internal/middleware/proxy.go:31`, likewise enumerates exactly those credential families:

```go
var serviceTokenRedactedResponseFields = map[string][]string{
    "/api/acme_users":          {"eab_key_id", "eab_hmac_key"},
    "/api/acme_users/:id":      {"eab_key_id", "eab_hmac_key"},
    "/api/auto_backup":         {"s3_access_key_id", "s3_secret_access_key"},
    "/api/auto_backup/:id":     {"s3_access_key_id", "s3_secret_access_key"},
    "/api/dns_credentials":     {"config", "configuration", "links"},
    "/api/dns_credentials/:id": {"config", "configuration", "links"},
}
```

There is no certificate entry. The certificate detail endpoint is the one credential-bearing read endpoint that was never wired into the redaction mechanism, which indicates an omission rather than a deliberate decision to expose private keys to `api:read` tokens.

Note also that the list endpoint is already safe: `GetCertList` in `api/certificate/certificate.go:66` uses a transformer that returns only `Cert`, `CertificateInfo`, `DeploymentStatus` and `UsedBy`, and never populates `SSLCertificateKey`. Only the detail endpoint leaks.

# Impact

The private key is the credential that lets an attacker present a certificate for the affected domain. Possession of the key allows:

- impersonating the site to clients that pin or validate the certificate chain;
- decrypting previously captured traffic for that hostname when the key is reused across key rotations;
- defeating TLS-based trust decisions in internal or partner integrations that trust the gateway's certificate.

Because the guard restricts the read to certificates whose key file lives under the nginx configuration directory, the disclosed key is always one that is in active service. On a gateway that terminates TLS for multiple domains, a single `api:read` token discloses all of them.

The same token can also be used through the cluster proxy path: `router/routers.go:120` mounts `certificate.InitCertificateRouter(g)` on the group that carries `middleware.AuthRequired()` and `middleware.Proxy()`, and `internal/middleware/proxy.go` forwards the request to the selected node without applying any certificate-specific redaction.

# Scope and preconditions

- The attacker needs a valid `api:read` service token. Tokens are minted through `POST /api/service_tokens` (or the compatibility alias `POST /api/mcp/tokens`), which requires an interactive administrator plus a secure-session step-up (`mcp/service_tokens.go:43-46`).
- A service token is a machine credential intended to be embedded in an integration. The read scope is advertised to operators as the safe scope to hand out for monitoring and reporting.
- No further privilege is required: the scope check in `internal/middleware/middleware.go:118-129` classifies every GET request as `api:read` unless the path appears in `serviceTokenWriteGETPaths`, and `/api/certs/:id` is not listed there.

# Fix suggestion

Apply the existing redaction pattern to the certificate detail path: when `internalmcp.IsServiceTokenRequest(c)` is true, omit `SSLCertificateKey` from the response, the same way `redactDnsCredential` and `redactAcmeUser` omit their secret fields. Add the corresponding entry to `serviceTokenRedactedResponseFields` in `internal/middleware/proxy.go` so the cluster-proxy path is covered as well.

# Relation to the previously fixed advisory GHSA-pw4f-pq6v-x57r

This is not a duplicate of GHSA-pw4f-pq6v-x57r ("Read-scoped service tokens could disclose stored infrastructure credentials", fixed in commit 9594b04de86728cfee8112d52f1eb0f3203032e6, 2026-09-20). That advisory covered three credential families only - DNS provider secrets, ACME External Account Binding keys, and S3-compatible backup credentials - and the upstream fix enumerated them by hand.

The upstream fix added a regression test, `internal/middleware/sensitive_read_endpoints_test.go`, whose setup registers exactly three routers:

```go
certificateapi.InitDNSCredentialRouter(group)
certificateapi.InitAcmeUserRouter(group)
backupapi.InitAutoBackupRouter(group)
```

`certificateapi.InitCertificateRouter` is not registered there, and neither is the external-notification router. The same three-entry enumeration is still present on the current `dev` branch. The redaction mechanism is therefore endpoint-enumerated rather than applied by response inspection, and the certificate detail endpoint was never added to the list.

Concretely, the certificate endpoint differs from the three that were fixed in two ways: it is not covered by the upstream regression test, and it returns a credential - the TLS private key of a live nginx certificate - that the three already-fixed endpoints never expose. The upstream `serviceTokenRedactedResponseFields` map in `internal/middleware/proxy.go` likewise has no certificate entry.

The fix for GHSA-pw4f-pq6v-x57r therefore does not close this issue; the certificate read path still returns the key to a read-scoped token on the current `dev` branch (verified against `dev` at `api/certificate/certificate.go`, which contains no `IsServiceTokenRequest` check).


### Proof of concept

# Preconditions

- A running Nginx-UI instance with at least one certificate whose private key is stored under the nginx configuration directory (the default layout).
- A service token minted with the `api:read` scope.

# Step 1 - mint a read-scoped service token

As an administrator with a secure session:

```bash
curl -k -X POST 'https://<host>/api/service_tokens' \
  -H 'Authorization: Bearer <admin_session_token>' \
  -H 'Content-Type: application/json' \
  -d '{"name":"read-only-integration","scopes":["api:read"]}'
```

The response contains the raw token in the `token` field. Record it as `$SVC`.

# Step 2 - list the certificates

```bash
curl -k 'https://<host>/api/certs' -H "Authorization: Bearer $SVC"
```

This returns the certificate list. Note the `id` of the target certificate. This list contains no private key, which is expected.

# Step 3 - read one certificate with the read-scoped token

```bash
curl -k 'https://<host>/api/certs/<ID>' -H "Authorization: Bearer $SVC"
```

# Expected observation

The JSON response contains a `SSLCertificateKey` field whose value is the PEM-encoded private key:

```
"SSLCertificateKey": "-----BEGIN PRIVATE KEY-----\nMIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQ...\n-----END PRIVATE KEY-----\n"
```

# Control - the same token against the other credential endpoints

The endpoints that implement the redaction pattern do not leak:

```bash
curl -k 'https://<host>/api/dns_credentials/<ID>' -H "Authorization: Bearer $SVC"
curl -k 'https://<host>/api/acme_users/<ID>'  -H "Authorization: Bearer $SVC"
```

Neither response contains the provider configuration, the EAB key id, or the EAB HMAC key.

# Vulnerable-behaviour criterion

The issue is present when a token carrying only the `api:read` scope receives a response for `/api/certs/:id` that contains a `SSLCertificateKey` value starting with `-----BEGIN` and ending with `PRIVATE KEY-----`, while the same token receives redacted responses from `/api/dns_credentials/:id` and `/api/acme_users/:id`.

# Impact check

The key can be checked against the live certificate. Comparing the public modulus of the returned `SSLCertificate` with the private key confirms the pair belongs to the certificate nginx is serving for the affected domain.


### Impact

A service token limited to the `api:read` scope discloses the cleartext TLS private key of any certificate whose key file resides under the nginx configuration directory. The directory check guarantees the disclosed key is the one nginx actively presents, so the token yields the credential needed to impersonate the affected site: it can be used to satisfy certificate validation for that hostname, to decrypt previously captured traffic for it across key reuse, and to defeat TLS trust in internal or partner integrations that rely on the gateway's certificate. On a gateway terminating TLS for multiple domains, one read-only token exposes every one of them. The vulnerability is a scope violation rather than a missing authorization check: the same response body is returned to an `api:read` token and to a full administrator session, even though the codebase already redacts credentials for `api:read` tokens on the DNS credential, ACME user and auto-backup read paths. Since service tokens are machine credentials meant to be embedded in read-only integrations, an operator who issued a read-only token for monitoring or status reporting has unknowingly handed out the site's private keys.

## References

- https://github.com/0xJacky/nginx-ui/security/advisories/GHSA-c2cq-7453-7xpj

Page: https://cve.now/GHSA-C2CQ-7453-7XPJ

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