Skip to content

fix(auth0-express-api): forward missing-ApiClient error via next() - #44

Merged
frederikprijck merged 2 commits into
mainfrom
fix/sdk-9-require-auth-next-err
Sep 15, 2026
Merged

frederikprijck merged 2 commits into
mainfrom
fix/sdk-9-require-auth-next-err

Conversation

@frederikprijck

@frederikprijck frederikprijck commented Aug 25, 2026

Copy link
Copy Markdown
Member

Summary

requiresAuth threw synchronously when req.auth0.client was absent (router not registered). In an async Express 4 middleware that surfaces as an unhandled promise rejection instead of reaching the app's error middleware. On Express 5 thrown errors in async middleware are caught, but Express 4 does not do this — so behaviour differed by version.

This returns next(err) instead, so the missing-ApiClient case reaches the app's error middleware consistently on both Express 4 and 5, with no response written by the middleware itself.

Changes

  • require-auth.ts: throw new Error(...)return next(new Error(...))
  • require-auth.spec.ts: the existing "should throw" test now asserts the next(err) contract and that no response is written.

requiresAuth threw synchronously when req.auth0.client was absent. In an
async Express 4 middleware that surfaces as an unhandled promise rejection
rather than reaching the app's error middleware. Return next(err) instead
so the error is handled the same way on Express 4 and 5.

SECURITY: SDK-9 — fail-safe hardening (CWE-248).
@frederikprijck
frederikprijck merged commit cc2de87 into main Sep 15, 2026
7 checks passed
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.

2 participants