fix: proxy body forwarding and auth for /hooks routes#213
Open
serefyarar wants to merge 1 commit into
Open
Conversation
Two issues prevented the hooks endpoint from working through the proxy: 1. express.json() consumed the request body stream before http-proxy could pipe it to the gateway. Add a proxyReq handler to re-serialize req.body so the gateway receives the full payload. 2. attachGatewayAuthHeader injected the gateway token into the Authorization header for /hooks requests when no Authorization was present, causing the hooks handler to read the wrong credential instead of the hooks-specific X-OpenClaw-Token.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Two issues prevented the OpenClaw hooks endpoint (
/hooks/agent,/hooks/wake) from working through the Express proxy wrapper:Body not forwarded:
express.json()consumes the request body stream beforehttp-proxycan pipe it to the gateway. Added aproxyReqhandler to re-serializereq.bodyso the gateway receives the full payload.Wrong auth token injected:
attachGatewayAuthHeaderinjected the gateway token into theAuthorizationheader for/hooksrequests when noAuthorizationheader was present. The hooks handler readsAuthorizationfirst, so it would compare the gateway token against the hooks token and reject with 401. Skipping the injection for/hooksroutes lets the hooks-specificX-OpenClaw-Tokenheader work correctly.Test plan
POST /hooks/agentwithAuthorization: Bearer <hooks-token>returns200 { ok: true, runId: "..." }POST /hooks/agentwithX-OpenClaw-Token: <hooks-token>returns200 { ok: true, runId: "..." }POST /hooks/wakewith body{ "text": "..." }returns200 { ok: true, mode: "now" }401 Unauthorized