# GHSA-97PJ-XRFH-GCFM: WebSocket short tokens still authenticate the HTTP MCP endpoint (incomplete fix of GHSA-gp79-j356-rr7m)

- Database: GitHub
- Severity: CVSS 8.1 (High)
- Published: 2026-10-22
- Modified: 2026-10-22

## Affected versions

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

## Description

**Class**: authentication bypass (CWE-287 improper authentication) — incomplete fix of GHSA-gp79-j356-rr7m

## Details

Repository `0xJacky/nginx-ui`, file `mcp/router.go` lines 87–91 (`mcpAuthRequired`), unfixed at HEAD `d875dbd2` (v2.8.4). A second authentication middleware still accepts a 16-character WebSocket short token as an HTTP `Authorization: Bearer` credential on `POST /mcp` and `POST /mcp_message`. The GHSA-gp79-j356-rr7m fix removed this branch from `AuthRequired()` only.

## Summary

The fix for GHSA-gp79-j356-rr7m (commit 1b022804ea20e99053f1a0514416c851f1f34d1d) removed the short-token branch from the general HTTP middleware `AuthRequired()` in `internal/middleware/middleware.go` and replaced it with an explicit rejection:

```go
// internal/middleware/middleware.go:284-288 (fixed)
if len(token) <= 16 {
    // Short tokens are only valid on AuthRequiredWS routes.
    abortWithAuthFailure()
    return
}
```

The advisory's own regression test encodes the invariant in its name: `TestShortTokenOnlyAuthenticatesWebSocketRoutes` (`api/user/short_token_security_test.go`). The fix did not touch `mcpAuthRequired()`, a separate authentication middleware used by the MCP endpoints, which still contains the identical pre-fix short-token branch:

```go
// mcp/router.go:82-97 (still present at HEAD d875dbd2)
if token != "" {
    var (
        currentUser *model.User
        ok          bool
    )
    if len(token) <= 16 {
        currentUser, ok = user.GetTokenUserByShortToken(token)   // <-- sink
    } else {
        currentUser, ok = user.GetTokenUser(token)
    }
    if ok {
        c.Set("user", currentUser)
        c.Next()
        return
    }
}
```

`mcp.InitRouter` is registered unconditionally (`router/routers.go:69`) with no feature flag, so the endpoint is reachable whenever nginx-ui is. The fix's file list (api/user/auth.go, api/user/short_token.go, internal/middleware/middleware.go, internal/user/*, model/user.go) does not include mcp/router.go, which was last modified by the earlier MCP parser fix (66471391) and is unchanged at HEAD.

## Impact

A party holding a WebSocket short token (the same pre-requisite as GHSA-gp79-j356-rr7m) can authenticate to the HTTP MCP endpoint and invoke MCP management tools. `authorizeMCPToolRequest()` classifies each call: read-classified tools (`nginx_config_get`, `nginx_config_list`, `nginx_status`, …) require no secure session, so a short token reaches them directly. For an account without OTP/passkey, `userNeedsSecureSession()` returns false, so even write-classified tools (`nginx_config_add`, `nginx_config_modify`, `reload_nginx`, `restart_nginx`) clear `RequireSecureSession` — the same escalation path that made the original advisory HIGH. This is the residual "access management APIs" half of GHSA-gp79-j356-rr7m; the "renew after logout" half is fixed by the session binding, and this sink is distinct from the `AuthRequired` sink that was fixed.

## PoC

Executed against HEAD d875dbd2 with the source-built test `mcp/router_shorttoken_proof_test.go`:

```
GOWORK=off go test -tags=unembed -run TestMCPAcceptsWebSocketShortTokenOnHTTP ./mcp/ -v
```

The test mints a normal login session for a non-OTP user and reads the paired 16-character short token from the `AuthToken` row, then sends it to three routes. Observed output:

```
control (garbage token) status=403 body={"message":"Authorization failed"}
short-token AuthRequired /api/nginx/status status=403
short-token /mcp_message status=400 body={"jsonrpc":"2.0","id":null,"error":{"code":-32602,"message":"Missing sessionId"}}
```

Line 1 shows the endpoint rejects a bad credential. Line 2 shows the same short token is correctly rejected (403) by the fixed `AuthRequired()`. Line 3 shows the same short token is accepted on `POST /mcp_message` — the request passed `mcpAuthRequired` and reached the MCP server, which only reports the missing transport `sessionId`. A caller completes the MCP `initialize` handshake to obtain a `sessionId` and then dispatches tools with the same short token.

## Suggested fix

Apply the same rejection in `mcpAuthRequired()`:

```go
if len(token) <= 16 {
    c.AbortWithStatusJSON(http.StatusForbidden, gin.H{"message": "Authorization failed"})
    return
}
u, ok := user.GetTokenUser(token)
```

Preferably, centralise short-token resolution behind a single helper that only `AuthRequiredWS` may call, so a future authentication middleware cannot reintroduce the branch. A regression test should assert the short token is rejected on `/mcp` and `/mcp_message` as it already is on `AuthRequired` routes.

## References

- https://github.com/0xJacky/nginx-ui/security/advisories/GHSA-97pj-xrfh-gcfm

Page: https://cve.now/GHSA-97PJ-XRFH-GCFM

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