CWE-400
- Location
plugin/dist/client.js:282- Finding
Unbounded Hindsight Write Responses Can Exhaust Gateway Memory ## Remediation Suggestions 1. **Enforce a bounded default centrally.** Make `request()` apply a response-size limit even when a caller does not specify one. Use `readBoundedText()` for every successful response instead of falling back to unrestricted `response.text()`. 2. **Use small limits for write acknowledgements.** Assign explicit, appropriately small response limits to `retain()` and `applyBankDefaults()`. Preserve larger limits only for operations that legitimately return memory content. 3. **Enforce limits while streaming.** Count bytes actually received and cancel the response body immediately when the limit is exceeded. Treat `Content-Length` as an optional early-rejection mechanism, not the sole enforcement control. Checking size after `response.text()` does not prevent excessive allocation. 4. **Retain timeouts as a separate control.** Keep request deadlines and host cancellation signals, but do not treat them as substitutes for byte limits. Limit response size before invoking `JSON.parse()`. 5. **Add regression tests.** Cover oversized retain and bank-setup responses with and without `Content-Length`, chunked responses, incorrect length declarations, and oversized valid JSON. Verify that reading stops at the limit, the body is cancelled, and errors do not include sensitive response content.
- Content
View full analysis
Vulnerability Details
File Location:
plugin/dist/client.js:282–306andplugin/dist/client.js:607–616
Vulnerability Type: CWE-400 — Uncontrolled Resource Consumption
Risk Level: MediumVulnerable Code
The request handler buffers successful responses without a size limit when the caller omits
maxBodyBytes:js let text; if (init.maxBodyBytes === undefined) { text = await response.text(); } else { try { text = await readBoundedText(response, init.maxBodyBytes); } catch (error) { if (error instanceof BodyTooLargeError) { throw new Error(`Hindsight ${operation} failed: response larger than ${init.maxBodyBytes} bytes`, { cause: error }); } throw error; } } // SAFETY: T only names optional fields; every caller type-checks each field before use. return (text ? JSON.parse(text) : {});The retain operation does not supply a response-size limit:
js async retain(bankId, item, options = {}) { await this.request("retain", this.bankUrl(bankId, "/memories"), { method: "POST", body: { items: [item], async: options.async ?? true }, signal: options.signal, }); }Bank setup also omits the limit:
js async applyBankDefaults(bankId, defaults, signal) { const body = {}; if (defaults.retainMission) { body.retain_mission = defaults.retainMission; } if (Object.keys(body).length === 0) { return; } await this.request("bank setup", this.bankUrl(bankId), { method: "PUT", body, signal }); }Technical Analysis
request()applies streaming response limits only when its caller suppliesmaxBodyBytes. Bothretain()andapplyBankDefaults()omit this option, causing successful response bodies to be buffered completely throughresponse.text()and subsequently passed toJSON.parse().A malicious or compromised configured Hindsight backend can therefore return an oversized successful response. Buffer ...[truncated 1989 chars]
