Skip to content

fix(security): enforce 32 MiB response body limit on HTTP client and correct documentation - #4

Open
magqqgq wants to merge 1 commit into
coinbase:mainfrom
magqqgq:magqqgq-patch-1
Open

magqqgq wants to merge 1 commit into
coinbase:mainfrom
magqqgq:magqqgq-patch-1

Conversation

@magqqgq

@magqqgq magqqgq commented Sep 21, 2026

Copy link
Copy Markdown

Description

Remediates an unbounded HTTP response body allocation vulnerability (CWE-770/CWE-400), cleans up invalid package usage documentation, and documents gorilla/websocket close lifecycle behavior in core-go.

Key Changes & Remediations

  • Bounded Response Body Allocation (http.go):

    • Implemented maxResponseBytes = 32 << 20 (32 MiB) cap in makeCall().
    • Wrapped res.Body with io.LimitReader(res.Body, maxResponseBytes+1) to read with an extra byte budget.
    • Replaces unbounded io.ReadAll() allocations with an explicit over-limit error if the payload exceeds 32 MiB, preventing malicious or runaway upstream endpoints from crashing client processes via memory exhaustion.
  • API Documentation Accuracy (README.md, CHANGELOG.md):

    • Replaced the invalid core.NewClient() snippet with accurate documentation detailing exported HTTP helper methods (HttpGet, HttpPost), DialWebSocket, and the RestClient interface.
    • Removed the broken/sunset Go Report Card badge.
    • Added release notes for v0.4.1 in CHANGELOG.md.
  • WebSocket Close Handshake Documentation (ws.go, ws_utils.go):

    • Clarified that gorilla/websocket handles close frames internally and surfaces closures as *CloseError via ReadMessage(), guiding SDK consumers on proper shutdown handling.

Verification

  • Verified compilation and static analysis with go vet ./....
  • Validated all tests passing via go test ./....
  • Verified that HTTP responses exceeding 32 MiB are rejected with the configured error.

…correct documentation

## Description
Remediates an unbounded HTTP response body allocation vulnerability (CWE-770/CWE-400), cleans up invalid package usage documentation, and documents gorilla/websocket close lifecycle behavior in `core-go`.

## Key Changes & Remediations

* **Bounded Response Body Allocation (`http.go`)**:
  - Implemented `maxResponseBytes = 32 << 20` (32 MiB) cap in `makeCall()`.
  - Wrapped `res.Body` with `io.LimitReader(res.Body, maxResponseBytes+1)` to read with an extra byte budget.
  - Replaces unbounded `io.ReadAll()` allocations with an explicit over-limit error if the payload exceeds 32 MiB, preventing malicious or runaway upstream endpoints from crashing client processes via memory exhaustion.

* **API Documentation Accuracy (`README.md`, `CHANGELOG.md`)**:
  - Replaced the invalid `core.NewClient()` snippet with accurate documentation detailing exported HTTP helper methods (`HttpGet`, `HttpPost`), `DialWebSocket`, and the `RestClient` interface.
  - Removed the broken/sunset Go Report Card badge.
  - Added release notes for v0.4.1 in `CHANGELOG.md`.

* **WebSocket Close Handshake Documentation (`ws.go`, `ws_utils.go`)**:
  - Clarified that `gorilla/websocket` handles close frames internally and surfaces closures as `*CloseError` via `ReadMessage()`, guiding SDK consumers on proper shutdown handling.

## Verification
- Verified compilation and static analysis with `go vet ./...`.
- Validated all tests passing via `go test ./...`.
- Verified that HTTP responses exceeding 32 MiB are rejected with the configured error.
@magqqgq
magqqgq requested a review from a team as a code owner September 21, 2026 21:16
@cb-heimdall

Copy link
Copy Markdown

🟡 Heimdall Review Status

Requirement Status More Info
Reviews 🟡 0/1
Denominator calculation
Show calculation
1 if user is bot 0
1 if user is external 0
2 if repo is sensitive 0
From .codeflow.yml 1
Additional review requirements
Show calculation
Max 0
0
From CODEOWNERS 0
Global minimum 0
Max 1
1
1 if commit is unverified 0
Sum 1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants