fix(session): split safe_key and _storage_key to fix WebUI coupling (#4533)
This commit is contained in:
1 parent
cf2f589615
commit
00a907c493
4 files changed
+63
-15
No files matched your search
@@ -231,8 +231,22 @@ def _indexed_row_for_session(session: Session, path: Path) -> dict[str, Any]:
|
||||
}
|
||||
|
||||
|
||||
def _try_decode_storage_stem(stem: str) -> str | None:
|
||||
"""Try to decode a base64url (no-padding) session storage stem back to the original key."""
|
||||
import base64
|
||||
|
||||
try:
|
||||
padding = 4 - len(stem) % 4
|
||||
if padding != 4:
|
||||
stem += "=" * padding
|
||||
return base64.urlsafe_b64decode(stem).decode("utf-8")
|
||||
except Exception:
|
||||
return None
|
||||
|
||||
|
||||
def _scan_session_row(session_manager: SessionManager, path: Path) -> dict[str, Any] | None:
|
||||
fallback_key = path.stem.replace("_", ":", 1)
|
||||
storage_key = _try_decode_storage_stem(path.stem)
|
||||
fallback_key = storage_key or path.stem.replace("_", ":", 1)
|
||||
try:
|
||||
with open(path, encoding="utf-8") as f:
|
||||
first_line = f.readline().strip()
|
||||
|
||||
Reference in new issue
Block a user