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-page): refresh scoped access for existing sessions

Maxf1e338fb9bee
diff --git a/docs/plans/show-page-email-access.md b/docs/plans/show-page-email-access.md
index 616320329..e3b71d05b 100644
--- a/docs/plans/show-page-email-access.md
+++ b/docs/plans/show-page-email-access.md
@@ -20,6 +20,12 @@ Anonymous Public links remain an independent sharing switch.
- When a broader user also has the target ShowPage email grant, the broader
source and role remain unchanged while the signed `vibe_show_page_id` is
retained as an independent exact-page entitlement.
+- The exact-page entitlement bypass applies only to ShowPage routes and
+ ShowPage-specific APIs. Generic Session APIs still require their normal
+ Project/session ACL so a page grant cannot expose the owner's transcript.
+- A broader browser session that predates a page grant reauthorizes once when
+ the requested ShowPage is otherwise forbidden, allowing the control plane to
+ refresh the signed exact-page entitlement without requiring logout.
- A `show_page_email` browser session may serve only the exact
`/show/<vibe_show_page_id>` route subtree and required public static assets.
Workbench, Chat, other Sessions, Agents, files, Cloud capabilities, APIs, and
diff --git a/tests/scenario_harness/show_page_email_access.py b/tests/scenario_harness/show_page_email_access.py
index 262e03028..c579060ec 100644
--- a/tests/scenario_harness/show_page_email_access.py
+++ b/tests/scenario_harness/show_page_email_access.py
@@ -92,7 +92,30 @@ class ShowPageEmailAccessScenarioHarness:
"nonce": handshake["nonce"],
}
- def complete_login(self, handshake: dict[str, str]):
+ def seed_broader_session(self) -> None:
+ cookie = remote_access.make_session_cookie(
+ self.config,
+ "guest-1",
+ session_claims={
+ "vibe_instance_id": "inst_123",
+ "vibe_instance_role": "editor",
+ "vibe_instance_access_source": "email",
+ },
+ )
+ self.client.set_cookie(
+ remote_access.SESSION_COOKIE_NAME,
+ cookie,
+ domain="alex.avibe.bot",
+ )
+
+ def complete_login(
+ self,
+ handshake: dict[str, str],
+ *,
+ instance_role: str = "viewer",
+ access_source: str = "show_page_email",
+ ):
show_page_id = handshake["show_page_id"]
exchange_result = {
"claims": {
@@ -102,8 +125,8 @@ class ShowPageEmailAccessScenarioHarness:
},
"session_claims": {
"vibe_instance_id": "inst_123",
- "vibe_instance_role": "viewer",
- "vibe_instance_access_source": "show_page_email",
+ "vibe_instance_role": instance_role,
+ "vibe_instance_access_source": access_source,
"vibe_show_page_id": show_page_id,
},
}
diff --git a/tests/scenarios/auth_setup/test_auth_setup_scenarios.py b/tests/scenarios/auth_setup/test_auth_setup_scenarios.py
index 07aa99463..8261509a0 100644
--- a/tests/scenarios/auth_setup/test_auth_setup_scenarios.py
+++ b/tests/scenarios/auth_setup/test_auth_setup_scenarios.py
@@ -67,6 +67,23 @@ class ShowPageEmailAccessScenarioTests(unittest.TestCase):
self.assertEqual(other.get_json()["error"], "show_page_access_forbidden")
self.assertEqual(api.status_code, 403)
+ self.harness.seed_broader_session()
+ existing_session_handshake = self.harness.begin_login("session-one")
+ existing_session_callback = self.harness.complete_login(
+ existing_session_handshake,
+ instance_role="editor",
+ access_source="email",
+ )
+ self.assertEqual(existing_session_callback.status_code, 302)
+ self.assertEqual(
+ existing_session_callback.headers["Location"],
+ existing_session_handshake["next_path"],
+ )
+ self.assertEqual(
+ self.harness.get(existing_session_handshake["next_path"]).status_code,
+ 200,
+ )
+
class _FakeNextTurnRuntime:
def __init__(self):
diff --git a/tests/test_resource_acl_show_pages.py b/tests/test_resource_acl_show_pages.py
index 7b25a8dab..731a84a90 100644
--- a/tests/test_resource_acl_show_pages.py
+++ b/tests/test_resource_acl_show_pages.py
@@ -224,7 +224,16 @@ def test_remote_show_page_list_and_direct_requests_enforce_policy(monkeypatch, t
assert {item["session_id"] for item in catalog.get_json()["pages"]} == {"ses-public", "ses-scope"}
assert mutation.status_code == 403
assert mutation.get_json()["code"] == "resource_access_forbidden"
- assert page.status_code == 403
+ assert page.status_code == 302
+ assert "show_page_id=ses-private" in page.headers["Location"]
+
+ reauth_result = client.get(
+ "/show/ses-private/?__vibe_show_page_reauth=1",
+ base_url="https://alex.avibe.bot",
+ environ_base=_remote_peer(),
+ follow_redirects=False,
+ )
+ assert reauth_result.status_code == 403
def test_remote_show_page_creation_defaults_private_and_org_public_does_not_share(monkeypatch, tmp_path) -> None:
diff --git a/tests/test_ui_remote_access_auth.py b/tests/test_ui_remote_access_auth.py
index 5e6eb4d0e..db86513c6 100644
--- a/tests/test_ui_remote_access_auth.py
+++ b/tests/test_ui_remote_access_auth.py
@@ -164,6 +164,82 @@ def test_private_show_page_login_freezes_target_in_authorize_and_handshake(
assert stored["show_page_id"] == "session-one"
+def test_existing_broader_session_reauthorization_stops_when_grant_is_missing(
+ monkeypatch,
+ tmp_path,
+):
+ from core.show_pages import ShowPageStore
+
+ monkeypatch.setenv("AVIBE_HOME", str(tmp_path))
+ config = _save_config(tmp_path)
+ store = ShowPageStore()
+ try:
+ store.ensure("session-one")
+ finally:
+ store.close()
+ client = app.test_client()
+ client.set_cookie(
+ remote_access.SESSION_COOKIE_NAME,
+ remote_session_cookie(
+ config,
+ "guest-1",
+ role="editor",
+ access_source="email",
+ ),
+ domain="alex.avibe.bot",
+ )
+
+ start = client.get(
+ "/show/session-one/__show/me",
+ base_url="https://alex.avibe.bot",
+ environ_base=_remote_peer(),
+ follow_redirects=False,
+ )
+ authorize_params = httpx.URL(start.headers["Location"]).params
+ state = authorize_params["state"]
+ state_payload = ui_server._read_oauth_state(
+ config.remote_access.vibe_cloud.session_secret,
+ state,
+ )
+ assert state_payload is not None
+ nonce = remote_access._oauth_handshakes[state_payload["r"]]["nonce"]
+ monkeypatch.setattr(
+ remote_access,
+ "exchange_oauth_code",
+ lambda *args, **kwargs: {
+ "claims": {
+ "email": "[email protected]",
+ "sub": "guest-1",
+ "nonce": nonce,
+ },
+ "session_claims": {
+ "vibe_instance_id": "inst_123",
+ "vibe_instance_role": "editor",
+ "vibe_instance_access_source": "email",
+ },
+ },
+ )
+
+ callback = client.get(
+ f"/auth/callback?code=test-code&state={state}",
+ base_url="https://alex.avibe.bot",
+ environ_base=_remote_peer(),
+ follow_redirects=False,
+ )
+ assert callback.status_code == 302
+ assert ui_server.REMOTE_SHOW_PAGE_REAUTH_PARAM in callback.headers["Location"]
+
+ denied = client.get(
+ callback.headers["Location"],
+ base_url="https://alex.avibe.bot",
+ environ_base=_remote_peer(),
+ follow_redirects=False,
+ )
+ assert denied.status_code == 404
+ assert "Location" not in denied.headers
+
+
def test_show_page_email_session_is_confined_to_its_signed_route(monkeypatch, tmp_path):
monkeypatch.setenv("AVIBE_HOME", str(tmp_path))
config = _save_config(tmp_path)
@@ -2176,6 +2252,96 @@ def test_remote_owner_can_still_read_authorized_session_history(
]
+def test_signed_show_page_entitlement_does_not_bypass_session_history_acl(
+ monkeypatch,
+ tmp_path,
+):
+ from core.show_pages import ShowPageStore
+ from storage import (
+ messages_service,
+ project_access_service,
+ projects_service,
+ workbench_sessions_service,
+ )
+ from storage.db import create_sqlite_engine
+ from storage.importer import ensure_sqlite_state
+
+ monkeypatch.setenv("AVIBE_HOME", str(tmp_path))
+ config = _save_config(tmp_path)
+ ensure_sqlite_state()
+ engine = create_sqlite_engine()
+ project_dir = tmp_path / "page-entitlement-project"
+ project_dir.mkdir()
+ with engine.begin() as conn:
+ project = projects_service.create_project(conn, str(project_dir))
+ applied = project_access_service.apply_project_access_intent(
+ conn,
+ {
+ "project_id": project["id"],
+ "organization_id": "org-1",
+ "revision": 1,
+ "mode": "restricted",
+ "bindings": [
+ {
+ "principal_kind": "organization_group",
+ "principal_value": "group-engineering",
+ "access_role": "viewer",
+ }
+ ],
+ },
+ )
+ assert applied.outcome == "applied"
+ session = workbench_sessions_service.create_session(
+ conn,
+ scope_id=project["scope_id"],
+ agent_backend="codex",
+ agent_name="owner-worker",
+ )
+ messages_service.append(
+ conn,
+ scope_id=project["scope_id"],
+ session_id=session["id"],
+ platform="avibe",
+ author="user",
+ message_type="user",
+ text="owner-only transcript",
+ )
+ show_pages = ShowPageStore()
+ try:
+ show_pages.ensure(session["id"])
+ finally:
+ show_pages.close()
+
+ client = app.test_client()
+ client.set_cookie(
+ remote_access.SESSION_COOKIE_NAME,
+ remote_session_cookie(
+ config,
+ "guest-1",
+ session_claims={
+ "vibe_instance_id": "inst_123",
+ "vibe_instance_role": "editor",
+ "vibe_instance_access_source": "organization_group",
+ "vibe_organization_id": "org-1",
+ "vibe_organization_member_id": "member-guest-1",
+ "vibe_organization_role": "member",
+ "vibe_group_ids": ["group-sales"],
+ "vibe_show_page_id": session["id"],
+ },
+ ),
+ domain="alex.avibe.bot",
+ )
+ response = client.get(
+ f"/api/sessions/{session['id']}/messages",
+ base_url="https://alex.avibe.bot",
+ environ_base=_remote_peer(),
+ )
+
+ assert response.status_code == 404
+ assert response.get_json() == {"ok": False, "error": "not_found"}
+
+
def test_remote_viewer_can_read_but_cannot_use_management_api(monkeypatch, tmp_path):
monkeypatch.setenv("AVIBE_HOME", str(tmp_path))
config = _save_config(tmp_path)
diff --git a/vibe/ui_server.py b/vibe/ui_server.py
index b71937cfd..f8308f42e 100644
--- a/vibe/ui_server.py
+++ b/vibe/ui_server.py
@@ -167,6 +167,7 @@ VAULT_SANDBOX_PERMISSIONS_POLICY = (
)
REMOTE_OAUTH_COOKIE_NAME = "__Host-vibe_remote_oauth"
REMOTE_OAUTH_RETRY_PARAM = "__vibe_oauth_retry"
+REMOTE_SHOW_PAGE_REAUTH_PARAM = "__vibe_show_page_reauth"
# Lifetime of the short-lived OAuth handshake (signed state + PKCE cookie). The
# cookie MUST carry an explicit Max-Age: iOS standalone PWAs drop session-scoped
# cookies (no Max-Age) across the cross-origin authorize excursion / app
@@ -1646,6 +1647,27 @@ def _add_oauth_retry_param(value: str) -> str:
return urlunsplit(("", "", parsed.path or "/", urlencode(params), ""))
+def _strip_show_page_reauth_param(value: str) -> str:
+ target = _safe_remote_redirect_target(value)
+ parsed = urlsplit(target)
+ query = urlencode(
+ [
+ (key, val)
+ for key, val in parse_qsl(parsed.query, keep_blank_values=True)
+ if key != REMOTE_SHOW_PAGE_REAUTH_PARAM
+ ]
+ )
+ return urlunsplit(("", "", parsed.path or "/", query, ""))
+
+
+def _add_show_page_reauth_param(value: str) -> str:
+ target = _strip_show_page_reauth_param(value)
+ parsed = urlsplit(target)
+ params = parse_qsl(parsed.query, keep_blank_values=True)
+ params.append((REMOTE_SHOW_PAGE_REAUTH_PARAM, "1"))
+ return urlunsplit(("", "", parsed.path or "/", urlencode(params), ""))
+
+
def _oauth_callback_arg(name: str) -> str | None:
return request.args.get(name) or request.args.get(f"amp;{name}")
@@ -1662,7 +1684,11 @@ def _show_page_id_from_private_route(path: str) -> str | None:
return None
-def _redirect_to_vibe_cloud_login(config: V2Config):
+def _redirect_to_vibe_cloud_login(
+ config: V2Config,
+ *,
+ show_page_reauth: bool = False,
+):
from vibe import remote_access
cloud = config.remote_access.vibe_cloud
@@ -1670,7 +1696,9 @@ def _redirect_to_vibe_cloud_login(config: V2Config):
digest = hashlib.sha256(code_verifier.encode("ascii")).digest()
code_challenge = base64.urlsafe_b64encode(digest).rstrip(b"=").decode("ascii")
raw_next = request.full_path if request.query_string else request.path
- next_target = _strip_oauth_retry_param(raw_next)
+ next_target = _strip_show_page_reauth_param(_strip_oauth_retry_param(raw_next))
+ if show_page_reauth:
+ next_target = _add_show_page_reauth_param(next_target)
show_page_id = _show_page_id_from_private_route(request.path)
rid = secrets.token_urlsafe(18)
state = _make_oauth_state(
@@ -2207,7 +2235,22 @@ def enforce_remote_access_cookie():
return _auth_rate_limit_response()
return _redirect_to_vibe_cloud_login(config)
return jsonify({"ok": False, "error": "remote_access_authorization_refresh_required"}), 401
- g.authorization_context = context_from_session_payload(payload)
+ context = context_from_session_payload(payload)
+ if request.method == "GET" and context.instance_access_source != "show_page_email":
+ show_page_id = _show_page_id_from_private_route(request.path)
+ if show_page_id is not None:
+ resource_allowed = context.can_use_show_page(
+ show_page_id
+ ) or _show_page_resource_access_allowed(context, show_page_id)
+ reauth_attempted = request.args.get(REMOTE_SHOW_PAGE_REAUTH_PARAM) == "1"
+ raw_next = request.full_path if request.query_string else request.path
+ if reauth_attempted and resource_allowed:
+ return redirect(_strip_show_page_reauth_param(raw_next))
+ if not reauth_attempted and not resource_allowed:
+ if _auth_rate_limited():
+ return _auth_rate_limit_response()
+ return _redirect_to_vibe_cloud_login(config, show_page_reauth=True)
+ g.authorization_context = context
g.remote_session_payload = payload
g.remote_authorization_refresh_at = remote_access.session_authorization_refresh_deadline(payload)
if remote_access.session_needs_renewal(payload):
@@ -2461,9 +2504,9 @@ async def enforce_remote_local_execution_boundary():
_PROJECT_RESOURCE_PATHS = (
("project", re.compile(r"^/api/projects/([^/]+)(?:/agents-md)?$")),
("session", re.compile(r"^/api/sessions/([^/]+)(?:/.*)?$")),
- ("session", re.compile(r"^/api/show-pages/([^/]+)(?:/.*)?$")),
- ("session", re.compile(r"^/api/show/sessions/([^/]+)(?:/.*)?$")),
- ("session", re.compile(r"^/show/([^/]+)(?:/.*)?$")),
+ ("show_page", re.compile(r"^/api/show-pages/([^/]+)(?:/.*)?$")),
+ ("show_page", re.compile(r"^/api/show/sessions/([^/]+)(?:/.*)?$")),
+ ("show_page", re.compile(r"^/show/([^/]+)(?:/.*)?$")),
)
@@ -2496,7 +2539,7 @@ def enforce_project_role_capabilities():
return None
kind, resource_id = resource
- if kind == "session" and context.can_use_show_page(resource_id):
+ if kind == "show_page" and context.can_use_show_page(resource_id):
return None
engine = create_sqlite_engine()
with engine.connect() as conn:
@@ -6172,6 +6215,11 @@ def remote_access_auth_callback():
or session_claims.get("vibe_show_page_id") != expected_show_page_id
):
raise remote_access.OAuthCodeExchangeError("invalid_show_page_id")
+ if (
+ isinstance(expected_show_page_id, str)
+ and session_claims.get("vibe_show_page_id") == expected_show_page_id
+ ):
+ next_target = _strip_show_page_reauth_param(next_target)
except Exception as exc:
# Unauthenticated-reachable (valid handshake + bad code), so rate-limited.
reason = exc.reason if isinstance(exc, remote_access.OAuthCodeExchangeError) else exc.__class__.__name__