Drop watch websockets on session loss, purge SSO cache on logout
- Successful SSO /auth/api/validate responses are cached per credential and perm/renew URL for 10s, so watch websocket re-checks do not hammer the auth backend. A POST to the logout endpoint purges all cached entries for the request's credentials immediately, so logout/login flows are not served stale successes. - The watch websocket now re-validates auth before each forwarded message and every 10s when idle (SSO and built-in sessions alike). When the session is gone the client gets an auth error message and the socket is closed, instead of streaming updates forever. - Token-authenticated (API/share token) sockets are exempt from re-validation; they are checked once at handshake.
This commit is contained in:
@@ -102,6 +102,19 @@ async def forward_sso_cookies(req, res):
|
||||
res.headers.add("set-cookie", cookie)
|
||||
|
||||
|
||||
@app.on_response
|
||||
async def invalidate_sso_cache_on_logout(req, _res):
|
||||
"""Purge cached SSO validations after a logout request."""
|
||||
# Convenience for logout/login flows, not a security feature: cached
|
||||
# entries expire after 10 seconds anyway if the logout happened elsewhere.
|
||||
if (
|
||||
sso.paskia_enabled()
|
||||
and req.method == "POST"
|
||||
and req.path in {"/auth/api/logout", "/auth/logout"}
|
||||
):
|
||||
sso.invalidate_validation_cache(req)
|
||||
|
||||
|
||||
@app.on_response
|
||||
async def persist_auth_session(req, res):
|
||||
"""Persist a session cookie after successful Authorization-based auth."""
|
||||
|
||||
Reference in New Issue
Block a user