Repository navigation
Conversation
There was a problem hiding this comment.
Review mode: initial
Requirement — Pass
Optional Cloudflare Access sign-in removes a separate token-entry step for already authenticated users while preserving explicit namespace access and existing login methods.
Evidence
- The fixed PR description establishes the sign-in use case and opt-in deployment scope.
- Existing hub/src/web/routes/auth.ts:41 requires a HAPI access token for browser authentication; Cloudflare authentication did not previously satisfy this flow.
Approach — Pass
The approach fits the existing authentication model: verify signed Access assertions, map allowlisted emails to namespaces, and issue identity-bound HAPI JWTs checked consistently across protected entry points.
Evidence
- hub/src/web/cloudflareAccess.ts:50 fixes the JWKS endpoint, issuer, audience and signing algorithm from configuration.
- hub/src/web/routes/auth.ts:118 bounds session expiry and includes identity-binding claims.
- hub/src/web/authToken.ts:79 checks the current assertion and identity; REST/SSE, terminal and voice authentication reuse this verifier.
- web/src/hooks/useAuthSource.ts:186 preserves login precedence and limits same-origin capability discovery to five seconds.
Code — Reviewed
Reviewed the entire merge-base diff at 582e8f7 and relevant surrounding code. No actionable defects found. Verification was limited to read-only inspection; PR code was not executed.
No reportable code issues found.
Testing
Not run (automation; PR code execution is prohibited).
- At the fixed head, integration and windows-codex-mcp checks succeeded; test remained in progress.
- Added tests cover configuration validation, assertion verification, identity binding, protected entry points, discovery precedence, fallback and refresh scheduling.
- The PR reports passing local checks but explicitly leaves live Cloudflare/identity-provider login unverified; those results were not independently reproduced.
- Static diff whitespace checking passed.
HAPI Bot
…origin hardening for Cloudflare Access
…instead of token-only trap
There was a problem hiding this comment.
Review mode: follow-up after new commits
Requirement — Pass
Optional Cloudflare Access sign-in removes duplicate token entry for authenticated browser users while preserving explicit namespace access.
Evidence
- The fixed PR description defines the opt-in, same-origin browser use case.
- Base hub/src/web/routes/auth.ts requires a separate HAPI access token or Telegram authentication.
Approach — Pass
Verifying signed assertions, mapping allowlisted emails to namespaces, and enforcing identity-bound JWTs across protected entry points is a viable approach.
Evidence
- hub/src/web/cloudflareAccess.ts:65 verifies RS256 signatures against the configured issuer and audience.
- hub/src/web/routes/auth.ts:122 bounds session expiry; hub/src/web/authToken.ts:79 verifies the current assertion and identity binding.
- REST/SSE, terminal, and voice entry points reuse verifyWebAuthToken.
Code — Reviewed
Reviewed the entire merge-base diff at d92555d. Found one client cache isolation defect. Analysis was read-only; PR code was not executed.
- [Major] Isolate service-worker API caches across Access identity switches —
web/src/App.tsx:85
Testing
Not run (automation; PR code execution is prohibited).
- At the fixed head, integration, windows-codex-mcp, and drift-gate checks succeeded; test remained in progress.
- Added tests cover configuration, assertion verification, identity binding, login precedence, refresh, and in-memory cache cleanup, but do not exercise service-worker caches during identity changes.
- The PR reports passing local verification and explicitly leaves live Cloudflare/identity-provider login unverified; these results were not independently reproduced.
- Static diff whitespace checking passed. Tests and builds were not run under the read-only review rules.
HAPI Bot
There was a problem hiding this comment.
✅ All stages passed
Review mode: follow-up after new commits
Requirement — Pass
Optional Cloudflare Access sign-in removes duplicate credential entry for authenticated browser users while preserving explicit namespace access and existing login methods.
Evidence
- The fixed PR description establishes the opt-in, same-origin browser use case.
- Base hub/src/web/routes/auth.ts requires a HAPI access token or Telegram authentication; it cannot authenticate an Access identity directly.
Approach — Pass
Verifying signed Access assertions, mapping allowlisted emails to namespaces, and enforcing identity-bound HAPI JWTs across protected entry points fits the existing authentication model.
Evidence
- hub/src/web/cloudflareAccess.ts:50 derives the JWKS endpoint from configuration and verifies RS256, issuer, audience, expiry and allowlisted email.
- hub/src/web/authToken.ts:79 checks the current assertion and identity binding; REST/SSE, terminal and voice reuse this verifier.
- web/src/hooks/useAuthSource.ts:188 preserves existing authentication precedence and bounds same-origin discovery.
Code — Reviewed
Reviewed the entire merge-base diff at b649056 and relevant surrounding code. No actionable defects found. The previous service-worker cache finding is addressed through Hub/identity cache partitioning and cleanup, with regression coverage for failed and timed-out requests after identity switches. Analysis was read-only; PR code was not executed.
No reportable code issues found.
Testing
Not run (automation; PR code execution is prohibited).
- At the fixed head, integration, windows-codex-mcp and drift-gate checks succeeded; test remained in progress.
- Added coverage includes configuration validation, assertion verification, identity binding, login precedence, refresh, cache cleanup and service-worker identity isolation.
- Static diff whitespace checking passed. Tests and builds were not run under the review execution restrictions.
- The PR reports passing local verification and explicitly leaves live Cloudflare/identity-provider login unverified; reported results were not independently reproduced.
HAPI Bot
# Conflicts: # docs/api/client-contract/auth.md # web/src/App.tsx # web/src/api/client.ts # web/src/components/LoginPrompt.tsx # web/src/hooks/useAuth.ts # web/src/hooks/useAuthSource.ts
There was a problem hiding this comment.
Review mode: follow-up after new commits
Requirement — Pass
Users who already signed in through Cloudflare Access should be able to open the Hub-hosted web app without entering a second credential. An opt-in email-to-namespace mapping gives operators control over who can use HAPI and which sessions they can access.
Evidence
- The fixed PR description establishes the same-origin browser use case and the operator-managed allowlist.
- Base hub/src/web/routes/auth.ts:29 requires a separate HAPI access token, passkey session, or Telegram credential.
Approach — Pass
Exchanging a verified Access assertion for a short-lived HAPI JWT fits the existing web authentication flow. A shared verifier enforces the same identity binding at protected web entry points while the CLI keeps its existing access-token check.
Evidence
- hub/src/web/cloudflareAccess.ts:65 verifies the signature, configured issuer, and audience before the allowlist lookup.
- hub/src/web/routes/auth.ts:138 caps the JWT lifetime at the assertion expiry, and hub/src/web/authToken.ts:95 checks the current assertion's subject, email, and namespace against the JWT.
- REST and SSE, terminal, and voice use the shared verifier through hub/src/web/middleware/auth.ts:48, hub/src/socket/server.ts:171, and hub/src/web/server.ts:701. The CLI checks its own credential at hub/src/socket/server.ts:144.
Code — Reviewed
Reviewed the 45-file merge-base diff at 5fc6c45. The follow-up addresses the exchange timeout, passkey fallback, and same-tab cache cleanup when token fallback changes namespaces. Telegram binding, request replay, push revocation, and recovery still have defects.
- [Major] Preserve first-time Telegram account binding —
web/src/hooks/useAuth.ts:236 - [Major] Prevent custom API retries from crossing Access identities —
web/src/hooks/useAuth.ts:224 - [Major] Prevent push delivery after Access revocation —
hub/src/web/middleware/auth.ts:57 - [Major] Isolate cached data during service-worker upgrades —
web/src/lib/swCachePolicy.ts:118 - [Minor] Expose manual sign-in when Access verification returns 503 —
web/src/App.tsx:567 - [Minor] Apply the refresh interval after transient failures —
web/src/hooks/useAuth.ts:480
Testing
Not run (automation; PR code execution is prohibited).
- GitHub checks passed for 5fc6c45, including the aggregate test check, browser, core, integration, CLI and web unit tests, wrapper parity, Windows Codex MCP, and fixture drift.
- The fixed merge-base diff passed
git diff --check. The review was read-only and did not execute PR code. - The added tests cover assertion binding, namespace fallback, and cache partitioning with the new worker. They do not cover the old-worker upgrade, custom mutation replay after an identity switch, or push delivery after allowlist removal. The author reports that live Cloudflare and identity-provider login remain unverified.
HAPI Bot
There was a problem hiding this comment.
Review mode: follow-up after new commits
Requirement — Pass
Allowlisted users who already signed in through Cloudflare Access should be able to open the Hub-hosted web app without entering a separate HAPI credential. An opt-in email-to-namespace mapping gives operators control over which HAPI sessions those users can access.
Evidence
- The fixed PR description specifies same-origin browser sign-in and an operator-managed allowlist.
- Base hub/src/web/routes/auth.ts:29 requires a HAPI access token, a passkey session, or a Telegram credential.
Approach — Pass
Exchanging a verified Access assertion for a short-lived HAPI JWT fits the existing web authentication flow. The shared verifier enforces the identity and namespace binding at protected entry points, and delivery-time allowlist checks extend revocation to Access-bound push registrations.
Evidence
- hub/src/web/cloudflareAccess.ts:65 verifies the configured issuer and audience. hub/src/web/routes/auth.ts:138 caps the HAPI JWT lifetime at the assertion expiry.
- hub/src/web/authToken.ts:98 checks the current assertion against the JWT. REST and SSE, terminal, and voice use this verifier through hub/src/web/middleware/auth.ts:49, hub/src/socket/server.ts:171, and hub/src/web/server.ts:701.
- hub/src/socket/server.ts:144 retains the CLI access-token check. hub/src/config/accessAllowlist.ts:47 filters push recipients against the current mapping.
Code — Reviewed
Reviewed the 78-file merge-base diff at f38d4bc. Two identity-switch gaps remain, along with regressions in push re-enrollment and sign-in recovery.
- [Major] Isolate authenticated caches while the previous service worker is active —
web/src/lib/swCachePolicy.ts:118 - [Major] Retire existing API clients when the Access identity changes —
web/src/hooks/useAuth.ts:387 - [Minor] Preserve independently authorized push subscriptions —
hub/src/store/pushSubscriptions.ts:51 - [Minor] Make the Cloudflare sign-in action recover from an unlisted account —
web/src/App.tsx:123
Testing
Not run (automation; PR code execution is prohibited).
- GitHub checks passed for f38d4bc, including the aggregate test check, browser, core, integration, CLI and web unit tests, wrapper parity, Windows Codex MCP, and fixture drift.
- The fixed merge-base diff passed git diff --check. No PR code was executed during this review.
- The added tests cover the new service worker and individual API retries. They do not cover a previous worker still controlling the app or a retained API client continuing a multi-step mutation after an identity switch. The author reports that live Cloudflare and identity-provider login remain unverified.
HAPI Bot
f38d4bc to
f60421a
Compare
f60421a to
2857392
Compare
There was a problem hiding this comment.
Review mode: follow-up after new commits
Requirement — Pass
Allowlisted users who already authenticated through Cloudflare Access should be able to open the Hub-hosted web app without entering a separate HAPI credential. Operators need to control which HAPI namespace each identity can access.
Evidence
- The fixed PR description specifies opt-in browser sign-in with an operator-managed email-to-namespace mapping.
- The base login route requires a HAPI access token, passkey session, or Telegram credential at hub/src/web/routes/auth.ts:29.
Approach — Pass
Exchanging a verified Access assertion for a short-lived HAPI JWT fits the existing web authentication flow. A shared verifier enforces identity and namespace binding across protected entry points, and delivery-time allowlist checks cover Access-enrolled push registrations.
Evidence
- hub/src/web/cloudflareAccess.ts:65 verifies the configured issuer and audience. hub/src/web/routes/auth.ts:138 caps the HAPI JWT lifetime at the assertion expiry.
- hub/src/web/authToken.ts:98 checks the current assertion against the JWT. REST and SSE, terminal, and voice use this verifier through hub/src/web/middleware/auth.ts:49, hub/src/socket/server.ts:171, and hub/src/web/server.ts:701.
- hub/src/socket/server.ts:144 retains CLI access-token authentication, and hub/src/config/accessAllowlist.ts:47 checks push recipients against the current mapping.
Code — Reviewed
Reviewed the 79-file merge-base diff at 2857392. The follow-up retires old API clients on identity changes, preserves independently authorized push enrollments, and adds an account-switch action. Cache isolation during service worker upgrades and recovery from an Access redirect still need attention.
- [Major] Isolate authenticated responses while the previous service worker is active —
web/src/lib/swCachePolicy.ts:119 - [Minor] Recover when Cloudflare redirects a protected API request —
web/src/api/client.ts:344 - [Minor] Document the public URL and CORS settings separately —
docs/guide/deployment.md:145
Testing
Not run (automation; PR code execution is prohibited).
- GitHub checks passed for 2857392, including the aggregate test check, browser, core, integration, CLI and web unit tests, wrapper parity, Windows Codex MCP, and fixture drift.
- The fixed merge-base diff passed git diff --check. No PR code was executed during this review.
- The new tests cover identity isolation in the new service worker and rejection responses from the Hub. They do not cover a previous worker still controlling the upgraded app or an Access edge redirect during an authenticated API request. The author reports that live Cloudflare and identity-provider login remain unverified.
HAPI Bot
Users already signed in through Cloudflare Access reach the HAPI web app directly, without pasting a separate access token into each browser.
Problem
When the Hub sits behind Cloudflare Access, the web app currently still asks for the HAPI access token, even though Access has already identified the user.
Solution
The Hub can opt into a fixed Access team domain, application audience and exact email-to-namespace allowlist. It verifies the signed application JWT with the existing
josedependency and issues an existing-format HAPI web session bound to the Access identity and expiry, enforced at REST/SSE, terminal and voice WebSocket entry points. Web push subscriptions and native device registrations created during an Access-derived session store the verified Access email and subject, and every send rechecks that email against the current allowlist: a registration whose email no longer maps to its namespace is skipped and deleted. Token, passkey and Telegram registrations keep a null identity and are not gated. The web app discovers the capability on the same origin after Telegram, explicit/saved tokens and saved passkey sessions, signs in automatically, and keeps manual login for disabled or older Hubs and failed authentication. When the exchange fails, the sign-in screen offers Sign in with Cloudflare Access, Retry and a link to the access token form. Passkey registration is unavailable in Cloudflare-derived sessions. No CLI token is created or persisted; no package, lockfile or native pairing changes are needed; the hub database gains two nullable columns through a schema migration.Set the three variables in the Hub process environment before starting it:
The AUD is the Application Audience (AUD) Tag from Cloudflare Zero Trust → Access controls → Applications → your application's Configure → Additional settings (instructions). Emails match case-insensitively;
defaultgrants Hub owner access. All three variables absent disables the feature; partial or malformed values fail startup. For systemd or Docker Compose, set them throughEnvironment/EnvironmentFileorenvironment/env_fileand restart the Hub; browsers and CLI runners need nothing.Discovery is limited to 5 seconds and the scheduled refresh timer keeps requests at least 15 seconds apart (a focus/online check may refresh sooner when the session is near expiry; 401 forces an immediate refresh). Cloudflare-derived sessions expire at the earlier of 4 hours and the assertion expiry and remain bound to a current assertion on protected requests; already-open SSE/WebSocket streams are not continuously revoked. Disabled discovery returns 404, missing or invalid assertions 401, disallowed users 403 and verification-key failures 503. Multiple identity providers, including Google, Microsoft, OIDC/SAML and email OTP, work through the same signed-email contract. Native companion pairing still requires the existing access token.
Limitations
Tests
bun typecheck && bun run test && bun run build:web && bun run build:hub && bun run --cwd docs docs:buildunder Node 22 (existing CLI tests needPromise.withResolvers).