Skip to content

Commit 5d944cf

Browse files
zzacharoGlignos
authored andcommitted
sessions: reset csrf token listener
1 parent c79fd75 commit 5d944cf

3 files changed

Lines changed: 14 additions & 2 deletions

File tree

invenio_accounts/ext.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
from .datastore import SessionAwareSQLAlchemyUserDatastore
3232
from .hash import InvenioAesEncryptedEmail, _to_binary
3333
from .models import Role, User
34-
from .sessions import login_listener, logout_listener
34+
from .sessions import csrf_token_reset, login_listener, logout_listener
3535
from .utils import obj_or_import_string, set_session_info
3636

3737

@@ -244,7 +244,9 @@ def init_config(self, app):
244244
def _enable_session_activity(self, app):
245245
"""Enable session activity."""
246246
user_logged_in.connect(login_listener, app)
247+
user_logged_in.connect(csrf_token_reset, app)
247248
user_logged_out.connect(logout_listener, app)
249+
user_logged_out.connect(csrf_token_reset, app)
248250
from .views.settings import blueprint
249251
from .views.security import security, revoke_session
250252
blueprint.route('/security/', methods=['GET'])(security)

invenio_accounts/sessions.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,16 @@ def _commit(response=None):
107107
return response
108108

109109

110+
def csrf_token_reset(app, user):
111+
"""Connect to the user_logged_in signal to reset the csrf token.
112+
113+
:param app: The Flask application.
114+
:param user: The :class:`invenio_accounts.models.User` instance.
115+
"""
116+
from invenio_rest.csrf import reset_token
117+
reset_token()
118+
119+
110120
def delete_session(sid_s):
111121
"""Delete entries in the data- and kvsessionstore with the given sid_s.
112122

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@
7777
'invenio-base>=1.2.2',
7878
'invenio-i18n>=1.2.0',
7979
'invenio-celery>=1.1.2',
80-
'invenio-rest>=1.1.3',
80+
'invenio-rest>=1.2.1',
8181
'maxminddb-geolite2>=2017.404',
8282
'passlib>=1.7.1',
8383
'pyjwt>=1.5.0',

0 commit comments

Comments
 (0)