fix(webui): logout via XHR wrong Basic creds (Chrome-safe)

fetch()+manual Authorization is ignored when browser has cached HTTP auth.
Use XMLHttpRequest.open(user,password) with random bogus pair, then
location.replace('/') so login prompts again. Add Cache-Control on 401.
Header buttons: type=button, @click.prevent on logout.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
Андрей Бобырев
2026-05-12 20:00:18 +03:00
parent 035534e4f2
commit b8757548a2
2 changed files with 36 additions and 17 deletions

View File

@@ -594,10 +594,18 @@ def api_change_password():
@app.route("/api/logout")
def api_logout():
"""Возвращаем 401 с новым realm — браузер сбрасывает кеш Basic Auth."""
"""401 + смена realm — подсказка браузеру забыть предыдущий Basic Auth.
Клиент должен дергать этот URL через XMLHttpRequest.open(..., user, password)
с заведомо неверной парой; иначе многие браузеры подставят сохранённые креды."""
return Response(
"logged out", 401,
{"WWW-Authenticate": f'Basic realm="kaskad-logout-{os.urandom(4).hex()}"'},
"logged out\n",
401,
{
"WWW-Authenticate": f'Basic realm="kaskad-logout-{os.urandom(4).hex()}"',
"Cache-Control": "no-store, no-cache, must-revalidate",
"Pragma": "no-cache",
},
)