Skip to content

armgit / avibe

Public Imported from GitHub
0

Make your computer a home for your AI partner. Avibe is the local-first Agent OS: Vibey, its built-in AI partner, works out of the box, and Claude Code, Codex & OpenCode run unchanged beside it — reach them from your browser, phone, or any chat app.

fix(show): reject stale guest navigation (#1536)

Call Whitefad820d0410d
diff --git a/tests/test_ui_show_pages.py b/tests/test_ui_show_pages.py
index c1de9c11b..b96c15976 100644
--- a/tests/test_ui_show_pages.py
+++ b/tests/test_ui_show_pages.py
@@ -975,7 +975,57 @@ def test_public_show_ignores_an_existing_limited_guest_lease(monkeypatch, tmp_pa
assert "Cookie" not in response.headers.get("Vary", "")
-def test_limited_guest_lease_survives_rotation_only_for_that_browser(
+def test_rotated_public_share_rejects_an_old_guest_lease(monkeypatch, tmp_path):
+ monkeypatch.setenv("AVIBE_HOME", str(tmp_path))
+ config = _save_config(tmp_path)
+ old_share_id = _create_show_page("ses123", "limited")
+ lease = show_identity.make_show_guest_lease(
+ config,
+ page_id="ses123",
+ share_id=old_share_id,
+ normalized_email="[email protected]",
+ )
+ client = app.test_client()
+ client.set_cookie(
+ show_identity.show_guest_cookie_name(old_share_id),
+ lease,
+ domain="alex.avibe.bot",
+ path=show_identity.show_guest_cookie_path(old_share_id),
+ )
+
+ store = ShowPageStore()
+ try:
+ access = store.get_access("ses123")
+ assert access is not None
+ result = store.apply_access(
+ "ses123",
+ expected_revision=access.revision,
+ target_access_mode="public",
+ target_share_id="rotated-public-share",
+ target_emails=[],
+ )
+ assert result.status == "applied"
+ finally:
+ store.close()
+
+ old_response = client.get(
+ f"/p/{old_share_id}/",
+ base_url="https://alex.avibe.bot",
+ environ_base=_remote_peer(),
+ )
+ new_response = app.test_client().get(
+ "/p/rotated-public-share/",
+ base_url="https://alex.avibe.bot",
+ environ_base=_remote_peer(),
+ )
+
+ assert old_response.status_code == 404
+ assert old_response.headers["Cache-Control"] == "private, no-store"
+ assert "Cookie" in old_response.headers["Vary"]
+ assert new_response.status_code == 200
+
+
+def test_limited_guest_lease_is_rejected_after_rotation(
monkeypatch,
tmp_path,
):
@@ -1016,7 +1066,19 @@ def test_limited_guest_lease_survives_rotation_only_for_that_browser(
base_url="https://alex.avibe.bot",
environ_base=_remote_peer(),
)
- assert continuing.status_code == 200
+ rotated_navigation = admitted.get(
+ f"/p/{old_share_id}/",
+ base_url="https://alex.avibe.bot",
+ environ_base=_remote_peer(),
+ headers={
+ "Accept": "text/html",
+ "Sec-Fetch-Mode": "navigate",
+ "Sec-Fetch-Dest": "document",
+ },
+ follow_redirects=False,
+ )
+ assert rotated_navigation.status_code == 404
+ assert continuing.status_code == 404
fresh_old_link = app.test_client().get(
f"/p/{old_share_id}/",
base_url="https://alex.avibe.bot",
@@ -1026,7 +1088,7 @@ def test_limited_guest_lease_survives_rotation_only_for_that_browser(
assert fresh_old_link.status_code == 404
-def test_limited_show_guest_is_admitted_once_and_not_live_revoked(
+def test_limited_show_guest_is_rechecked_after_access_changes(
monkeypatch,
tmp_path,
):
@@ -1175,7 +1237,25 @@ def test_limited_show_guest_is_admitted_once_and_not_live_revoked(
base_url="https://alex.avibe.bot",
environ_base=_remote_peer(),
)
- assert existing_asset.status_code == 200
+ assert existing_asset.status_code == 404
+ assert existing_asset.headers["Cache-Control"] == "private, no-store"
+ assert "Cookie" in existing_asset.headers["Vary"]
+ html_subresource = client.get(
+ f"/p/{share_id}/index.html",
+ base_url="https://alex.avibe.bot",
+ environ_base=_remote_peer(),
+ headers={"Accept": "text/html"},
+ )
+ assert html_subresource.status_code == 404
+
+ stale_limited_navigation = client.get(
+ f"/p/{share_id}/",
+ base_url="https://alex.avibe.bot",
+ environ_base=_remote_peer(),
+ headers={"Accept": "text/html"},
+ follow_redirects=False,
+ )
+ assert stale_limited_navigation.status_code == 404
fresh_client = app.test_client()
fresh_login = fresh_client.get(
@@ -1220,7 +1300,15 @@ def test_limited_show_guest_is_admitted_once_and_not_live_revoked(
base_url="https://alex.avibe.bot",
environ_base=_remote_peer(),
)
- assert still_open.status_code == 200
+ assert still_open.status_code == 404
+ stale_private_navigation = client.get(
+ f"/p/{share_id}/",
+ base_url="https://alex.avibe.bot",
+ environ_base=_remote_peer(),
+ headers={"Accept": "text/html"},
+ follow_redirects=False,
+ )
+ assert stale_private_navigation.status_code == 404
new_visit = app.test_client().get(
f"/p/{share_id}/",
base_url="https://alex.avibe.bot",
diff --git a/vibe/ui_server.py b/vibe/ui_server.py
index c35d680e9..2df70dab7 100644
--- a/vibe/ui_server.py
+++ b/vibe/ui_server.py
@@ -15163,6 +15163,14 @@ def _with_limited_show_policy(response: Response) -> Response:
return response
+def _show_limited_not_found_response():
+ result = _show_page_not_found_response()
+ if isinstance(result, tuple):
+ response, status = result
+ return _with_limited_show_policy(response), status
+ return _with_limited_show_policy(result)
+
+
@app.route("/auth/show-identity/callback", methods=["POST"])
async def complete_show_identity_login():
from core.show_pages import ShowPageStore
@@ -15308,6 +15316,10 @@ async def serve_public_show_page(share_id, asset_path):
page = store.get_by_share_id(share_id)
if page is None and lease is not None:
page = store.get(lease.page_id)
+ if page is not None:
+ access = store.get_access(page.session_id)
+ if access is None or access.share_id != share_id:
+ return _show_limited_not_found_response()
if page is None:
return _show_page_not_found_response()
limited_guest = (
@@ -15339,6 +15351,19 @@ async def serve_public_show_page(share_id, asset_path):
if query:
private_target = f"{private_target}?{query}"
return redirect(private_target)
+ if limited_guest:
+ # A guest lease does not grant a grace period after access changes.
+ # Already-rendered pages are not proactively closed, but every
+ # subsequent request must match the current local access record.
+ access = store.get_access(page.session_id)
+ if (
+ access is None
+ or page.visibility != "limited"
+ or access.access_mode != "limited"
+ or access.share_id != share_id
+ or lease.normalized_email not in access.normalized_emails
+ ):
+ return _show_limited_not_found_response()
if page.visibility == "limited":
if not limited_guest:
if request.method != "GET" or not is_spa_navigation: