fix(session): disable generic broker API by default#332
Conversation
Greptile SummaryThis PR hides the generic broker HTTP surface (
Confidence Score: 4/5Safe to merge; the change is a straightforward route interception with no impact on existing Hunk session paths or the underlying session-broker package. The logic is small and well-tested: the new 404 block sits correctly before any Hunk session path, Host/Origin validation still runs first, and the curated health payload accurately reflects the advertised surface. The only rough edge is that the 404 body is plain text while every other intentional error response in the file returns JSON. No files require special attention beyond the minor body-format inconsistency in Important Files Changed
Sequence DiagramsequenceDiagram
participant Client
participant BunServe as Bun serve (serve.ts)
participant CustomHandler as handleRequest (brokerServer.ts)
participant Daemon as SessionBrokerDaemon
Client->>BunServe: Any request
BunServe->>CustomHandler: validateHost / validateOrigin
alt /health
CustomHandler-->>BunServe: "JSON { ...health (no /broker paths), sessionApi, sessionCapabilities, sessionSocket }"
else /broker or /broker/capabilities (NEW)
CustomHandler-->>BunServe: 404 Not found
else /session-api/capabilities
CustomHandler-->>BunServe: JSON sessionCapabilities()
else /session-api
CustomHandler-->>BunServe: handleSessionApiRequest()
else /mcp
CustomHandler-->>BunServe: 410 tombstone
else undefined (fall-through)
CustomHandler-->>BunServe: undefined
BunServe->>Daemon: daemon.handleRequest()
Daemon-->>BunServe: Response or null
alt /session (WebSocket)
BunServe-->>Client: 101 Upgrade
else unmatched
BunServe-->>Client: 404 Not found
end
end
BunServe-->>Client: Response
Prompt To Fix All With AIFix the following 1 code review issue. Work through them one at a time, proposing concise fixes.
---
### Issue 1 of 1
src/session-broker/brokerServer.ts:458-460
Prefer `jsonError` here to match the JSON error format used by every other intentional error response in this file (including the MCP tombstone), so callers that parse the body don't get an unexpected JSON decode failure.
```suggestion
if (url.pathname === daemon.paths.api || url.pathname === daemon.paths.capabilities) {
return jsonError("Not found.", 404);
}
```
Reviews (1): Last reviewed commit: "fix(session): hide generic broker API" | Re-trigger Greptile |
| if (url.pathname === daemon.paths.api || url.pathname === daemon.paths.capabilities) { | ||
| return new Response("Not found.", { status: 404 }); | ||
| } |
There was a problem hiding this comment.
Prefer
jsonError here to match the JSON error format used by every other intentional error response in this file (including the MCP tombstone), so callers that parse the body don't get an unexpected JSON decode failure.
| if (url.pathname === daemon.paths.api || url.pathname === daemon.paths.capabilities) { | |
| return new Response("Not found.", { status: 404 }); | |
| } | |
| if (url.pathname === daemon.paths.api || url.pathname === daemon.paths.capabilities) { | |
| return jsonError("Not found.", 404); | |
| } |
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/session-broker/brokerServer.ts
Line: 458-460
Comment:
Prefer `jsonError` here to match the JSON error format used by every other intentional error response in this file (including the MCP tombstone), so callers that parse the body don't get an unexpected JSON decode failure.
```suggestion
if (url.pathname === daemon.paths.api || url.pathname === daemon.paths.capabilities) {
return jsonError("Not found.", 404);
}
```
How can I resolve this? If you propose a fix, please make it concise.Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
There was a problem hiding this comment.
The implementation has changed since this comment: Hunk no longer has an explicit /broker rejection branch here. The core broker daemon now leaves the generic HTTP API unregistered by default, so /broker falls through as a normal unknown route instead of being an intentional Hunk JSON error. I also updated the PR description to reflect that opt-in core-library approach.
Responded by Pi using OpenAI GPT-5.
0b813fc to
c943274
Compare
ececb28 to
ca03ebc
Compare
ca03ebc to
9f8d923
Compare
#332 made the generic broker HTTP API opt-in (exposeHttpApi). The new body-size-limit test must enable it to reach the 413 path. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Summary
@hunk/session-brokerdaemon so the generic/brokerand/broker/capabilitiesHTTP API is disabled by default.exposeHttpApi: trueopt-in for package consumers that intentionally want the genericlist/get/dispatchHTTP surface./health,/session, and Hunk-specific/session-apiroutes.Why
This makes the safer behavior the library default: Hunk no longer has to explicitly block
/broker, and future daemon users only expose the raw broker API when they ask for it.Tests
bun test src/session-broker/brokerServer.test.ts packages/session-broker/src/daemon.test.ts packages/session-broker-bun/src/serve.test.ts packages/session-broker-node/src/serve.test.tsbun run format:checkbun run typecheckbun run lintbun test ./test/session ./src/session ./src/hunk-session ./src/session-brokerhunk session list/context/commentplus/brokerreturning 404This PR description was generated by Pi using OpenAI GPT-5