Regenerate session-ids to prevent session fixation

master
Florent Daigniere 4 years ago
parent d459c37432
commit a1d32568d6

@ -17,6 +17,7 @@ def login():
if form.validate_on_submit(): if form.validate_on_submit():
user = models.User.login(form.email.data, form.pw.data) user = models.User.login(form.email.data, form.pw.data)
if user: if user:
flask.session.regenerate()
flask_login.login_user(user) flask_login.login_user(user)
endpoint = flask.request.args.get('next', '.index') endpoint = flask.request.args.get('next', '.index')
return flask.redirect(flask.url_for(endpoint) return flask.redirect(flask.url_for(endpoint)
@ -30,6 +31,7 @@ def login():
@access.authenticated @access.authenticated
def logout(): def logout():
flask_login.logout_user() flask_login.logout_user()
flask.session.destroy()
return flask.redirect(flask.url_for('.index')) return flask.redirect(flask.url_for('.index'))

@ -119,6 +119,7 @@ def user_password(user_email):
if form.pw.data != form.pw2.data: if form.pw.data != form.pw2.data:
flask.flash('Passwords do not match', 'error') flask.flash('Passwords do not match', 'error')
else: else:
flask.session.regenerate()
user.set_password(form.pw.data) user.set_password(form.pw.data)
models.db.session.commit() models.db.session.commit()
flask.flash('Password updated for %s' % user) flask.flash('Password updated for %s' % user)
@ -186,6 +187,7 @@ def user_signup(domain_name=None):
if domain.has_email(form.localpart.data): if domain.has_email(form.localpart.data):
flask.flash('Email is already used', 'error') flask.flash('Email is already used', 'error')
else: else:
flask.session.regenerate()
user = models.User(domain=domain) user = models.User(domain=domain)
form.populate_obj(user) form.populate_obj(user)
user.set_password(form.pw.data) user.set_password(form.pw.data)

Loading…
Cancel
Save