Refactor HMAC body handling to use shared request body read/restore helper - #9731
Conversation
There was a problem hiding this comment.
Pull request overview
Consolidates request-body read/restore behavior for HMAC validation and server helpers.
Changes:
- Adds a shared body read/restore helper.
- Refactors HMAC middleware to use it.
- Tests signed GET requests with bodies.
Show a summary per file
| File | Description |
|---|---|
internal/server/http_helpers.go |
Introduces the shared helper while preserving POST-only peeking. |
internal/server/hmac.go |
Replaces duplicated body handling. |
internal/server/hmac_test.go |
Verifies GET bodies remain readable downstream. |
Review details
Tip
Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Files reviewed: 3/3 changed files
- Comments generated: 0
- Review effort level: Medium
🔒 mcpg Read-Only Stress — gVisorSurface coverage: MCP tool calls + proxied CLI (REST) + GraphQL mutations
Overall: PASS Notes:
References: §29780640841 Warning Firewall blocked 1 domainThe following domain was blocked by the firewall during workflow execution:
network:
allowed:
- defaults
- "host.docker.internal"See Network Configuration for more information.
|
🔒 mcpg Read-Only Stress — default AWFSurface coverage: MCP tool calls + proxied CLI (REST) + GraphQL mutations
Overall: PASS Notes:
References: §29780640816 Warning Firewall blocked 1 domainThe following domain was blocked by the firewall during workflow execution:
network:
allowed:
- defaults
- "awmgmcpg"See Network Configuration for more information.
|
🔒 mcpg Read-Only Stress — docker-sbxSurface coverage: MCP tool calls + proxied CLI (REST) + GraphQL mutations
Overall: PASS
References: §29780640771
|
The refactor analysis identified duplicated request body read/restore logic in a security-sensitive path (
hmacMiddleware) and the existing server helper layer. This PR consolidates that logic into a single helper to reduce divergence risk and keep auth-path behavior consistent.Body handling consolidation
readAndRestoreRequestBody(*http.Request) ([]byte, error)ininternal/server/http_helpers.goas the canonical read+restore implementation for request bodies.peekRequestBodyto delegate to the shared helper (retaining its POST-only contract).HMAC middleware simplification
io.ReadAll+io.NopCloserbody handling ininternal/server/hmac.gowith the shared helper.Regression coverage for method/body edge case
GETrequests with bodies to confirm body bytes are still available to downstream handlers after HMAC validation.