Skip to content

fix(access): a pairing code the open LAN started ends with the gate, and so does a relayed socket that holds the bridge token - #3613

Merged
devswha merged 1 commit into
mainfrom
fix/gate-closes-pending-code
Nov 10, 2026
Merged

devswha merged 1 commit into
mainfrom
fix/gate-closes-pending-code

Conversation

@devswha

@devswha devswha commented Nov 10, 2026

Copy link
Copy Markdown
Owner

Follow-up to #3610, part (b) of the merge pass's list: the two findings its reviewers left. Authentication, so it is opened now under the rule of 2026-11-11. Part (a) is #3611.

Change

  • A pairing code the open LAN started outlived the gate. While nothing is paired, anyone on the LAN can call POST /api/devices/pair/start, and a code admits whoever holds it. When the first device's cookie came back, match() closed the gate and dropped the other unconfirmed first pairings, but left a code still pending: redeemed in the next ten minutes, it took the gated path and paired a device. closeGate() and revokeAll() already end a pending code. In every release so far.
    A code started by a request the open LAN alone let in is now marked (open, set by the start route from access.via), and match() ends it with the gate through endPairing(), so whoever shows it is told and a typed relay code bound to it goes too.
    A code this PC, its token or its owner's login started stays. The request that brings the first cookie back may be the one that redeems it: server/open-access.test.ts pins that flow, and the first version of this change, which ended every pending code, failed it.
  • A relayed socket that also held the bridge token was not marked. fix(access): end what the open LAN let in when the pairing gate closes #3610 kept a bridge-authorized upgrade from being marked open, on both /ws branches. On the relayed branch (/ws?machine_id=<pc>) that was wrong: the bridge token opens this PC's bridge, the route to another PC is the open LAN's, and a new request for it is refused once the gate closes. That socket is marked and ends with the gate. A bridge's local /ws stays unmarked.

No frame or feature is added.

