fix(service): make bearer auth stateless and remove unneeded sessions - #468
Draft
newmanw wants to merge 1 commit into
Draft
fix(service): make bearer auth stateless and remove unneeded sessions#468newmanw wants to merge 1 commit into
newmanw wants to merge 1 commit into
Conversation
MAGE's authenticated API/token traffic was accidentally relying on
express-session everywhere: passport.authenticate('bearer') defaults
to session:true unless told otherwise, so every bearer-authenticated
request across ~80 call sites was silently establishing/regenerating
a session cookie. Combined with global session middleware and
in-memory MemoryStore, concurrent requests could race each other's
session state, intermittently leaving req.user unpopulated on
requests that otherwise carried a valid token (observed as
intermittent 400s loading /ui_plugins/* assets).
- Scope express-session to only the OAuth2 SSO signin/callback routes
(oauth.js), the one flow that legitimately needs it (passport-oauth2's
CSRF state store and our origin stash both require req.session).
Remove the global session()/passport.session() middleware.
- Remove SAML's and the deprecated /api/devices local-auth route's
req.login() calls, which established sessions no code depended on.
- Add { session: false } to every passport.authenticate('bearer') call,
and centralize it as a single security.authentication.bearerAuthentication
middleware (added to AuthenticationInitializer's returned auth layer)
instead of each route file constructing its own.
- Simplify /ui_plugins auth: drop the custom access-token-to-header
copy and req.user pre-check, since passport-http-bearer already reads
access_token from the query string natively; the old code was
manufacturing a token-in-two-places state that passport-http-bearer's
own CSRF guard then rejected with 400.
newmanw
marked this pull request as draft
July 31, 2026 22:06
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
MAGE's authenticated API/token traffic was accidentally relying on express-session everywhere: passport.authenticate('bearer') defaults to session:true unless told otherwise, so every bearer-authenticated request across ~80 call sites was silently establishing/regenerating a session cookie. Combined with global session middleware and in-memory MemoryStore, concurrent requests could race each other's session state, intermittently leaving req.user unpopulated on requests that otherwise carried a valid token (observed as intermittent 400s loading /ui_plugins/* assets).