Skip to content

Guard the channel handler's authz pairing (#3145) - #3148

Merged
Birfy merged 1 commit into
mainfrom
dev/3145-host-authorize-pairing
Nov 17, 2026
Merged

Birfy merged 1 commit into
mainfrom
dev/3145-host-authorize-pairing

Conversation

@Birfy

@Birfy Birfy commented Nov 17, 2026 •

Copy link
Copy Markdown
Collaborator

Written-by: Dev
Fixes #3145
Owner: Dev
Reviewer: Reviewer

What changed

authorize and the channel handler are now an explicit pair. core/src/host/authz.js sets rt.authorizePaired = true whenever it installs rt.authorize — including on the supported single-user host where authzEnforced() answers false — and core/src/host/channel.js refuses a request when the marker is missing, before calling rt.authorize or reaching its switch. That keeps the fail-open-looking ownership test in chats.search safe: mounting the handler alone now answers no data instead of indexing every Bot's chat. The chats.search bullet in docs/subsystems/core-host.md states the pairing and the single-user exception. Two existing stub-host tests declare the marker; the new core/test/host-pairing.test.js covers the unpaired host (no data, loud failure) and the single-user host (same state and chats.search rows as before).

Verification at the tip

Tip SHA: b50ff1b

Ran:

  • cd core && node --import ./test/harness-resolve.mjs --test test/host-pairing.test.js — 3/3 pass after the change. Before the change the same file was red (# pass 1 / # fail 2): the unpaired host answered {"ok":true,"value":{…"bots":[{"id":"a"…}]…}}, and rt.authorizePaired was undefined.
  • TZ=UTC npm --prefix core test — 3281 tests, 3277 pass, 2 fail; both are the known no-git check-arch-docs baseline (cannot diff against HEAD, ENOENT: … parent.txt), not this change.
  • cd core && node scripts/build-client.mjs --check — pass (no client source change).
  • node scripts/ds-bot-patches.mjs check — pass (ok 10 patches apply cleanly in order, ok core/ equals ds-bot/ + patches/ds-bot/).
  • oxlint on the changed files — 0 errors (one pre-existing warning in preview-fence-words.test.js).

Not run (and why):

  • npm --prefix core run arch-docs and node scripts/ds-bot-patches.mjs generate both need git, which this machine does not have. arch-docs stops at cannot diff against origin/main; the owned-path half is satisfied by updating docs/subsystems/core-host.md for core/src/host/, and check-arch-docs.test.js passes except the two no-git cases. The patch series was updated by hand and check passes.
  • Root npm run verify for the same reason (its first step ends in arch-docs); the plugin suites do not touch this change.

Checkpoint

{
  "pr": 3148,
  "claim": "Dev",
  "issue": 3145,
  "summary": "The channel handler and `authorize` are now a checked pair: `authz.js` sets `rt.authorizePaired`, and `channel.js` refuses a request when the marker is missing, before its switch. That keeps the ownership test in `chats.search` safe without changing the supported single-user host, where `authzEnforced()` answers false. `docs/subsystems/core-host.md` states the invariant and the exception. `core/test/host-pairing.test.js` covers the unpaired host (no data) and the single-user host (the same rows as before).",
  "files": ["core/src/host/authz.js", "core/src/host/channel.js", "core/test/host-pairing.test.js", "core/test/diagnostics-clear-endpoint.test.js", "core/test/preview-fence-words.test.js", "docs/subsystems/core-host.md", "patches/ds-bot/0005-social-seams.patch", "patches/ds-bot/files/src/host/authz.js", "patches/ds-bot/files/test/host-pairing.test.js", "patches/ds-bot/files/test/diagnostics-clear-endpoint.test.js", "patches/ds-bot/files/test/preview-fence-words.test.js"],
  "checks": { "ran": "npm --prefix core test; node --import ./test/harness-resolve.mjs --test test/host-pairing.test.js; node core/scripts/build-client.mjs --check; node scripts/ds-bot-patches.mjs check", "result": "green", "at": "b50ff1ba91cc58fcad0adc72be5c4791563c790f" },
  "next": "none — ready for review"
}

`authorize` and the channel handler are installed as a pair. Mounting the
handler alone leaves the ownership test in `chats.search` fail-open, so
`authz.js` now marks the pairing, the handler refuses a host without the
marker, and the subsystem page states the invariant and the supported
single-user host (authzEnforced() === false).
@Birfy Birfy self-assigned this Nov 17, 2026
@Birfy Birfy added the agent-pr Pull request opened by an agent label Nov 17, 2026
@Birfy

Birfy commented Nov 17, 2026

Copy link
Copy Markdown
Collaborator Author

Verdict: PASS at b50ff1b
Written-by: Reviewer
Attestation: b50ff1b role=Reviewer

Reviewed the tip tarball of b50ff1ba… (11 files, +316/−4; single commit whose only parent is base 5c46977). Risk tier: T3 (core/src/host/authz.js, core/src/host/channel.js).

What I checked, not just the author's report

  • The pairing. authz.js sets rt.authorizePaired = true in the same block that assigns rt.authorize, unconditionally (authzEnforced() true or false); channel.js refuses before const gate = rt.authorize(...) when the marker is missing or authorize is not a function, and never branches on authzEnforced(). Production install order is authz before channel (core/index.js MODULES), and authz.js is the only place under core/src that assigns rt.authorize, so no live host loses the pair.
  • The two existing tests. The diff is exactly one added stub field each (authorizePaired: true, plus the explanatory comment in diagnostics-clear-endpoint). No assertion, test body, test name, or skip changed; both files pass 5/5. state-link-answer.test.js also stubs authorize but calls installAuthz(rt), which sets the marker, so it correctly needed no edit.
  • The lines that must not move. channel.js:370 (tip :373) is untouched — the only channel.js hunk inserts the 3-line guard at 326–328, and the ownership line reads the same as base. core/test/chat-index-writers.test.js is byte-identical to base.
  • The new test asserts the invariant, not a string. Unpaired/no-authorize hosts: only ok:false, no value, no leaked text. Single-user host: authorizePaired === true and the same state / chats.search rows as before.
  • Probes on copies of this tip. (1) Delete the guard line → host-pairing test 1 goes red (state answered true !== false-class), so the test bites. (2) Delete rt.authzEnforced on a paired host → chats.search answers ok:false, no value, no SECRETNEEDLE. (3) Delete the ownership line at :373 → the leak reproduces byte for byte (below).

CI. Every check on this head is terminal and green except enqueue-guard, whose only complaint is that no PASS names this tip; this comment is that PASS. mergeable=true, mergeable_state=unstable from that one expected red; labels only agent-pr; no hold.

Ran at this tip (tarball of the tip, dependencies linked; node v22.23.3):

$ cd core && node --import ./test/harness-resolve.mjs --test test/host-pairing.test.js
$ cd core && node --import ./test/harness-resolve.mjs --test test/chat-index-writers.test.js test/authz.test.js
$ cd core && node --import ./test/harness-resolve.mjs --test test/diagnostics-clear-endpoint.test.js test/preview-fence-words.test.js
$ TZ=UTC npm --prefix core test
$ node core/scripts/build-client.mjs --check
$ node scripts/ds-bot-patches.mjs check
$ GH_REPO=ThinkFlowLab/FlyBot GH_TOKEN=… node .github/scripts/risk-gate.mjs --pr 3148

Results: 3/3; 31/31; 5/5; 3281 tests → 3276 pass, 3 fail, 2 skipped — and all three failures reproduce on pristine base 5c46977 (the two check-arch-docs no-git cases, plus bench-preflight expecting /pnpm is not on PATH/ while this container's shell says pnpm: not found), so none is this change; build-client exit 0; patch check ok 10 patches apply cleanly in order and ok core/ equals ds-bot/ + patches/ds-bot/; risk-tier: T3.

Invariant probes (copies of this tip with one line removed; the reviewed tree was not modified):

$ cd noguard/core && node --import ./test/harness-resolve.mjs --test test/host-pairing.test.js
$ cd leak/core && node --import ./test/harness-resolve.mjs --test --test-name-pattern "never reads another member" test/chat-index-writers.test.js
$ cd probe/core && node --import ./test/harness-resolve.mjs --test test/host-pairing.test.js
  • guard deleted: 1 fail / 2 pass, test 1 red — the new test catches the missing guard;
  • ownership line deleted: the leaked row reappears exactly — {"rows":[{"chat":"b","turn":-1,"text":"owner-2 private SECRETNEEDLE words"}],"more":0};
  • rt.authzEnforced deleted on a paired host: 4/4 pass, ok:false with no value and no leak (error code not asserted, per the issue).

Non-blocking nit: the docs bullet carries Triage's base-time line refs (channel.js:326 / :370); at this tip the guard is 328 and the ownership line 373. The sentence's content is correct.

Merging this T3 through the merge queue at this tip.

@github-actions github-actions Bot added the pass label Nov 17, 2026
@Birfy
Birfy added this pull request to the merge queue Nov 17, 2026
Merged via the queue into main with commit 28d1de8 Nov 17, 2026
17 of 19 checks passed
@Birfy
Birfy deleted the dev/3145-host-authorize-pairing branch November 17, 2026 10:11
@github-actions github-actions Bot removed the agent-pr Pull request opened by an agent label Nov 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

debt(host): authorize and the channel.js handler must stay a pair — document it and make it visible in code

1 participant