Skip to main content
Menu
Advisories

JwtSecret Overwrite via Settings API Causes Session Invalidation and Monopoly

GHSA-2RJR-44WX-8QPGPublished Updated GitHub

Description

An administrator session or an api:write service token could overwrite JwtSecret through the app settings write. That invalidates every issued session at once, and the change persists in app.ini. Users can sign in again immediately, because sessions are issued and checked with the current secret, so this is a recoverable forced logout rather than an exclusive takeover.

Patches

Fixed in 2.9.1 (fecb2a8d71): settings writes always keep the saved JwtSecret; it can only be changed in app.ini.

Workarounds

Limit api:write tokens to trusted automation.

---

Original report

The maintainer narrowed the following points: the prerequisite is an administrator-equivalent credential rather than "any authenticated user"; "session monopoly" and "recovery requires direct server access" do not hold, since other users can sign in again right away.

Summary

The JwtSecret field in the cosy framework's App struct lacks the protected:"true" tag, allowing any authenticated user to overwrite it via POST /api/settings/app. This immediately invalidates ALL existing JWT sessions and allows the attacker to monopolize access. This is a regression — the v1 struct had protected:"true" on JwtSecret, and restore.go still treats it as a protected field.

Details

The JwtSecret field in the cosy framework's App struct lacks the protected:"true" tag, allowing any authenticated user to overwrite it via POST /api/settings/app. This immediately invalidates ALL existing JWT sessions (since they were signed with the old secret), and the attacker can log in again to hold the only valid session.

Evidence This Is a Regression

  1. The v1 struct (settings/server_v1.go line 19) had protected:"true" on JwtSecret — it was removed during the cosy framework migration.
  2. The restore function (settings/restore.go lines 20-27) explicitly lists JwtSecret in protectedFields:
protectedFields: map[string]struct{}{
    "JwtSecret": {},
}

This proves the maintainer knows JwtSecret needs protection.

  1. Inconsistency with other protected fields:

| Field | Has protected:"true" | Controls | |-------|----------------------|----------| | Terminal.StartCmd | YES | Command execution | | Logrotate.CMD | YES | Command execution | | Crypto.Secret | YES | Encryption key | | Casdoor.* (all fields) | YES | SSO authentication | | OIDC.* (all fields) | YES | SSO authentication | | JwtSecret | NO | ALL JWT authentication |

JwtSecret, which controls the validity of every session in the system, is the only authentication-critical field missing protection.

Note on Token Forgery

Direct JWT forgery does NOT work because GetTokenUser() (internal/user/user.go lines 161-185) performs a dual check: JWT signature validation AND exact token string lookup in the auth_tokens database table. A forged JWT with a valid signature but no matching DB row is rejected. The real impact is session invalidation and monopoly, not token forgery.

Proof of concept

Step 1: Login as any user and note the JWT token.

Step 2: Overwrite JwtSecret:

POST /api/settings/app
Content-Type: application/json
Authorization: Bearer <jwt>

{"jwt_secret": "attacker-controlled-secret"}

Result: HTTP 200 — accepted.

Step 3: Verify ALL existing sessions are killed:

GET /api/users
Authorization: Bearer <old-jwt>

Result: HTTP 403 — session invalidated.

Step 4: Verify other sensitive fields ARE correctly protected (proving this is a gap):

POST /api/settings/terminal
Content-Type: application/json

{"start_cmd": "/bin/evil"}

Result: Terminal.StartCmd remains unchanged — protected:"true" works correctly on other fields.

Step 5: Login again — the attacker is now the only user with a valid session.

Step 6: Verify persistence — survives server restarts:

cat /etc/nginx-ui/app.ini | grep JwtSecret
# JwtSecret = attacker-controlled-secret

Full automated PoC tested on Docker (nginx-ui latest).

Impact

  • Immediate session invalidation for ALL users (Denial of Service)
  • Session monopoly — attacker is the only user with valid access after re-login
  • Persistent — written to app.ini, survives server restarts
  • Recovery requires direct server access — other admins must SSH in and manually edit app.ini to restore access. In cloud/containerized deployments, this may require infrastructure-level intervention.

Suggested Fix

Add protected:"true" to the JwtSecret field in the cosy App struct, consistent with:

  • How it was protected in the v1 struct (settings/server_v1.go line 19)
  • How restore.go treats it as protected (lines 20-27)
  • How all other security-critical fields (Terminal.StartCmd, Logrotate.CMD, Crypto.Secret, Casdoor/OIDC) are protected

Affected versions

References

GitHub · 0xJacky/nginx-ui