Skip to content

feat(account): sign in from a PC's own page with GitHub's device flow - #2995

Merged
devswha merged 4 commits into
mainfrom
feat/account-browser-signin
Nov 5, 2026
Merged

devswha merged 4 commits into
mainfrom
feat/account-browser-signin

Conversation

@devswha

@devswha devswha commented Nov 5, 2026 •

Copy link
Copy Markdown
Owner

What

A browser on a PC's own https address can now sign in to the Ovis account in Settings → Phone & devices → Account, as the desktop app can. No redirect can come back to that address (the account service sends sign-ins only to https://app.ovis.sh/, ovis://account/callback and loopback), so the page uses GitHub's device flow (RFC 8628). It shows GitHub's code and an Open GitHub link to github.com/login/device, then polls the account service until the person approves there.

  • server/static.ts: the PC's own shell carries <meta name="ovis-pc-account-service">, set to exactly the origin its connect-src already admits. There is no meta when OVIS_ACCOUNT_SERVICE_URL=off or when that URL is not https. The hosted shell's ovis-account-service meta is a different one, so app.ovis.sh keeps its redirect sign-in. /index.html now revalidates like /.
  • src/lib/account/deviceSignIn.ts: the sign-in is bound to a PKCE-style verifier (32 random bytes, kept in memory only). The service must answer code_challenge_method: "S256", or the page shows no code and polls nothing. The link goes only to GitHub's own device page. On slow_down the interval grows by 5 s, and a 429 waits Retry-After. The session is stored under the same cross-tab lock as a refresh or a sign-out, and never after Cancel, a sign-out or closing Settings.
  • src/components/AccountSection.tsx: when there is no desktop bridge, the section shows on a secure page with that meta, GitHub only. The desktop app keeps its loopback sign-in.
  • shared/account-service-fake.ts: the bound device flow, as in the service.
  • docs/account.md: the contract for the bound device flow and the PC's meta, plus device-code phishing and the PC-origin risk under "What this does not protect against".

Nothing about admission changes. devices.json stays the only authority, a new device is still approved from a linked device by comparing digits, there are no cookies, and the CSP is unchanged.

Precedent: the device-code sign-in of GitHub CLI (gh auth login) and of the Codex CLI. Both show a short code and link to the provider's device page, because nothing can redirect back to them.

Service side: ovis-sh/account#6 (private), already deployed to production (account.ovis.sh, version d39a53c7). Without it the page says the service cannot sign in a browser here yet.

Design review

Codex (Terra, xhigh) reviewed the design before any code was written. What changed because of it:

  • The sign-in is offered on a secure page only.
  • The service must acknowledge the binding.
  • The PC has its own meta, so neither the hosted shell nor the native shell picks up this path.
  • A 429 is handled.
  • Session writes happen under the lock and are dropped once aborted.
  • The verification link is checked exactly.
  • /index.html revalidates.

Device-code phishing is inherent to RFC 8628 and already applied to the headless path; it is documented.

Validation

  • Failing-first tests:
    • src/lib/account/account.test.ts (device sign-in: approve, unbound service refused, 429, denied, expired, cancel, foreign link; PC meta reader).
    • server/static.test.ts (meta injection).
    • shared/account-service-fake.test.ts (binding).
  • bun run check fast on the merged head: all steps ok (typecheck, build, unit tests, conventions, i18n).
  • Real browser check on a throwaway server at https://home-server.example.ts.net:17461 (tailscale serve, isolated herdr session and state dir):
    • Against the old service: the page refused ("This account service can't sign in a browser on this PC yet.").
    • Against production: it showed the code and polled /v1/token about every 6 s.
    • Cancel and leaving the tab stopped the polls.
    • Open GitHub led to GitHub's sign-in, which returns to /login/device. The run stopped there, where a human approves.
    • Checked at 1280 px (dark and light) and 390 px.
  • Not run: bun run check full, and a completed GitHub approval (it needs a human click).

@coderabbitai

coderabbitai Bot commented Nov 5, 2026 •

Copy link
Copy Markdown

Explain Change →

Caution

Review failed

The pull request is closed.

Summary

Summary by CodeRabbit

  • New Features
    • Sign in to your account from a supported secure PC browser by entering a code on GitHub, then return to the page to complete sign-in.
    • View the code, approval status, and cancellation option while sign-in is in progress. Desktop sign-in options remain available.
    • Browser sign-in is offered only when the PC’s account service supports it.

