Repository navigation
fix(mattermost): bound null-body error response reads - #97851
vincentkoc merged 1 commit into
Conversation
|
Codex review: needs maintainer review before merge. Reviewed June 29, 2026, 12:16 PM ET / 16:16 UTC. Summary PR surface: Source -10, Tests +56. Total +46 across 2 files. Reproducibility: yes. source-reproducible: current main calls Review metrics: none identified. Stored data model Root-cause cluster Members:
Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything. Merge readiness Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch. Next step before merge
Security Review detailsBest possible solution: Land this narrow branch through the existing automerge or maintainer gates so current main returns to one bounded Mattermost error-reader path. Do we have a high-confidence way to reproduce the issue? Yes, source-reproducible: current main calls Is this the best way to solve the issue? Yes. Removing the null-body special case is the narrowest maintainable fix because it reuses the existing bounded reader and avoids adding a second catch-or-buffering path. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against 6de357ad4772. Label changesLabel changes:
Label justifications:
Evidence reviewedPR surface: Source -10, Tests +56. Total +46 across 2 files. View PR surface stats
What I checked:
Likely related people:
What the crustacean ranks mean
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics. How this review workflow works
|
|
@clawsweeper automerge |
|
🦞🧹
Draft PRs stay fix-only until GitHub marks them ready for review. Pause with Automerge progress:
|
|
🦞✅ Source: Why human review is needed: What the maintainer can do as a next step: I added |
Co-authored-by: Pick-cat <[email protected]>
Co-authored-by: Pick-cat <[email protected]>
Co-authored-by: Pick-cat <[email protected]> (cherry picked from commit 54d2fa2)
Co-authored-by: Pick-cat <[email protected]> (cherry picked from commit 54d2fa2)
What Problem This Solves
readMattermostError()had a!res.bodyfallback that bypassed the bounded reader and called nativeres.json()/res.text()directly. For a null-body error response with a JSON content-type (a 401/503 withcontent-type: application/jsonand an empty body — common from reverse proxies and gateways),await res.json()throwsSyntaxError: Unexpected end of JSON input. That rejection propagates out ofreadMattermostError(), so the caller's intendedMattermost API <status>: unknown erroris replaced by a confusing JSON-parse crash. It was also the last remaining unboundedjson()/text()read in this error path after #96033 bounded the success path.Affected surface:
extensions/mattermost/src/mattermost/client.ts—readMattermostError(), reached byclient.request(), the file-upload path, andprobe.ts.Why This Change Was Made
The
!res.bodyspecial-case is removed entirely, so every error read goes through the existing boundedreadResponseTextLimited(8 KiB) and the JSONmessageis parsed from that bounded text.readResponseTextLimitedreturns""when there is no readable body, so a null-body response now yields an empty detail instead of throwing — and all three callers already coalesce that to a clean message (detail || "unknown error"/detail || res.statusText). One canonical read path, no second buffering strategy.Net change is a deletion (
client.ts+0/−10): removes the divergent branch rather than adding code.User Impact
Operators and agents talking to self-hosted or misbehaving Mattermost servers get a clean, accurate API error (
Mattermost API 503 Service Unavailable: unknown error) on null-body JSON error responses, instead of an internalUnexpected end of JSON inputcrash — and every error read now goes through the bounded reader.Evidence
1. Real-behavior proof with a negative control (real HTTP). A harness drives the real exported
readMattermostErrorand the realcreateMattermostClient().request()(through the realfetchWithSsrFGuardSSRF path,allowPrivateNetwork: truefor localhost) against a realnode:httpserver returning503 Service Unavailablewithcontent-type: application/jsonand no body. The negative control runs the deleted branch's exact logic (await res.json()) on the same response.Without the fix the null-body JSON error path throws
SyntaxError: Unexpected end of JSON input; with the fixreadMattermostErrorreturns""and the client surfaces the clean... 503 Service Unavailable: unknown error.2. Committed regression tests (
extensions/mattermost/src/mattermost/client.test.ts) cover: null-body JSON errors never callresponse.json()/response.text(); bounded JSONmessagefields still parse from normal bodies; and a guarded null-body failure surfaced end-to-end throughcreateMattermostClient().request().3. Lint on the changed file:
What was NOT tested: I did not run against a live production Mattermost server. The null-body JSON error condition is reproduced with a real local HTTP server over the real SSRF-guarded fetch path, including the negative control showing the pre-fix crash.
AI-assisted: implementation, tests, and the proof harness were drafted with agent assistance; all commands above were run locally.