You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fix(admin): #320 block forged JWTs when admin credentials are empty - #325
When the optional admin or admin-next service runs without both ADMIN_USER and ADMIN_PASS configured (such as with the default docker-compose.env, where ADMIN_PASS and SECRET are empty), the /login endpoint refuses sign-in, but the authentication middleware still derived a predictable signing key and accepted forged JWTs on protected admin routes. This change makes both admin services fail closed until valid credentials are set and hardens token and credential checks.
Require non-empty, non-whitespace ADMIN_USER and ADMIN_PASS via getAdminAuth() and getAuthSecret() in server/admin and server/admin-next, returning 401 on /login and all protected routes when credentials are unset.
Harden the auth() middleware to require a case-insensitive Bearer header prefix, restrict jwt.verify to HS256, and validate payload.username alongside payload.platform.
Replace plain string checks in /login with constant-time comparison (verifyAdminCredentials using SHA-256 + crypto.timingSafeEqual) and safely default missing req.body.
Log startup warnings in both server/admin and server/admin-next when admin credentials are missing or when SECRET is unset in production.
Add a test script to server/admin/package.json and expand middleware auth tests for both services.
Testing
Added server/admin/src/server/middleware/auth.test.ts (with a test script in server/admin/package.json) and expanded server/admin-next/src/server/middleware/auth.test.ts to cover forged JWTs under empty/default docker-compose.env values, unset or whitespace-only credentials, valid case-insensitive Bearer tokens with write-request auditing, invalid authorization headers, mismatched platform/username claims, unsigned (alg: none) tokens, and verifyAdminCredentials.
Summary by CodeRabbit
Security
Admin sign-in now requires configured, nonblank credentials. Requests with missing or invalid authorization, forged tokens, or tokens that don’t match the configured administrator are rejected.
Configuration
The server logs warnings at startup when admin credentials are unavailable, and in production when the secret is missing or blank. Startup continues despite these warnings.
No actionable comments were generated in the recent review.
Walkthrough
Both admin services now load credentials at runtime, reject authentication when credentials are unset, and validate the configured username in admin tokens. Login routes use the configured username. Startup checks, authentication tests, and a test command were added or updated.
Changes: Admin authentication
Layer / File(s)
Summary
Credential configuration and login server/admin/src/server/middleware/auth.ts, server/admin-next/src/server/middleware/auth.ts, server/admin/src/server/router/api.ts, server/admin-next/src/server/router/api.ts
Both services load credentials and derive the signing secret through getters. Login checks credentials through a shared verifier and uses the configured username in successful tokens, responses, and audit records.
Request authentication and tests server/admin/src/server/middleware/auth.ts, server/admin-next/src/server/middleware/auth.ts, server/admin/src/server/middleware/auth.test.ts, server/admin-next/src/server/middleware/auth.test.ts, server/admin/package.json
Both middleware implementations reject requests when credentials are unavailable and validate the Bearer scheme, HS256 signature, platform, and username. Tests cover rejection cases, authenticated requests, and write auditing. The admin package adds a middleware test command.
sequenceDiagram
participant Client
participant AuthMiddleware
participant getAdminAuth
participant getAuthSecret
participant JWTVerifier
participant ProtectedAPI
Client->>AuthMiddleware: Send request with Bearer token
AuthMiddleware->>getAdminAuth: Load configured credentials
AuthMiddleware->>getAuthSecret: Derive signing secret
AuthMiddleware->>JWTVerifier: Verify token with HS256
JWTVerifier-->>AuthMiddleware: Return token claims
AuthMiddleware->>ProtectedAPI: Continue when platform and username match
Loading
Merge Risk: Minimal · up to 24164
This change makes the optional admin services reject login and protected requests when admin credentials are unset or blank. It also tightens JWT validation, which closes the forged-token bypass described in issue #320. No remaining merge-blocking risk was identified in the supplied changes.
Pre-merge checks: 4
Check name
Status
Explanation
Description Check
Check skipped - CodeRabbit’s high-level summary is enabled.
Linked Issues check
Issue #320 requires that protected admin routes reject JWTs signed with the public fallback key when admin credentials are unset. At the reviewed head, getAdminAuth() returns null when ADMIN_USER …
Out of Scope Changes check
All changes relate to #320. The auth() and credential-check changes in both admin services address the forged-JWT bypass directly. Startup warnings in server/admin/src/server/index.ts and `server/…
Title check
The title "fix(admin): #320 require credentials and harden JWT auth" matches the main change. The PR makes both admin and admin-next reject login and protected routes when ADMIN_USER or ADMIN_PASS is …
Full details: Linked Issues check
Explanation
Issue #320 requires that protected admin routes reject JWTs signed with the public fallback key when admin credentials are unset. At the reviewed head, getAdminAuth() returns null when ADMIN_USER or ADMIN_PASS is missing, empty, or whitespace-only. getAuthSecret() then returns null, and auth() in both server/admin/src/server/middleware/auth.ts and server/admin-next/src/server/middleware/auth.ts returns 401 before any JWT verification. This removes the forged-token path for the default docker-compose.env values (ADMIN_PASS empty). The login route uses the same helpers, so /login fails closed as well. Additional hardening in the same middleware (case-insensitive Bearer prefix, algorithms: ['HS256'], payload.username checked against the configured admin username, platform checked per service) and verifyAdminCredentials (SHA-256 plus crypto.timingSafeEqual) supports the same objective. The issue's residual case, where operators set non-public credentials and keep the public SECRET default, is documented as an operator obligation and is not a coding requirement of this issue. Automated tests were not executed in this review; the test coverage claim rests on the PR description and the change summary.
Full details: Out of Scope Changes check
Explanation
All changes relate to #320. The auth() and credential-check changes in both admin services address the forged-JWT bypass directly. Startup warnings in server/admin/src/server/index.ts and server/admin-next/src/server/index.ts report the missing-credential and unset-SECRET conditions that the issue describes. The test script in server/admin/package.json and the test files in both services verify the auth behavior and support the fix. The /login changes in api.ts use the same helpers and constant-time comparison. The username-claim check and the Bearer and HS256 restrictions are part of the token-forgery hardening. No unrelated functional change was identified in the reviewed summary or in the inspected auth.ts files.
Full details: Title check
Explanation
The title "fix(admin): #320 require credentials and harden JWT auth" matches the main change. The PR makes both admin and admin-next reject login and protected routes when ADMIN_USER or ADMIN_PASS is unset or blank. It also tightens JWT checks: a Bearer prefix, HS256 only, and platform and username claims. The title names the linked issue #320 and states the purpose, so a teammate scanning history can see the primary change. The title is slightly long and the PR objectives cite #325 as the PR number, but this does not make the title unrelated.
Finishing Touches
Generate unit tests (beta)
Commit to this branch
Create a new PR
Fix failing CI checks
Commit to this branch
Create a new PR
Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.
moonrailgun
changed the title
fix(admin): require credentials and harden JWT auth
fix(admin): #320 require credentials and harden JWT auth
Nov 25, 2026
moonrailgun
changed the title
fix(admin): #320 require credentials and harden JWT auth
fix(admin): #320 block forged JWTs when admin credentials are empty
Nov 25, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Background
When the optional
adminoradmin-nextservice runs without bothADMIN_USERandADMIN_PASSconfigured (such as with the defaultdocker-compose.env, whereADMIN_PASSandSECRETare empty), the/loginendpoint refuses sign-in, but the authentication middleware still derived a predictable signing key and accepted forged JWTs on protected admin routes. This change makes both admin services fail closed until valid credentials are set and hardens token and credential checks.Fixes #320
Changes
ADMIN_USERandADMIN_PASSviagetAdminAuth()andgetAuthSecret()inserver/adminandserver/admin-next, returning401on/loginand all protected routes when credentials are unset.auth()middleware to require a case-insensitiveBearerheader prefix, restrictjwt.verifytoHS256, and validatepayload.usernamealongsidepayload.platform./loginwith constant-time comparison (verifyAdminCredentialsusing SHA-256 +crypto.timingSafeEqual) and safely default missingreq.body.server/adminandserver/admin-nextwhen admin credentials are missing or whenSECRETis unset in production.testscript toserver/admin/package.jsonand expand middleware auth tests for both services.Testing
server/admin/src/server/middleware/auth.test.ts(with atestscript inserver/admin/package.json) and expandedserver/admin-next/src/server/middleware/auth.test.tsto cover forged JWTs under empty/defaultdocker-compose.envvalues, unset or whitespace-only credentials, valid case-insensitiveBearertokens with write-request auditing, invalid authorization headers, mismatchedplatform/usernameclaims, unsigned (alg: none) tokens, andverifyAdminCredentials.Summary by CodeRabbit