The change adds GitHub device-code sign-in for eligible browsers on a PC’s secure address. The PC shell supplies its configured account-service origin. The flow uses PKCE, supports polling and cancellation, and adds account-interface states, translations, tests, and documentation.

Changes: PC Browser Account Sign-In

Layer / File(s) Summary
Expose and select the PC account service
server/static.ts, server/static.test.ts, src/lib/account/service.ts, src/lib/account/account.test.ts, docs/account.md
The shell inserts the configured HTTPS account-service origin, and the browser accepts the PC-specific service only on a secure page. The shell test covers default, configured, disabled, and HTTP settings.
Implement the verifier-bound device flow
shared/account-service-fake.ts, shared/account-service-fake.test.ts, src/lib/account/deviceSignIn.ts, src/lib/account/account.test.ts, src/lib/account/service.ts, src/lib/account/signin.ts, docs/account.md
Device sign-in sends an S256 challenge and requires the matching verifier on token polling. The flow handles polling intervals, rate limits, errors, expiry, cancellation, and session storage. Tests cover these cases and verification-link restrictions.
Connect the flow to the account interface
src/components/AccountSection.tsx, src/components/AccountPcs.css, src/lib/i18n.{ja,ko,zh}.ts, changelog.d/account-browser-signin.md, docs/account.md
Eligible PC browsers display a device code, verification link, waiting status, and cancellation action. The component cancels pending flows and guards against stale account loads. The changelog and documentation describe the browser flow and related threat-model considerations.

Estimated code review effort: 4 (Complex) | ~45 minutes

Possibly related PRs

  • devswha/ovis#2834: Defines the account-linking contract and service fake that this change uses and extends for verifier-bound device requests.

Suggested reviewers: sma505

Merge Risk: Low · up to 44296

The new sign-in flow has bounded cancellation and error-handling gaps: cancelled starts can remain pending, storage failures can leave the account section blank, and some service responses are not fully handled. These warrant localized fixes or explicit follow-up, but no broad sign-in or device-admission failure was established.

- [ ] Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@devswha

devswha commented Nov 5, 2026

Copy link
Copy Markdown
Owner Author

Review findings (omo, and Codex Terra xhigh) and how each was resolved in f1a5604:

  • Codex HIGH, reproduced: a sign-in cancelled while its session was being written to IndexedDB kept the session. Fixed: the abort is checked again after the write, under the lock, and exactly that session is taken back (never a newer one). New test.
  • omo LOW: a session discarded by Cancel kept its tokens at the service. Fixed: the page calls /v1/signout for it. Covered by the same test.
  • Codex MEDIUM and omo MEDIUM, reproduced: URL.canParse is missing on iOS 16 / Safari 16, so opening Phone & devices crashed there. Fixed: both call sites use new URL in a try.
  • Codex MEDIUM: the phone and Mac apps could show the code sign-in on a PC's page. Fixed: the path is skipped in inNativeApp() and inMacApp(); those apps sign in their own way.
  • Codex MEDIUM: a long Retry-After could keep "Waiting for GitHub" up past the code's lifetime. Fixed: each wait is capped at the time the code has left, and then the page says it expired. New test.
  • Codex MEDIUM: a PC list that came back after Sign out could show the signed-in view again. Fixed: a sign-out or unmount drops the results of loads still in flight.
  • Codex HIGH (omo rated it LOW, unreproduced as a harm): a sign-out in tab A does not cancel a device sign-in waiting in tab B. Kept as designed. The person approved that code at GitHub themselves, so tab B signing in is the sign-in they asked for. This is the same as a redirect sign-in that returns after a sign-out in another tab.

Service side: ovis-sh/account#6 is omo CLEAR at 51feebe and live on account.ovis.sh.

@devswha

devswha commented Nov 5, 2026

Copy link
Copy Markdown
Owner Author

omo re-review at 4429602 found no HIGH. Its points, and what happens to each:

  • MEDIUM, reproduced: after a code sign-in on a PC's own page, Remove from every PC shows on the account's other devices, but this browser's key is a member of no PC, so every PC refuses it (signer_not_member). No device is affected, but the button cannot work. Filed as a follow-up: Account: hide 'Remove from every PC' on a client whose account key is a member of no PC #2996.
  • LOW: useAccountSignedIn reads the sign-in once, on mount, so the device rows' account buttons update only when Settings opens again. Left for later.
  • LOW: Retry-After in its HTTP-date form is read as no value, so the page falls back to the poll interval. The service sends seconds.
  • LOW: changing the language while a code is shown reruns load, which shows the signed-out view while the poll goes on. It finishes signing in once approved.

