You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fix: make session blocking opt-in with strictSessionEnforcement
BREAKING: Session blocking is now DISABLED by default!
Changes:
- Add `strictSessionEnforcement` config option (default: false)
- Only block requests when:
1. strictSessionEnforcement is explicitly set to true AND
2. User has inactive sessions (was explicitly logged out)
- If no sessions exist at all → allow through (bug/race condition)
- Log warnings instead of blocking when strictMode is off
- Apply same logic to JWT verify, middleware, and policy
To enable strict blocking, add to config/plugins.js:
```
'magic-sessionmanager': {
config: {
strictSessionEnforcement: true,
},
},
```
// 1. If user has inactive sessions = they were explicitly logged out → BLOCK (if strict)
660
+
// 2. If user has NO sessions at all = session never created (bug/race condition) → ALLOW
661
+
// 3. If strictMode is off → always ALLOW but log warning
662
+
663
+
if(!strictMode){
664
+
// Non-strict mode: Log warning but allow through
665
+
if(totalSessions===0){
666
+
strapi.log.warn(
667
+
`[magic-sessionmanager] [JWT-WARN] No session found for user ${userDocId.substring(0,8)}... (allowing - session may not have been created)`
668
+
);
669
+
}elseif(hasInactiveSessions){
670
+
strapi.log.warn(
671
+
`[magic-sessionmanager] [JWT-WARN] User ${userDocId.substring(0,8)}... has ${totalSessions} inactive sessions but no active ones (allowing - strictMode off)`
672
+
);
673
+
}
674
+
returndecoded;// Allow through in non-strict mode
675
+
}
676
+
677
+
// Strict mode enabled - more careful about blocking
678
+
if(totalSessions===0){
679
+
// No sessions at all - likely a bug or race condition, allow through
680
+
strapi.log.warn(
681
+
`[magic-sessionmanager] [JWT-ALLOW] No sessions exist for user ${userDocId.substring(0,8)}... (allowing - possible race condition)`
682
+
);
683
+
returndecoded;
684
+
}
685
+
686
+
if(hasInactiveSessions){
687
+
// User has inactive sessions = explicitly logged out → BLOCK
649
688
strapi.log.info(
650
-
`[magic-sessionmanager] [JWT-BLOCKED] Valid JWT but no active session (user: ${userDocId.substring(0,8)}..., total sessions: ${allSessions?.length||0})`
689
+
`[magic-sessionmanager] [JWT-BLOCKED] User ${userDocId.substring(0,8)}... was logged out (${totalSessions} inactive sessions)`
651
690
);
652
-
returnnull;// This will cause auth to fail
691
+
returnnull;// Block - user was explicitly logged out
653
692
}
654
693
655
-
// Session exists - return decoded token
694
+
// Edge case: sessions exist but none are active or inactive (shouldn't happen)
695
+
strapi.log.warn(
696
+
`[magic-sessionmanager] [JWT-ALLOW] Unexpected session state for user ${userDocId.substring(0,8)}... (allowing)`
0 commit comments