Skip to content

Commit 60d1877

Browse files
cxbAsDevclaude
andcommitted
fix(cli): bound docs search API response reads
Replace raw response.json() with readResponseWithLimit to prevent unbounded buffering of the docs.openclaw.ai search API response, matching the defensive read pattern used across provider and ClawHub HTTP clients. Co-Authored-By: Claude <[email protected]>
1 parent 92c10d4 commit 60d1877

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

src/commands/docs.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
// Implements docs link/search output for `openclaw docs`.
2+
import { readResponseWithLimit } from "@openclaw/media-core/read-response-with-limit";
23
import { formatDocsLink } from "../../packages/terminal-core/src/links.js";
34
import { isRich, theme } from "../../packages/terminal-core/src/theme.js";
45
import { formatCliCommand } from "../cli/command-format.js";
56
import type { RuntimeEnv } from "../runtime.js";
67

78
const SEARCH_API = "https://docs.openclaw.ai/api/search";
89
const SEARCH_TIMEOUT_MS = 30_000;
10+
const DOCS_SEARCH_RESPONSE_MAX_BYTES = 8 * 1024 * 1024;
911

1012
type DocResult = {
1113
title: string;
@@ -75,7 +77,10 @@ async function fetchDocsSearch(query: string): Promise<DocResult[]> {
7577
if (!response.ok) {
7678
throw new Error(`HTTP ${response.status}`);
7779
}
78-
const payload = (await response.json()) as DocsSearchResponse;
80+
const bytes = await readResponseWithLimit(response, DOCS_SEARCH_RESPONSE_MAX_BYTES, {
81+
onOverflow: ({ maxBytes }) => new Error(`Docs search response exceeds ${maxBytes} bytes`),
82+
});
83+
const payload = JSON.parse(new TextDecoder().decode(bytes)) as DocsSearchResponse;
7984
return parseDocsSearchResults(payload.results);
8085
} finally {
8186
clearTimeout(timeout);

0 commit comments

Comments
 (0)