fix(infra): cap request body timeouts · openclaw/openclaw@7cd93f8
steipete
·
2026-05-30
·
via Recent Commits to openclaw:main
| Original file line number | Diff line number | Diff line change |
|---|
|
1 | 1 | import { EventEmitter } from "node:events"; |
2 | 2 | import type { IncomingMessage } from "node:http"; |
3 | 3 | import { beforeEach, describe, expect, it, vi } from "vitest"; |
| 4 | +import { MAX_TIMER_TIMEOUT_MS } from "../shared/number-coercion.js"; |
4 | 5 | import { createMockServerResponse } from "../test-utils/mock-http-response.js"; |
5 | 6 | import { |
6 | 7 | installRequestBodyLimitGuard, |
7 | 8 | RequestBodyLimitError, |
8 | 9 | type RequestBodyLimitErrorCode, |
9 | 10 | readJsonBodyWithLimit, |
10 | 11 | readRequestBodyWithLimit, |
| 12 | +testApi, |
11 | 13 | } from "./http-body.js"; |
12 | 14 | |
13 | 15 | type MockIncomingMessage = IncomingMessage & { |
@@ -254,6 +256,18 @@ describe("http body limits", () => {
|
254 | 256 | expect(req["__unhandledDestroyError"]).toBeUndefined(); |
255 | 257 | }); |
256 | 258 | |
| 259 | +it("does not overflow oversized request body timeouts into immediate failures", async () => { |
| 260 | +expect( |
| 261 | +testApi.resolveRequestBodyLimitValues({ |
| 262 | +maxBytes: 128, |
| 263 | +timeoutMs: Number.MAX_SAFE_INTEGER, |
| 264 | +}), |
| 265 | +).toEqual({ |
| 266 | +maxBytes: 128, |
| 267 | +timeoutMs: MAX_TIMER_TIMEOUT_MS, |
| 268 | +}); |
| 269 | +}); |
| 270 | + |
257 | 271 | it("guard clamps invalid maxBytes to one byte", async () => { |
258 | 272 | const { res } = await expectGuardPayloadTooLarge({ |
259 | 273 | chunks: ["ab"], |
|
| Original file line number | Diff line number | Diff line change |
|---|
|
1 | 1 | import type { IncomingMessage, ServerResponse } from "node:http"; |
2 | 2 | import { clearTimeout as clearNodeTimeout, setTimeout as setNodeTimeout } from "node:timers"; |
| 3 | +import { resolveTimerTimeoutMs } from "../shared/number-coercion.js"; |
3 | 4 | import { formatErrorMessage } from "./errors.js"; |
4 | 5 | import { parseStrictNonNegativeInteger } from "./parse-finite-number.js"; |
5 | 6 | |
@@ -101,12 +102,15 @@ function resolveRequestBodyLimitValues(options: {
|
101 | 102 | ? Math.max(1, Math.floor(options.maxBytes)) |
102 | 103 | : 1; |
103 | 104 | const timeoutMs = |
104 | | -typeof options.timeoutMs === "number" && Number.isFinite(options.timeoutMs) |
105 | | - ? Math.max(1, Math.floor(options.timeoutMs)) |
106 | | - : DEFAULT_WEBHOOK_BODY_TIMEOUT_MS; |
| 105 | +options.timeoutMs === undefined |
| 106 | + ? DEFAULT_WEBHOOK_BODY_TIMEOUT_MS |
| 107 | + : resolveTimerTimeoutMs(options.timeoutMs, DEFAULT_WEBHOOK_BODY_TIMEOUT_MS); |
107 | 108 | return { maxBytes, timeoutMs }; |
108 | 109 | } |
109 | 110 | |
| 111 | +export const testApi = { resolveRequestBodyLimitValues }; |
| 112 | +export { testApi as __test__ }; |
| 113 | + |
110 | 114 | function advanceRequestBodyChunk( |
111 | 115 | chunk: Buffer | string, |
112 | 116 | totalBytes: number, |
|
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。