Skip to content

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

Open
frederikprijck wants to merge 1 commit into
mainfrom
fix/sdk-9-require-auth-next-err
Open

fix(auth0-express-api): forward missing-ApiClient error via next()#44
frederikprijck wants to merge 1 commit into
mainfrom
fix/sdk-9-require-auth-next-err

Conversation

@frederikprijck

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.

Context

Split out of #27 (fix/sdk-9-fail-safe-nits). This half is independent of the SDK-4 backchannel work, so it targets main directly; #27 now carries only the backchannel-logout fail-safe fix.

SECURITY: SDK-9 — fail-safe hardening (CWE-248).

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).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

1 participant