mirror of
https://github.com/retspen/webvirtcloud
synced 2026-12-02 08:56:07 +00:00
fix(console): a session that a password change ended opens no console
session_user_id read the user id out of the session row as it was, so a session cookie that Django no longer accepts (the user's password changed, or the user was deactivated) still matched a console token of its user in novncd and socketiod. It now asks django.contrib.auth.get_user, which checks the session's password hash and that the user may sign in. The serial console tests built sessions by hand with only the user id; they now sign in with force_login, as the panel does. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Kk4h2TcUiaWmU5MUszYSea
This commit is contained in:
parent
fe553a2d65
commit
8eb619114c
3 changed files with 25 additions and 10 deletions
|
|
@ -6,11 +6,11 @@ also wants the session cookie of the token's user (session_user_id).
|
|||
socketiod's token travels in the Socket.IO handshake, not the URL."""
|
||||
|
||||
from importlib import import_module
|
||||
from types import SimpleNamespace
|
||||
|
||||
from django import db
|
||||
from django.conf import settings
|
||||
from django.contrib.auth import SESSION_KEY
|
||||
from django.contrib.auth import get_user_model
|
||||
from django.contrib.auth import get_user, get_user_model
|
||||
from django.core.signing import BadSignature, SignatureExpired, TimestampSigner
|
||||
from django.http import parse_cookie
|
||||
|
||||
|
|
@ -55,8 +55,10 @@ def may_still_open(user_id, instance):
|
|||
|
||||
def session_user_id(cookie_header):
|
||||
"""The id (a string) of the user signed in with the session cookie of a
|
||||
request's Cookie header, or None."""
|
||||
request's Cookie header, or None. Django's own check: a session that a
|
||||
password change or a deactivation ended is no one's."""
|
||||
session_key = parse_cookie(cookie_header or "").get(settings.SESSION_COOKIE_NAME)
|
||||
if not session_key:
|
||||
return None
|
||||
return import_module(settings.SESSION_ENGINE).SessionStore(session_key).get(SESSION_KEY)
|
||||
user = get_user(SimpleNamespace(session=import_module(settings.SESSION_ENGINE).SessionStore(session_key)))
|
||||
return str(user.pk) if user.is_authenticated else None
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue