Skip to content

fix(admin): #320 block forged JWTs when admin credentials are empty - #325

Merged
moonrailgun merged 1 commit into
masterfrom
moonrailgun/security-empty-admin-credentials-still-allow-for
Nov 25, 2026
Merged

moonrailgun merged 1 commit into
masterfrom
moonrailgun/security-empty-admin-credentials-still-allow-for

Conversation

@moonrailgun

@moonrailgun moonrailgun commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

Background

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.

Fixes #320

Changes

  • 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.

@netlify

netlify Bot commented Nov 25, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for tailchat-nightly ready!

Name Link
🔨 Latest commit 24164d9
🔍 Latest deploy log https://app.netlify.com/projects/tailchat-nightly/deploys/6b06fe158b7b2b405126260a
😎 Deploy Preview https://deploy-preview-325--tailchat-nightly.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@coderabbitai

coderabbitai Bot commented Nov 25, 2026 •

Copy link
Copy Markdown

Explain Change →

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.
Startup configuration warnings
server/admin/src/server/index.ts, server/admin-next/src/server/index.ts
Both services warn when admin credentials are unavailable. In production, they also warn when SECRET is missing or blank.

Estimated code review effort: 4 (Complex) | ~45 minutes

Change: Bug fix · Severity of issue fixed: High

Sequence Diagram(s)

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: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Linked Issues check Passed 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 Passed 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 Passed 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.

Share

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: eacfbde1-eb2b-4df0-a341-9994a3a39f41
Commits

Reviewing files that changed from the base of the PR and between dee3553 and 24164d9.

Files selected for processing: 9

  • server/admin-next/src/server/index.ts
  • server/admin-next/src/server/middleware/auth.test.ts
  • server/admin-next/src/server/middleware/auth.ts
  • server/admin-next/src/server/router/api.ts
  • server/admin/package.json
  • server/admin/src/server/index.ts
  • server/admin/src/server/middleware/auth.test.ts
  • server/admin/src/server/middleware/auth.ts
  • server/admin/src/server/router/api.ts

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 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
moonrailgun merged commit f7c188b into master Nov 25, 2026
5 of 8 checks passed
@moonrailgun 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Security] Empty Admin Credentials Still Allow Forged Admin JWTs

1 participant