Tests

  • server/devices.test.ts: a code the open LAN started ends when the first cookie closes the gate (the listeners of a code's start are told, the code no longer pairs, only the phone is listed); a code started through the closed gate still pairs; a code this PC started under the open gate still pairs after the first cookie.
  • server/dispatch.test.ts: a relayed upgrade from the LAN with the bridge token is marked open; the bridge's local /ws is not.
  • server/device-access.contract.test.ts: on a real server, a stranger starts a code through the open LAN, the phone's cookie closes the gate, and redeeming the code is refused with no cookie and no device.
  • Failing first: the devices test and the dispatch test failed on main (9cc3530).

Validation

On the pushed head:

  • bun run check fast: pass (unit 15389 pass, 0 fail, 51 skip; typecheck, build, generated types and themes fresh). The first version failed here, in server/open-access.test.ts, which is how the owner's own code came to be kept.
  • bun run check run bun test --timeout 15000 ./server/device-access.contract.test.ts ./server/machine-events.contract.test.ts ./server/relay/session-ws.contract.test.ts: 59 pass.
  • Skipped: bun run check full, the other integration files, every browser script (no page code changes).

🤖 Generated with Claude Code

…layed socket is the open LAN's whatever token it holds

Follow-up to #3610, from the merge pass's reviews of its head. Tests first:
both failed on main.

- `match()` closing the gate on the first device's cookie left a pairing
  code still pending. While the gate was open anyone on the LAN could
  start one, and the code admits whoever holds it: redeemed after the gate
  closed, it took the gated path and paired a device. A code started by a
  request the open LAN alone let in is marked (`open`) and ends with the
  gate (endPairing, so a typed relay code bound to it goes too). In every
  release so far. A code this PC, its token or its owner's login started
  stays: the request that brings the first cookie back may be the one that
  redeems it, which open-access.test.ts pins.
- #3610 left a relayed socket unmarked when its request also held the
  bridge token. The bridge token opens this PC's bridge, not the route to
  another PC: that socket's access is the open LAN's, and a new request
  for it is refused once the gate closes. It is marked and ends with the
  gate. The local `/ws` of a bridge stays unmarked.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
@coderabbitai

coderabbitai Bot commented Nov 10, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Summary

Summary by CodeRabbit

  • Bug Fixes
    • Open-LAN pairing codes can no longer enroll another device after the first device pairs and closes the pairing gate. Pairing codes started through other access paths remain usable.
    • Remote-machine connections authorized through the open-LAN gate are now recognized consistently, including when using a bridge token.

The server now tracks whether a pending device pairing started through open LAN access and ends that pairing when the first-pair cookie closes the gate. Bridge-authorized remote WebSocket connections also retain the open-access marker.

Changes: Open-LAN Gate Lifecycle

Layer / File(s) Summary
End open-LAN pairings when the gate closes
server/devices.ts, server/devices.test.ts, server/device-access.contract.test.ts, changelog.d/open-lan-pairing-code-ends-with-gate.md
The pairing start path records whether access came through the open LAN path. When a first-pair cookie is confirmed, the store ends pending pairings started that way. Tests verify that those codes cannot enroll another device after gate closure, while other pending pairings remain redeemable.
Mark bridge-authorized remote connections as open
server/dispatch.ts, server/dispatch.test.ts
Remote WebSocket connection data now marks full-access requests through the open LAN path as open, including bridge-authorized requests. The test checks the marker and relay.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix · Severity of issue fixed: Medium

Possibly related PRs

  • devswha/ovis#3610: Adds gate-close handling and marks open-LAN WebSocket connections for teardown.
  • devswha/ovis#2504: Adds relay pairing offers and bridge-authorized relayed WebSocket connections, which this change updates.
Merge Risk: Minimal · up to bcd8a

No actionable merge-blocking risk was established in the pairing or relayed WebSocket changes.

Pre-merge checks: Passed 5

Check name Status Explanation
Title check Passed The title clearly identifies both main changes: ending open-LAN pairing codes with the gate and marking relayed sockets that hold the bridge token.
Description check Passed The description explains the problem and resulting behavior, links the follow-up issues, lists validation results and skipped checks, and includes HTTP/WS contract-test coverage.
Docstring Coverage Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentat…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Docstring Coverage

Explanation

Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 1 functions across 5 files. (1 skipped: 1 unsupported.)

Finishing Touches

Generate docstrings

  • Commit to this branch
  • Create a new PR
Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • 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

Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 06836a7 and bcd8a0e.

Files selected for processing: 6

  • changelog.d/open-lan-pairing-code-ends-with-gate.md
  • server/device-access.contract.test.ts
  • server/devices.test.ts
  • server/devices.ts
  • server/dispatch.test.ts
  • server/dispatch.ts

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 4 remain after this review.

@devswha
devswha merged commit fad0cf5 into main Nov 10, 2026
21 checks passed
@devswha

devswha commented Nov 10, 2026

Copy link
Copy Markdown
Owner Author

Merge pass

Merged head bcd8a0e789f0 as fad0cf5036c6 on GitHub's checks, with no unresolved review threads.

Reviewer Verdict Note
claude CLEAR
codex CLEAR

Merge pass note (head bcd8a0e). Both reviewers CLEAR with no findings: both #3610 findings are closed, the open-access mark cannot be avoided, a code the owner started is not ended, and no server-to-server bridge connection is cut.

@devswha
devswha deleted the fix/gate-closes-pending-code branch November 10, 2026 21:21
devswha added a commit that referenced this pull request Nov 10, 2026
…add finishes its clean-up or says it could not (#3616)

Follow-up to #3586, from the merge pass review of its head 7a9ce2a
([note](#3586 (comment))).
Security: it is about devices that stay paired, or get paired, after
`ovis add` said they were removed.

## What

1. **A revoked device's pairing code ends with it** (Opus MEDIUM,
reproduced at the store). On a PC in no account any driving device may
start a pairing code. A device the QR code let in could start one, be
removed, and the code still paired a second device for up to ten
minutes, after the command had printed "Removed.". `DeviceStore.revoke`
now ends the pending code when the revoked device holds it, and tells
the listeners, so the typed code bound to it goes too.
2. **An unreadable device list during clean-up is an unfinished
clean-up** (Codex MEDIUM). As a run ends, the list is read up to three
times inside the 4 s deadline. When it still cannot be read, the command
removes the devices it knew of and says that one may still be paired,
and where to revoke it. Before, it removed nothing and said only
"Stopped.".
3. **Comments and docs no longer claim a proof of membership** (Opus
LOW). A first member links itself with its own key and names its
account; nothing can check that. `docs/account.md` lists it under "What
this does not protect against".
4. **The last look comes after the DELETE** (Opus LOW). After an answer
that removed a device, the run ended on the look taken before the
removal. It now looks once more before it ends.

## How

- `server/devices.ts`: the pending code keeps `holders`, the paired
devices that started it or were handed it. `revoke(id)` calls
`endPairing()` when `id` is among them. This covers Settings' Revoke, an
account `remove` and a relay identity reset, which all go through
`revoke`.
- The reviewed path was `POST /api/devices/pair/start` through the
relay. Two more paths start or hand over a code and are covered the same
way, because a device paired at the PC's own address (which the QR
code's six digits also admit) can use them:
- `pair/start` at the PC's own address: the asking device is recorded
(`by`), apart from `startedBy`, which stays the relay member whose
addition the new device is.
- `POST /api/relay/offer` and `POST /api/relay/code`: `dispatch.ts`
passes the asking device to `handleRelayRequest`, and on to
`RelayService.offer` and `RelayPairCodes.mint`. An offer that carries a
code already pending adds the asker to its holders.
- A code the PC itself started is held by no device and survives any
revoke, so Settings on the PC behaves as before.
- `scripts/plugin-link.ts`:
- `clear` returns why it cannot tell that none is left: the list was
unreadable, or more devices kept pairing than it looks again for. The
sweep and the other-account branch say so. Nothing is said before any
code was shown.
- After a removal the loop continues to a fresh look instead of
returning. The no-account ending ("Sign in on that device, then run ovis
add again") is said by that look, only when the PC is still in no
account and nobody is left to ask about.

## Decisions for the merge pass

- **Scope of (1) is wider than the reproduced path**: four more server
files, about 15 lines, for the direct-address and relay-offer paths.
Without them a device paired at the PC's own address keeps the same
hole. Say if you want only the `startedBy` case.
- **In the other-account branch an unreadable list ends the run with the
warning**; it does not keep looking until the PC answers again.
- **Not changed: variant E**, as instructed.
- **Not changed: clean-up removes a device the owner paired another way
during the run** (Codex's other MEDIUM). It needs pairing provenance on
the server.

## Validation

- Ran: `bun run check fast` on f6bd7fb (main merged in, with #3613's
conflict in `server/devices.ts` resolved): every step ok, 15471 pass, 0
fail.
- Ran on f6bd7fb: `bun test ./server/relay/ ./server/account/
./server/relay-pc.contract.test.ts ./server/relay-pc.test.ts
./server/open-access.test.ts ./server/device-access.contract.test.ts`,
531 pass, 0 fail.
- Failing first, on 06836a7:
- `server/devices.test.ts` "revoking a device that holds a pairing code"
(three tests).
- `server/relay/service.contract.test.ts` "ends the relay offer's code,
and a typed code, with the paired device that asked for it".
- `scripts/plugin-link.test.ts` "says that devices may still be paired
when this PC's devices cannot be read as the run ends, after trying
again", "ends on a look taken after the removal, not the one before it",
and the unreadable cases of "says so when the PC stays in the other
account".
- Failing first, on a70b3ef (second review,
[comment](#3616 (comment))):
the gone-device tests in `server/devices.test.ts` and
`server/relay/pair-code.test.ts`, the 401 cases in the relay contract
test, and the `more` case of the other-account branch.
- Not run: `bun run check full`, the browser regressions (no UI change),
a real phone or relay, the Windows and macOS jobs. This PR touches
`scripts/plugin*` and `server/`, so it waits for GitHub's checks.

Needs a real review: it changes when a pairing code ends
(authentication).

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Co-authored-by: Claude Fable 5.2 <[email protected]>
devswha added a commit that referenced this pull request Nov 10, 2026
…'s and its own asking's (#3611)

Follow-up to #3591, part (a) of the merge pass's list (its note:
#3591 (comment)). Each
of these leaves a password to the plain input line and its draft, or
leaves the field up after its answer. Part (b), the two access findings
from #3610, was #3613.

## Change

The page's reading of a masked prompt moves out of `useTerminalMount`
into `src/lib/secretScreen.ts` (`createSecretScreen(term,
cursorKnown).read(pane)`), where a unit test can drive a real xterm with
frames as herdr draws them: after `?1049h ?7l`, a synchronized update,
every row at its own place with every cell written, the cursor last. The
reviewers of #3591 found each round's defects with scratch tests of that
shape; they are in the tree now.

What the reader does, beyond what #3591 had:

- **What was seen is one pane's.** The asking last seen with the cursor
on it is kept with the pane it was seen on and dropped when the terminal
shows another pane. On main it lived as long as the terminal mount, so
pane B's prompt of the same words, read below its line, was taken for
pane A's answered one and got no field. It is kept while the same pane's
screen is drawn again (a reconnect, a phone that let the pane go while
hidden): there is nothing for the mount to forget.
- **An asking is the prompt's words under as many lines of the same
words.** A script that asks twice prints its second prompt under the
first, and that is all that tells the two apart. So a second and a third
prompt of the same words, read below their line, ask, where main took
them for the answered one. Under fewer of them it is still itself when
they reach the screen's first line (some scrolled off). Nothing else on
the screen is part of an asking.
- **Rows are read as wide as the pane is now.** On the alternate screen,
which herdr's attach draws on, xterm keeps a row's cells past a narrower
edge, and herdr's redraw for a new grid clears nothing. After the pane
narrowed, a prompt on a row that had been wider was not read at all, on
main too (git's prompt drawn at 80 columns and redrawn at 30 while
asking: no field).
- **A long prompt on herdr-core.** On a stream of the program's own
bytes xterm wraps the prompt itself and the page joins its rows, so the
joined text passed the "last row reaches the right edge" measure at any
width, and the field stayed after an answer that ended in a line feed
alone. The row-below rule applies to a line of one row only
(`promptHasCursor`).
- **The older-PC note arriving late.** Whether the field says "This PC
is not updated: …" was decided when the field was drawn. A bridge that
said what it takes after that changed nothing on screen. It is part of
the field's state now (`unchecked`), set again when `features` or a
snapshot comes.

Limits, as on main:

- A prompt herdr draws over two rows, printed again below an answered
one and read below its line, is not told from it (its last row has its
first above it). Pinned by a test.
- The same for a repeated prompt after the first was asked on the
screen's first row with nothing above it, or after a clear in the same
frame.
- A view that never saw the cursor on the prompt (a second device, a
reload) shows the field for as long as the prompt is the last text, and
the server checks only the screen's text: a second answer from there
still passes. #3591's description said "the frame's transit"; it is
wider than that.
- On herdr-core, a prompt whose trailing space fills the last column
still asks after a line feed alone.

No frame, feature or server change. `promptAsks` (shared), which the
page alone used, is removed. No changelog fragment: these correct
#3591's behaviour, which no release has shipped.

## Review history

- 63c42a3 forgot what was seen in `retireOutput`, which also runs on a
reconnect and on a phone's release of its pane: the field came back for
an answered prompt after an app switch, a regression against main (the
merge pass's Opus review, reproduced). It also took the line above the
prompt as part of an asking, which changes with the width and scrolls
away (Opus, Codex).
- A first fix kept four lines above and the width. One more review
before the push, on a real xterm, found that worse than main in three
cases: stale cells past a narrowed edge, a wrapped line cut by the
screen's top on herdr-core, and a clock above the prompt. The asking is
now the smallest thing that still tells a repeated prompt apart.

## Tests

- `src/lib/secretScreen.test.ts`, 16 tests on a real xterm (herdr-shaped
frames, and raw bytes for herdr-core): git's flow, a prompt asked again
in place, the answered prompt at the last row scrolling up; a prompt
read on the row below; a pane switch with the same line above in both
panes; the same pane drawn again after `ESC c` and after a reconnect; a
width change with the line above drawn another way; the line above
scrolling off; a clock above the prompt; a second and a third prompt of
the same words; a prompt that went away and is printed again; identical
prompts scrolling off the top; rows that were wider; a wrapped prompt
answered by a line feed alone, and one that fills its row; a long line
cut by the screen's top; a pane whose cursor is not known.
- `shared/secret-prompt.test.ts`: the row-below rule is refused under a
line of two rows.
- Failing first: with main's logic moved as it is, the pane switch, the
repeated prompt and the herdr-core case failed. With 63c42a3's logic,
the width change, the scrolled-off line, the third prompt and the
two-row prompt failed.
- Each rule of the module fails a test when taken out: the pane, the row
width, the repeats, dropping what was seen when the prompt goes, and the
allowance for lines scrolled off (five mutants, run by hand).
- Not covered by a test: the note arriving late (nothing in the tree
renders `PaneTerminal`; `typesSecret` is covered in `ws.test.ts`), and
the mount's call into the module.

## Validation

On the pushed head:

- `bun run check fast`: pass (unit 15399 pass, 0 fail, 51 skip;
typecheck, build, generated types and themes fresh).
- `bun run check run --build -- bun scripts/ui-contexts-regression.ts`
(runs `checkSecretInput`): 62 PASS, 0 FAIL.
- `bun run check run --build -- bun scripts/ui-regression.ts`: 85 PASS,
0 FAIL.
- On 63c42a3 the ui-contexts group failed once in
`checkNewTabTypeAhead` ("timed out: touch: the new tab ran the command
typed ahead") and passed on a rerun of the same commit; it passed in
both runs since. Cause not found.
- The browser scripts ran on this PC, not in the CI runner image; CI's
browser jobs run them there.
- Not run: a herdr-core server (its cases are unit tests on raw bytes),
Windows, `bun run check full`, the other integration files and browser
scripts.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Co-authored-by: Claude Fable 5.2 <[email protected]>
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