fix: _sidebar_data verifies workspace ownership before loading pages
- Stale numeric workspace cookie from another user now rejected - workspace_pages only loaded if owner_id matches current user - Prevents sidebar tree leak of other users' content
This commit is contained in:
@@ -82,13 +82,19 @@ def _sidebar_data(request: Request, repos: list[dict]) -> dict:
|
|||||||
active_ws_name = f"{gitea_owner}/{gitea_repo}"
|
active_ws_name = f"{gitea_owner}/{gitea_repo}"
|
||||||
gitea_workspace = True
|
gitea_workspace = True
|
||||||
workspace_pages = [] # loaded client-side
|
workspace_pages = [] # loaded client-side
|
||||||
elif ws_cookie:
|
elif ws_cookie and user:
|
||||||
workspace_pages = _load_workspace_pages(ws_cookie)
|
|
||||||
try:
|
try:
|
||||||
|
wsi = int(ws_cookie)
|
||||||
with get_conn() as conn:
|
with get_conn() as conn:
|
||||||
ws_row = conn.execute("SELECT name FROM workspaces WHERE id=?", (int(ws_cookie),)).fetchone()
|
# Verify this workspace belongs to the current user
|
||||||
if ws_row:
|
row = conn.execute(
|
||||||
active_ws_name = ws_row["name"]
|
"SELECT id, name, owner_id FROM workspaces WHERE id=? AND owner_id=?",
|
||||||
|
(wsi, user["id"])
|
||||||
|
).fetchone()
|
||||||
|
if row:
|
||||||
|
active_ws_name = row["name"]
|
||||||
|
workspace_pages = _load_workspace_pages(ws_cookie)
|
||||||
|
# else: stale cookie from another user — ignore
|
||||||
except (ValueError, Exception):
|
except (ValueError, Exception):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user