This PR has had its one fix round (f1a5604); these stay out of it.

@devswha

devswha commented Nov 5, 2026

Copy link
Copy Markdown
Owner Author

Local merge gate (owner-approved): bun run check fast passed on the merged head, threads resolved, merges cleanly. Authentication change: Codex Terra xhigh adversarial design review before code, then omo + Codex on the code (CodeRabbit stand-in). The fix round closed the Codex HIGH (a session kept if sign-in was cancelled mid-write) and the MEDIUMs; omo's re-review has no HIGH, and its one reproduced MEDIUM (a dead 'Remove from every PC' button for a browser whose key is on no PC) is #2996 and does not block. The device-flow poll is bound to an S256 verifier kept only in page memory; admission is unchanged (devices.json, number compare, no cookies). The service side is ovis-sh/account#6 (merged, in production). Merged without waiting for GitHub CI.

@devswha
devswha merged commit 5a6484c into main Nov 5, 2026
16 of 18 checks passed
@devswha
devswha deleted the feat/account-browser-signin branch November 5, 2026 13:46
devswha added a commit that referenced this pull request Nov 5, 2026
…PC (#3004)

Fixes #2996

## What

Settings > Phone & devices showed **Disconnect from all PCs** on the
account's other devices to any browser signed in to the account. A
browser signed in on a PC's own address (GitHub device flow, #2995) and
paired by cookie holds an account key that no row of the PC has, so
every PC refused its signed `remove` with `signer_not_member`, and the
button could never work.

Now the button shows only when this client's account key is a drive
member of the account on this PC, which is the condition the PC itself
checks (`accountSigner` in `server/devices.ts`). Otherwise the row keeps
its own **Revoke**, which works.

- `signsAccountRemoves(devices, account, key)` in `DevicesPanel.tsx`:
true only when some row has `account === signed-in account`,
`account_key === this client's key` and `role === "drive"`.
- The panel reads its account key only after the account sign-in is
known.
- A row holding this client's own key is not offered the removal: that
device leaves with Leave the account (`removeFromAccount` refuses it).

Design: account removal is offered only where it can take effect, and a
plain local Revoke is offered everywhere else. Google Account's device
list follows the same rule, offering remote sign-out only where the
session is allowed to do it.

## Screenshots

Isolated server (mkdtemp state, no herdr), one account member row "Lost
phone", and a browser with an account session.

Before (main), non-member browser: the button shows.

<img
src="https://raw.githubusercontent.com/devswha/ovis/bd1541f273bf71d74e380c61b725d30d2afae752/main-nonmember-1280-light.png"
width="640"> <img
src="https://raw.githubusercontent.com/devswha/ovis/bd1541f273bf71d74e380c61b725d30d2afae752/main-nonmember-390-dark.png"
width="200">

After, non-member browser: only Rename and Revoke.

<img
src="https://raw.githubusercontent.com/devswha/ovis/bd1541f273bf71d74e380c61b725d30d2afae752/fix-nonmember-1280-light.png"
width="640"> <img
src="https://raw.githubusercontent.com/devswha/ovis/bd1541f273bf71d74e380c61b725d30d2afae752/fix-nonmember-390-light.png"
width="200">
<img
src="https://raw.githubusercontent.com/devswha/ovis/bd1541f273bf71d74e380c61b725d30d2afae752/fix-nonmember-1280-dark.png"
width="640"> <img
src="https://raw.githubusercontent.com/devswha/ovis/bd1541f273bf71d74e380c61b725d30d2afae752/fix-nonmember-390-dark.png"
width="200">

After, member browser (a row holds its key): the button stays.

<img
src="https://raw.githubusercontent.com/devswha/ovis/bd1541f273bf71d74e380c61b725d30d2afae752/fix-member-1280-light.png"
width="640"> <img
src="https://raw.githubusercontent.com/devswha/ovis/bd1541f273bf71d74e380c61b725d30d2afae752/fix-member-390-dark.png"
width="200">

## Validation

- `bun test src/components/DevicesPanel.test.ts`: the new tests failed
before the change (no such export) and pass after it (7 pass with the
own-key case).
- `bun run check fast` at the final head, merged with main: pass
(typecheck, build, 12154 unit tests).
- Browser QA at 1280 and 390, light and dark, in all three states above.
Button counts: main non-member 4/4, fix non-member 0/4, fix member 8/8
(2 rows).
- Skipped: `check full` and the integration/browser suites (left to CI).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant