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): show access denied to authenticated viewers (#1543)

Call White05d0b3cc73e8
diff --git a/tests/test_ui_show_pages.py b/tests/test_ui_show_pages.py
index b96c15976..7bd92f830 100644
--- a/tests/test_ui_show_pages.py
+++ b/tests/test_ui_show_pages.py
@@ -588,6 +588,101 @@ def test_limited_show_page_uses_editor_route_and_redirects_guest_to_identity(
assert asset.status_code == 404
+def test_limited_show_page_shows_access_denied_to_authenticated_viewer(
+ monkeypatch,
+ tmp_path,
+):
+ monkeypatch.setenv("AVIBE_HOME", str(tmp_path))
+ config = _save_config(tmp_path)
+ _configure_show_identity(config)
+ share_id = _create_show_page("ses123", "limited")
+ client = app.test_client()
+ client.set_cookie(
+ remote_access.SESSION_COOKIE_NAME,
+ remote_session_cookie(
+ config,
+ "viewer-1",
+ role="viewer",
+ ),
+ domain="alex.avibe.bot",
+ )
+
+ def fail_oauth(*_args, **_kwargs):
+ pytest.fail("an authenticated viewer must not be sent through OAuth")
+
+ with monkeypatch.context() as denied_patch:
+ denied_patch.setattr(show_identity, "begin_show_identity_authorization", fail_oauth)
+ html_response = client.get(
+ f"/p/{share_id}/",
+ base_url="https://alex.avibe.bot",
+ environ_base=_remote_peer(),
+ headers={"Accept": "text/html"},
+ follow_redirects=False,
+ )
+ json_response = client.get(
+ f"/p/{share_id}/",
+ base_url="https://alex.avibe.bot",
+ environ_base=_remote_peer(),
+ headers={"Accept": "application/json"},
+ follow_redirects=False,
+ )
+
+ assert html_response.status_code == 403
+ assert "Location" not in html_response.headers
+ assert "You do not have access to this page" in html_response.text
+ assert "Please contact the page owner" in html_response.text
+ assert html_response.headers["Cache-Control"] == "private, no-store"
+ assert "Cookie" in html_response.headers["Vary"]
+ assert json_response.status_code == 403
+ assert json_response.get_json() == {"error": "show_access_forbidden"}
+
+ allowlisted_client = app.test_client()
+ allowlisted_client.set_cookie(
+ remote_access.SESSION_COOKIE_NAME,
+ remote_session_cookie(
+ config,
+ "viewer-1",
+ role="viewer",
+ ),
+ domain="alex.avibe.bot",
+ )
+ allowlisted = allowlisted_client.get(
+ f"/p/{share_id}/",
+ base_url="https://alex.avibe.bot",
+ environ_base=_remote_peer(),
+ headers={"Accept": "text/html"},
+ follow_redirects=False,
+ )
+ assert allowlisted.status_code == 302
+ assert (
+ urllib.parse.urlsplit(allowlisted.headers["Location"]).path
+ == "/api/v1/instances/inst_123/show-identity/authorize"
+ )
+
+ page_scoped_client = app.test_client()
+ page_scoped_client.set_cookie(
+ remote_access.SESSION_COOKIE_NAME,
+ _show_page_email_cookie(
+ config,
+ session_id="other-page",
+ subject="other-viewer",
+ ),
+ domain="alex.avibe.bot",
+ )
+ page_scoped = page_scoped_client.get(
+ f"/p/{share_id}/",
+ base_url="https://alex.avibe.bot",
+ environ_base=_remote_peer(),
+ headers={"Accept": "text/html"},
+ follow_redirects=False,
+ )
+ assert page_scoped.status_code == 403
+ assert 'href="/"' not in page_scoped.text
+
+
def test_limited_show_callback_maps_outages_and_rechecks_share_binding(
monkeypatch,
tmp_path,
diff --git a/vibe/i18n/en.json b/vibe/i18n/en.json
index 8276578ab..2caeb810f 100644
--- a/vibe/i18n/en.json
+++ b/vibe/i18n/en.json
@@ -23,6 +23,12 @@
"title": "Show Page unavailable",
"heading": "This page is unavailable",
"message": "The page does not exist or is no longer available."
+ },
+ "pageAccessDenied": {
+ "title": "Show Page access denied",
+ "heading": "You do not have access to this page",
+ "message": "Please contact the page owner to be added to the allowed list.",
+ "back": "Back to home"
}
},
"harness": {
diff --git a/vibe/i18n/zh.json b/vibe/i18n/zh.json
index 15099b32e..0ee1a857f 100644
--- a/vibe/i18n/zh.json
+++ b/vibe/i18n/zh.json
@@ -23,6 +23,12 @@
"title": "Show Page 暂时不可用",
"heading": "此页面暂时不可用",
"message": "页面不存在,或已不再提供访问。"
+ },
+ "pageAccessDenied": {
+ "title": "无权访问此 Show Page",
+ "heading": "你无权访问此页面",
+ "message": "请联系页面所有者,将你的邮箱加入允许访问名单。",
+ "back": "返回首页"
}
},
"harness": {
diff --git a/vibe/ui_server.py b/vibe/ui_server.py
index 2df70dab7..cb304421e 100644
--- a/vibe/ui_server.py
+++ b/vibe/ui_server.py
@@ -13052,6 +13052,52 @@ def _show_page_not_found_response():
return jsonify({"error": "not_found"}), 404
+def _show_page_access_denied_html_response(*, include_back_link: bool = True):
+ language = _request_ui_language()
+ title = html.escape(t("show.pageAccessDenied.title", language), quote=True)
+ heading = html.escape(t("show.pageAccessDenied.heading", language))
+ message = html.escape(t("show.pageAccessDenied.message", language))
+ back = html.escape(t("show.pageAccessDenied.back", language))
+ back_link = f'<a href="/">{back}</a>' if include_back_link else ""
+ html_body = """<!doctype html>
+<html lang="__LANGUAGE__">
+ <head>
+ <meta charset="utf-8">
+ <meta name="viewport" content="width=device-width, initial-scale=1">
+ <title>__TITLE__</title>
+ <style>
+ body { margin: 0; min-height: 100vh; display: grid; place-items: center; padding: 24px; box-sizing: border-box; font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; background: #f7f8fb; color: #172033; }
+ main { width: min(560px, 100%); border: 1px solid rgba(23, 32, 51, 0.12); border-radius: 12px; background: white; padding: 32px; box-shadow: 0 20px 60px rgba(23, 32, 51, 0.10); }
+ h1 { margin: 0; font-size: clamp(28px, 7vw, 42px); line-height: 1.05; letter-spacing: 0; }
+ p { margin: 14px 0 0; line-height: 1.65; color: #526078; }
+ a { display: inline-block; margin-top: 22px; color: #3157d5; font-weight: 600; text-decoration: none; }
+ a:hover { text-decoration: underline; }
+ </style>
+ </head>
+ <body>
+ <main>
+ <h1>__HEADING__</h1>
+ <p>__MESSAGE__</p>
+ __BACK_LINK__
+ </main>
+ </body>
+</html>
+""".replace("__LANGUAGE__", language).replace("__TITLE__", title).replace("__HEADING__", heading).replace("__MESSAGE__", message).replace("__BACK_LINK__", back_link)
+ response = Response(html_body, status=403, mimetype="text/html; charset=utf-8")
+ return _with_limited_show_policy(response)
+
+
+def _show_page_access_denied_response(*, include_back_link: bool = True):
+ if (
+ request.method in {"GET", "HEAD"}
+ and _show_page_accepts_html()
+ ):
+ return _show_page_access_denied_html_response(include_back_link=include_back_link)
+ response = jsonify({"error": "show_access_forbidden"})
+ response.status_code = 403
+ return _with_limited_show_policy(response)
+
+
def _show_page_file_not_found_response():
response = jsonify({"error": "not_found"})
response.status_code = 404
@@ -13390,6 +13436,13 @@ def _show_public_editor_context():
return instance_owner_context()
+def _show_public_authenticated_context(config: V2Config | None):
+ from vibe.authorization import context_from_session_payload
+
+ session = _resolved_remote_session_payload(config) if config is not None else None
+ return context_from_session_payload(session) if session is not None else None
+
+
async def _show_public_request_author() -> dict[str, str] | None:
context = await asyncio.to_thread(_show_public_editor_context)
if context is None:
@@ -15306,7 +15359,12 @@ def redirect_public_show_page_to_canonical_path(share_id):
methods=["GET", "HEAD", "POST", "PUT", "PATCH", "DELETE", "OPTIONS"],
)
async def serve_public_show_page(share_id, asset_path):
- from core.show_pages import ShowPageError, ShowPageStore, ensure_show_page_dir
+ from core.show_pages import (
+ ShowPageError,
+ ShowPageStore,
+ ensure_show_page_dir,
+ normalize_show_access_email,
+ )
from vibe import show_identity
config = _load_remote_access_config()
@@ -15368,6 +15426,29 @@ async def serve_public_show_page(share_id, asset_path):
if not limited_guest:
if request.method != "GET" or not is_spa_navigation:
return _show_page_not_found_response()
+ authenticated_context = await asyncio.to_thread(
+ _show_public_authenticated_context,
+ config,
+ )
+ if authenticated_context is not None:
+ access = store.get_access(page.session_id)
+ allowlisted = False
+ if authenticated_context.email:
+ try:
+ allowlisted = (
+ access is not None
+ and normalize_show_access_email(authenticated_context.email)
+ in access.normalized_emails
+ )
+ except (TypeError, ValueError):
+ allowlisted = False
+ page_scoped = authenticated_context.can_use_show_page(page.session_id)
+ if not allowlisted and not page_scoped:
+ return _show_page_access_denied_response(
+ include_back_link=(
+ authenticated_context.instance_access_source != "show_page_email"
+ )
+ )
if config is None:
return _show_identity_error_response("identity_unavailable", 503)
return_target = request.full_path if request.query_string else request.path