Skip to content

Commit

Permalink
sessions: reset csrf token listener
Browse files Browse the repository at this point in the history
  • Loading branch information
zzacharo authored and Glignos committed May 8, 2020
1 parent c79fd75 commit 5d944cf
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
4 changes: 3 additions & 1 deletion invenio_accounts/ext.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
from .datastore import SessionAwareSQLAlchemyUserDatastore
from .hash import InvenioAesEncryptedEmail, _to_binary
from .models import Role, User
from .sessions import login_listener, logout_listener
from .sessions import csrf_token_reset, login_listener, logout_listener
from .utils import obj_or_import_string, set_session_info


Expand Down Expand Up @@ -244,7 +244,9 @@ def init_config(self, app):
def _enable_session_activity(self, app):
"""Enable session activity."""
user_logged_in.connect(login_listener, app)
user_logged_in.connect(csrf_token_reset, app)
user_logged_out.connect(logout_listener, app)
user_logged_out.connect(csrf_token_reset, app)
from .views.settings import blueprint
from .views.security import security, revoke_session
blueprint.route('/security/', methods=['GET'])(security)
Expand Down
10 changes: 10 additions & 0 deletions invenio_accounts/sessions.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,16 @@ def _commit(response=None):
return response


def csrf_token_reset(app, user):
"""Connect to the user_logged_in signal to reset the csrf token.
:param app: The Flask application.
:param user: The :class:`invenio_accounts.models.User` instance.
"""
from invenio_rest.csrf import reset_token
reset_token()


def delete_session(sid_s):
"""Delete entries in the data- and kvsessionstore with the given sid_s.
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
'invenio-base>=1.2.2',
'invenio-i18n>=1.2.0',
'invenio-celery>=1.1.2',
'invenio-rest>=1.1.3',
'invenio-rest>=1.2.1',
'maxminddb-geolite2>=2017.404',
'passlib>=1.7.1',
'pyjwt>=1.5.0',
Expand Down

0 comments on commit 5d944cf

Please sign in to comment.