























@@ -10,6 +10,7 @@ export const securitySensitiveGuardMarker = "<!-- openclaw:security-sensitive-gu
1010export const securitySensitiveChangedLabel = "security-sensitive-changed";
1111export const allowSecuritySensitiveCommand = "/allow-security-sensitive-change";
1212export const GITHUB_ERROR_BODY_MAX_BYTES = 64 * 1024;
13+export const GITHUB_RESPONSE_BODY_MAX_BYTES = 4 * 1024 * 1024;
1314export const GITHUB_API_REQUEST_TIMEOUT_MS = 30_000;
14151516const securityTeamSlug = process.env.OPENCLAW_SECURITY_TEAM_SLUG ?? "openclaw-secops";
@@ -349,10 +350,31 @@ function githubErrorBodyTooLarge(maxBytes) {
349350return new Error(`GitHub error response body exceeded ${maxBytes} bytes`);
350351}
351352352-export async function readBoundedGitHubErrorText(response, maxBytes = GITHUB_ERROR_BODY_MAX_BYTES) {
353+function githubResponseBodyTooLarge(maxBytes) {
354+return new Error(`GitHub response body exceeded ${maxBytes} bytes`);
355+}
356+357+export async function readBoundedGitHubErrorText(
358+response,
359+maxBytes = GITHUB_ERROR_BODY_MAX_BYTES,
360+options = {},
361+) {
353362return await readBoundedResponseText(response, "GitHub error", maxBytes, {
354363createTooLargeError: () => githubErrorBodyTooLarge(maxBytes),
364+ ...options,
365+});
366+}
367+368+export async function readBoundedGitHubJson(
369+response,
370+maxBytes = GITHUB_RESPONSE_BODY_MAX_BYTES,
371+options = {},
372+) {
373+const text = await readBoundedResponseText(response, "GitHub", maxBytes, {
374+createTooLargeError: () => githubResponseBodyTooLarge(maxBytes),
375+ ...options,
355376});
377+return JSON.parse(text);
356378}
357379358380function timeoutError(path, method, timeoutMs) {
@@ -373,6 +395,7 @@ function combineAbortSignals(signals) {
373395export function githubApi(token, options = {}) {
374396const fetchImpl = options.fetchImpl ?? fetch;
375397const timeoutMs = options.timeoutMs ?? GITHUB_API_REQUEST_TIMEOUT_MS;
398+const responseMaxBodyBytes = options.responseMaxBodyBytes ?? GITHUB_RESPONSE_BODY_MAX_BYTES;
376399const baseHeaders = {
377400accept: "application/vnd.github+json",
378401authorization: `Bearer ${token}`,
@@ -402,15 +425,21 @@ export function githubApi(token, options = {}) {
402425if (!response.ok) {
403426let errorText;
404427try {
405-errorText = await readBoundedGitHubErrorText(response);
428+errorText = await readBoundedGitHubErrorText(response, GITHUB_ERROR_BODY_MAX_BYTES, {
429+signal: timeoutController.signal,
430+ timeoutPromise,
431+});
406432} catch (bodyError) {
407433errorText = bodyError instanceof Error ? bodyError.message : String(bodyError);
408434}
409435const error = new Error(`${response.status} ${response.statusText}: ${errorText}`);
410436error.status = response.status;
411437throw error;
412438}
413-return response.json();
439+return await readBoundedGitHubJson(response, responseMaxBodyBytes, {
440+signal: timeoutController.signal,
441+ timeoutPromise,
442+});
414443})();
415444operationPromise.catch(() => {});
416445try {
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。