Skip to content

Commit 1264877

Browse files
authored
Backport changes from Pro: Re-issue session cookie when switching between HTTP<>HTTPS (#1948)
This PR backports the changes from https://github.com/tiny-pilot/tinypilot-pro/pull/1857, Re-issue session cookie when switching between HTTP<>HTTPS – see https://github.com/tiny-pilot/tinypilot-pro/issues/1848 for details. <a data-ca-tag href="https://codeapprove.com/pr/tiny-pilot/tinypilot/1948"><img src="https://codeapprove.com/external/github-tag-allbg.png" alt="Review on CodeApprove" /></a>
1 parent f412a8c commit 1264877

1 file changed

Lines changed: 10 additions & 0 deletions

File tree

app/api.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -693,6 +693,16 @@ def settings_requires_https_put():
693693
flask.current_app.config.update(
694694
SESSION_COOKIE_SECURE=is_session_cookie_secure)
695695

696+
# Force the session cookie to be re-issued with the updated Secure flag.
697+
# This is important when HTTPS is being disabled: the browser will reject
698+
# a non-Secure Set-Cookie sent from an HTTP origin if a Secure cookie with
699+
# the same name already exists. By re-issuing the cookie, while the request
700+
# is still over HTTPS, the browser accepts the new non-Secure cookie and
701+
# replaces the old Secure one. Without this, every subsequent HTTP request
702+
# would arrive with no session cookie, causing CSRF validation to fail with
703+
# "CSRF session token is missing".
704+
flask.session.modified = True
705+
696706
return json_response.success()
697707

698708

0 commit comments

Comments
 (0)