Dosu LogoDosu Logo
Ask
Join our Discord
StrapiPublic
Strapi
DocumentsStrapi
Auth Error Classification
Auth Error Classification
Type
Topic
Status
Published
Created
Sep 23, 2026
Updated
Sep 23, 2026
Created by
Dosu Bot
Updated by
Dosu Bot

Auth Error Classification#

Auth error classification describes how Strapi translates thrown auth-related errors (UnauthorizedError, ForbiddenError, PolicyError, etc.) into HTTP responses. When this pipeline works correctly, intentional 401/403 errors surface to API clients; when it breaks — most commonly due to cross-package instanceof failures — those errors silently become 500 Internal Server Errors.


Error Class Hierarchy#

All auth error types live in @strapi/utils → errors.ts. The relevant portion of the class tree:

ApplicationError
├── ForbiddenError → HTTP 403
│ └── PolicyError → HTTP 403
└── UnauthorizedError → HTTP 401
  • ForbiddenError: thrown when a user is authenticated but lacks permission. Default message: "Forbidden access".
  • UnauthorizedError: thrown when the user is not authenticated. Default message: "Unauthorized".
  • PolicyError: extends ForbiddenError; used in route policies, exposes a custom message through the public API (unlike plain ForbiddenError).

Request Pipeline#

Every request passes through a fixed middleware stack composed in compose-endpoint.ts:

authenticate → authorize → policies → plugin middlewares → controller

Authenticate (createAuthenticateMiddleware) delegates to the active auth strategy's authenticate().

Authorize (createAuthorizeMiddleware) wraps authService.verify() and converts errors to Koa responses:

  • UnauthorizedError → ctx.unauthorized() (HTTP 401)
  • ForbiddenError → ctx.forbidden() (HTTP 403), unless it is a PolicyError, which is re-thrown so its message is visible to the caller
  • Any other error → re-thrown upstream

Global error middleware (errors.ts middleware) is the last catch-all:

  • ApplicationError → formatApplicationError(), which maps the class to the correct HTTP status.
  • HttpError → formatHttpError().
  • Anything else → formatInternalError(), i.e., HTTP 500.

The status mapping table in services/errors.ts drives formatApplicationError:

Error classHTTP status
UnauthorizedError401
ForbiddenError403
NotFoundError404
PayloadTooLargeError413
RateLimitError429
NotImplementedError501
(anything else ApplicationError)400

users-permissions Strategy#

The users-permissions auth strategy implements both halves:

  • authenticate(): resolves the JWT, fetches the user, builds a CASL ability from role permissions. Returns { authenticated: false } or { error: 'Invalid credentials' } for invalid/blocked/unconfirmed users — it does not throw. Any unexpected error is swallowed and returns { authenticated: false } .
  • verify(): throws UnauthorizedError when no ability exists or the route has no scope and the user is anonymous ; throws ForbiddenError when the user's ability doesn't cover the required scope .

The Cross-Package instanceof Problem#

Root cause: Node.js module resolution may give each package (e.g., a plugin bundled separately) its own copy of @strapi/utils. Errors thrown by a plugin's copy of ApplicationError fail instanceof errors.ApplicationError in core's error middleware — core sees them as unrecognized errors and returns HTTP 500.

This is tracked in GitHub issue #22488 and fixed in PR #27178.

