feat(session-broker): authenticate local peers - #932
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub. |
Greptile SummaryThis PR adds signed producer and caller authentication to the reusable session broker, including challenge/proof negotiation, replay-protected caller requests, reconnect ownership, and Node/Bun transport limits. It also adds adapter conformance coverage and CI execution for the real Node adapter.
Confidence Score: 4/5The reconnect-authority loss should be fixed before merging because it can permanently reject a valid reconnect-only producer after stale-session reconciliation. Reconciliation removes the current owner before its close callback can retain reconnect identity, so the next authenticated connection is incorrectly authorized as a new registration; the audit-operation issue is non-blocking but should also be corrected. Files Needing Attention: packages/session-broker/src/daemon.ts Important Files Changed
Sequence DiagramsequenceDiagram
participant Producer
participant Adapter
participant Daemon
participant Authenticator
participant Broker
Producer->>Adapter: hello-init
Adapter->>Daemon: hello-init
Daemon->>Authenticator: issueChallenge
Authenticator-->>Daemon: signed challenge
Daemon-->>Producer: hello-challenge
Producer->>Daemon: hello-proof
Daemon->>Authenticator: verify proof
Authenticator-->>Daemon: signed ack + retained authority
Daemon-->>Producer: hello-ack
Producer->>Daemon: register or reconnect
Daemon->>Broker: registerSession
Broker-->>Daemon: registered
Daemon->>Adapter: markAuthenticated
Prompt To Fix All With AI### Issue 1
packages/session-broker/src/daemon.ts:713-715
**Reconciliation Drops Reconnect Authority**
If a stale session is pruned while its authenticated producer socket remains open, reconciliation removes the owner before closing the socket, so the close callback cannot retain reconnect authority. A producer with only `reconnect` scope is then treated as a fresh registration and rejected, leaving the session unable to reconnect until credentials are reissued.
### Issue 2
packages/session-broker/src/daemon.ts:824
**Audit Records Mislabel Operations**
`handleAuthenticatedControl` always passes `list` to `authenticateRequest`, so authentication failures for dispatches and administrative controls are recorded as failed list operations. This makes security and operational audit records misleading.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.Reviews (1): Last reviewed commit: "feat(session-broker): authenticate local..." | Re-trigger Greptile |
| this.producerOwners.delete(sessionId); | ||
| this.broker.unregisterConnection(owner.brokerPeer); | ||
| owner.connection.close?.(1000, "Session producer authority retired."); |
There was a problem hiding this comment.
Reconciliation Drops Reconnect Authority
If a stale session is pruned while its authenticated producer socket remains open, reconciliation removes the owner before closing the socket, so the close callback cannot retain reconnect authority. A producer with only reconnect scope is then treated as a fresh registration and rejected, leaving the session unable to reconnect until credentials are reissued.
Knowledge Base Used:
Prompt To Fix With AI
This is a comment left during a code review.
Path: packages/session-broker/src/daemon.ts
Line: 713-715
Comment:
**Reconciliation Drops Reconnect Authority**
If a stale session is pruned while its authenticated producer socket remains open, reconciliation removes the owner before closing the socket, so the close callback cannot retain reconnect authority. A producer with only `reconnect` scope is then treated as a fresh registration and rejected, leaving the session unable to reconnect until credentials are reissued.
**Knowledge Base Used:**
- [Broker service and packages](https://app.greptile.com/modem/-/custom-context/knowledge-base/modem-dev/hunk/-/docs/broker-service-and-packages.md)
- [Session management](https://app.greptile.com/modem/-/custom-context/knowledge-base/modem-dev/hunk/-/docs/session-management.md)
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.There was a problem hiding this comment.
Valid. Reconciliation now revalidates the producer grant, retains the active binding before closing a stale owner, and clears the retired transport authentication before close. Revoked grants retain no reconnect authority. Added regression coverage for same-binding reconnect, a different binding, missing reconnect scope, and revocation.
Responded by Pi using gpt-5.6-sol.
This comment was generated by Pi using gpt-5.6-sol
| }, | ||
| ): Promise<Response> { | ||
| return this.handleBoundedControl(request, async (body) => { | ||
| const authenticated = await this.authenticateRequest(request, body, "list"); |
There was a problem hiding this comment.
Audit Records Mislabel Operations
handleAuthenticatedControl always passes list to authenticateRequest, so authentication failures for dispatches and administrative controls are recorded as failed list operations. This makes security and operational audit records misleading.
Prompt To Fix With AI
This is a comment left during a code review.
Path: packages/session-broker/src/daemon.ts
Line: 824
Comment:
**Audit Records Mislabel Operations**
`handleAuthenticatedControl` always passes `list` to `authenticateRequest`, so authentication failures for dispatches and administrative controls are recorded as failed list operations. This makes security and operational audit records misleading.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.There was a problem hiding this comment.
Valid. Authentication intentionally precedes parsing attacker-controlled payloads, so body-selected controls now audit pre-authentication failures as unknown instead of incorrectly claiming list. Routes with known semantics can supply an explicit label; capabilities uses diagnostics. Added coverage for generic, capabilities, and custom authenticated controls.
Responded by Pi using gpt-5.6-sol.
This comment was generated by Pi using gpt-5.6-sol
249bb0f to
9a26e93
Compare
9a26e93 to
e4b283f
Compare
Stack
1 of 3 → #933 → #934. Merge bottom-to-top.
Problem
The reusable session broker accepted local producer and HTTP control claims without cryptographic connection authority, and several transport/resource edge cases could outlive revocation or shutdown.
Approach
This layer does not add Hunk credentials, daemon migration policy, browser-review authority, or install/upgrade acceptance coverage; those follow in #933 and #934.
Verification
bun run typecheckbun run test:session-broker-node— 3 passedbun run deps:checkbun run changeset:statusgit diff --checkKnown limitations
Native Windows owner/DACL and reparse-point validation, plus durable reconnect-key rotation, remain publication gates for the eventual public package.
This PR description was generated by Pi using gpt-5.6-sol