#2772·emdash

Database schema failures during authentication can be misreported as HTTP 401

Author: yumam0815Created Aug 28, 2026Updated Sep 28, 2026

Problem

External authentication currently wraps identity verification, user lookup/provisioning, and related database operations in one catch block. Any thrown error is returned as HTTP 401 Authentication failed.

With an authenticated external-auth request and an incompatible database schema, a database query failure can therefore be reported as 401 even though the credentials were valid. The page does fail closed, but the HTTP classification is misleading: clients may retry or refresh credentials, and monitoring records a database/runtime incident as an authentication failure.

This was observed with EmDash 0.35.0 using the Cloudflare Access auth adapter. No schema, SQL, identity, or database identifiers are included here.

Expected contract

  • Missing or invalid identity: 401
  • Authenticated identity without permission: 403
  • Database schema mismatch, unavailable database, or runtime initialization failure during authenticated user lookup/provisioning: generic 503

For the 503 response:

  • Cache-Control: no-store
  • a short generic body
  • optionally Retry-After: 60
  • no SQL, table/column names, migration names, database identifiers, or stack traces

Implementation constraint

Please classify a known database/runtime error type (or separate the authentication and database stages) rather than mapping every Error or every 401 to 503. Credential failures must remain 401.

Suggested tests

  • invalid external identity remains 401
  • authenticated but unauthorized remains 403
  • authenticated request plus schema/query failure returns 503
  • the 503 is no-store and generic
  • schema/SQL details do not appear in the response