Fix (PR #27178): Two mechanisms were introduced :

  1. Symbol branding — ApplicationError instances are stamped with Symbol.for('strapi.ApplicationError') at construction time.
  2. Prototype-walking fallback — isApplicationError(error) checks for the brand first, then walks the prototype chain looking for an ApplicationError ancestor with a details property (handles errors from older, unbranded plugin copies).
  3. isErrorOfType(error, errorType) — generalizes prototype inspection for subclass status mapping, ensuring PolicyError/ForbiddenError from a foreign module copy still resolve to HTTP 403 rather than 400.

The error middleware's instanceof errors.ApplicationError check was replaced by errors.isApplicationError(error) .


Key Source Files#

FileRole
packages/core/utils/src/errors.tsError class definitions and (post-fix) isApplicationError / isErrorOfType helpers
packages/core/core/src/middlewares/errors.tsGlobal Koa error middleware — top-level catch handler
packages/core/core/src/services/errors.tsformatApplicationError, status mapping table
packages/core/core/src/services/server/compose-endpoint.tsRoute pipeline — authorize middleware
packages/plugins/users-permissions/server/src/strategies/users-permissions.jsAuth strategy: authenticate() + verify()
Documents
Content Manager List Configuration
content-manager
Content Releases
releases
Document ID Migration
document-service
introduction-and-faq
rest
step-by-step
Draft & Publish Relation Synchronization
do-not-update-repeatable-components-with-document-service-api
lifecycle-hooks-document-service
publishedat-always-set-when-dandp-disabled
status
status
DynamicZone Stability
components-and-dynamic-zones-do-not-return-id
components-dynamic-zones
no-shared-population-strategy-components-dynamic-zones
i18n Locale-Scoped Operations
crud
database-columns
document
document-service
i18n-content-manager-locale
internationalization
locale
locale
locale
no-locale-all
Strapi Data Transfer
deployment
Strapi Project Scaffolding
cli
create-a-plugin
deployment
How can I create my first Strapi project on a brand new MacBook with no prior coding experience, including all necessary terminal commands and setup steps?
quick-start
templates
Strapi v5 Plugin API
admin-panel-rbac-store-updated
breaking-changes
get-where-removed
helper-plugin
helper-plugin-deprecated
inject-content-manager-component
introduction
model-config-path-uses-uid
pass-data-from-server-to-admin
plugins-migration
rbac
redux-content-manager-app-state
remove-webhook-populate-relations
strapi-imports
Vite Build Configuration
vite
webpack-aliases-removed
Content Manager Mobile and Tablet UI Improvements
FilesManager API Reference
Focal Point Picker in Strapi Media Library
Nested Route File Structure for Strapi Plugins
Plugin-Specific Handling in the Strapi JavaScript Client
Strapi SDK Initialization and Architecture Guide
access-cast-environment-variables
access-configuration-values
adding-support-to-existing-project
admin-panel
admin-panel
admin-panel-api
admin-panel-customization
admin-permissions-for-plugins
advanced-policies
advanced-queries
amazon-s3
api
api-tokens
attributes-and-content-types-names-reserved
audit-logs
auth-zero
authentication
aws-cognito
backend-customization
bulk-operations
bundlers
cas
cli
client
cloudinary
community
configurations
configure-sso
content-api
content-history
content-manager-apis
content-type-builder
controllers
core-service-methods-use-document-service
create-components-for-plugins
cron
custom-fields
customization
data-management
database
database-identifiers-shortened
database-migrations
database-transactions
default-index-removed
default-input-validation
design-system
developing-plugins
development
discord
discord
docker
documentation
documents-and-entries
draft-and-publish
edit-view-layout-and-list-view-layout-rewritten
email
email-custom-providers
email-nodemailer
entity-service
entity-service-deprecated
environment
error-handling
examples
extension
facebook
faq
favicon
features
fetch
fields
filter
filtering
filters
filters
from-entity-service-to-document-service
functions
github
github
google
google
graphql
graphql
graphql-api-updated
guides
homepage
host-port-path
instagram
installation
installing-plugins-via-marketplace
interactive-query-builder
intro
intro
is-supported-image-removed
keycloak
keycloak
koa-body-v6
license-only
linkedin
local-upload
locales-translations
logos
mailgun-provider-variables
media-library
media-library-providers
microsoft
middlewares
middlewares
middlewares
middlewares
models
mysql5-unsupported
new-provider-guide
new-response-format
no-find-page-in-document-service
no-upload-at-entry-creation
okta
only-better-sqlite3-for-sqlite
only-mysql2-package-for-mysql
openapi
order-pagination
order-pagination
parameters
patreon
plugin-sdk
plugin-structure
plugins
plugins-extension
policies
policies
populate
populate
populate-creator-fields
populate-select
populating
preview
project-structure
publication-state-removed
query-engine
rbac
react-router-dom-6
reddit
register-allowed-fields
relations
removed-support-for-some-env-options
requests-responses
review-workflows
routes
routes
sentry
server
server-api
server-default-log-level
server-proxy
services
services-and-controllers
setting-up-admin-panel
setup-deployment
single-operations
sort-by-id
sort-pagination
sort-pagination
sso
store-and-access-data
strapi-container
strapi-utils-refactored
strict-requirements-config-files
templates
testing
theme-extension
twitch
twitter
typescript
typescript
understanding-populate
upgrade-to-apollov4
upgrade-tool
upgrades
upload
usage-information
use-document-id
users-and-permissions-providers
users-permissions
vk
webhooks
wysiwyg-editor
yarn-not-default