@@ -807,6 +807,31 @@ module.exports = function(User) {
807807 UserModel . validatesUniquenessOf ( 'username' , { message : 'User already exists' } ) ;
808808 }
809809
810+ UserModel . once ( 'attached' , function ( ) {
811+ if ( UserModel . app . get ( 'logoutSessionsOnSensitiveChanges' ) !== undefined )
812+ return ;
813+
814+ g . warn ( [
815+ '' ,
816+ 'The user model %j is attached to an application that does not specify' ,
817+ 'whether other sessions should be invalidated when a password or' ,
818+ 'an email has changed. Session invalidation is important for security' ,
819+ 'reasons as it allows users to recover from various account breach' ,
820+ 'situations.' ,
821+ '' ,
822+ 'We recommend turning this feature on by setting' ,
823+ '"{{logoutSessionsOnSensitiveChanges}}" to {{true}} in' ,
824+ '{{server/config.json}} (unless you have implemented your own solution' ,
825+ 'for token invalidation).' ,
826+ '' ,
827+ 'We also recommend enabling "{{injectOptionsFromRemoteContext}}" in' ,
828+ '%s\'s settings (typically via common/models/*.json file).' ,
829+ 'This setting is required for the invalidation algorithm to keep ' ,
830+ 'the current session valid.' ,
831+ ''
832+ ] . join ( '\n' ) , UserModel . modelName , UserModel . modelName ) ;
833+ } ) ;
834+
810835 return UserModel ;
811836 } ;
812837
@@ -832,6 +857,8 @@ module.exports = function(User) {
832857
833858 // Delete old sessions once email is updated
834859 User . observe ( 'before save' , function beforeEmailUpdate ( ctx , next ) {
860+ if ( ! ctx . Model . app . get ( 'logoutSessionsOnSensitiveChanges' ) ) return next ( ) ;
861+
835862 var emailChanged ;
836863 if ( ctx . isNewInstance ) return next ( ) ;
837864 if ( ! ctx . where && ! ctx . instance ) return next ( ) ;
@@ -872,6 +899,8 @@ module.exports = function(User) {
872899 } ) ;
873900
874901 User . observe ( 'after save' , function afterEmailUpdate ( ctx , next ) {
902+ if ( ! ctx . Model . app . get ( 'logoutSessionsOnSensitiveChanges' ) ) return next ( ) ;
903+
875904 if ( ! ctx . instance && ! ctx . data ) return next ( ) ;
876905 if ( ! ctx . hookState . originalUserData ) return next ( ) ;
877906
0 commit comments