Skip to content

Commit e2b6753

Browse files
committed
fix(qa-lab): bound credential payload reads
1 parent 366ef93 commit e2b6753

2 files changed

Lines changed: 50 additions & 0 deletions

File tree

‎extensions/qa-lab/src/cli.runtime.test.ts‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ vi.mock("./model-selection.runtime.js", () => ({
7575
import { resolveRepoRelativeOutputDir } from "./cli-paths.js";
7676
import {
7777
runQaLabSelfCheckCommand,
78+
runQaCredentialsAddCommand,
7879
runQaDockerBuildImageCommand,
7980
runQaDockerScaffoldCommand,
8081
runQaDockerUpCommand,
@@ -2188,6 +2189,30 @@ describe("qa cli runtime", () => {
21882189
expectWriteContains(stdoutWrite, "QA self-check report: /tmp/failed-report.md");
21892190
});
21902191

2192+
it("rejects oversized credential payload files before broker setup", async () => {
2193+
const previousMaxBytes = process.env.OPENCLAW_QA_CREDENTIAL_PAYLOAD_MAX_BYTES;
2194+
const payloadPath = path.join(suiteArtifactsDir, "oversized-credential.json");
2195+
await fs.writeFile(payloadPath, JSON.stringify({ blob: "x".repeat(64) }), "utf8");
2196+
process.env.OPENCLAW_QA_CREDENTIAL_PAYLOAD_MAX_BYTES = "32";
2197+
2198+
try {
2199+
await expect(
2200+
runQaCredentialsAddCommand({
2201+
kind: "telegram",
2202+
payloadFile: payloadPath,
2203+
}),
2204+
).rejects.toThrow(
2205+
"Payload file exceeds OPENCLAW_QA_CREDENTIAL_PAYLOAD_MAX_BYTES (32 bytes).",
2206+
);
2207+
} finally {
2208+
if (previousMaxBytes === undefined) {
2209+
delete process.env.OPENCLAW_QA_CREDENTIAL_PAYLOAD_MAX_BYTES;
2210+
} else {
2211+
process.env.OPENCLAW_QA_CREDENTIAL_PAYLOAD_MAX_BYTES = previousMaxBytes;
2212+
}
2213+
}
2214+
});
2215+
21912216
it("resolves docker scaffold paths relative to the explicit repo root", async () => {
21922217
await runQaDockerScaffoldCommand({
21932218
repoRoot: "/tmp/openclaw-repo",

‎extensions/qa-lab/src/cli.runtime.ts‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import fs from "node:fs/promises";
33
import path from "node:path";
44
import { formatErrorMessage } from "openclaw/plugin-sdk/error-runtime";
5+
import { parseStrictPositiveInteger } from "openclaw/plugin-sdk/number-runtime";
56
import { uniqueStrings } from "openclaw/plugin-sdk/string-coerce-runtime";
67
import {
78
buildQaAgenticParityComparison,
@@ -90,6 +91,8 @@ import {
9091
} from "./tool-coverage-report.js";
9192

9293
const QA_SUITE_INFRA_RETRY_LIMIT = 1;
94+
const QA_CREDENTIAL_PAYLOAD_MAX_BYTES_ENV = "OPENCLAW_QA_CREDENTIAL_PAYLOAD_MAX_BYTES";
95+
const DEFAULT_QA_CREDENTIAL_PAYLOAD_MAX_BYTES = 64 * 1024 * 1024;
9396
const QA_SUITE_INFRA_RETRY_NETWORK_ERROR_CODES = new Set([
9497
"ECONNRESET",
9598
"ECONNREFUSED",
@@ -543,7 +546,29 @@ async function runInterruptibleServer(label: string, server: InterruptibleServer
543546
await new Promise(() => {});
544547
}
545548

549+
function resolveQaCredentialPayloadFileMaxBytes(env: NodeJS.ProcessEnv = process.env) {
550+
const raw = env[QA_CREDENTIAL_PAYLOAD_MAX_BYTES_ENV]?.trim();
551+
if (!raw) {
552+
return DEFAULT_QA_CREDENTIAL_PAYLOAD_MAX_BYTES;
553+
}
554+
const parsed = parseStrictPositiveInteger(raw);
555+
if (parsed === undefined) {
556+
throw new Error(`${QA_CREDENTIAL_PAYLOAD_MAX_BYTES_ENV} must be a positive integer.`);
557+
}
558+
return parsed;
559+
}
560+
546561
async function readQaCredentialPayloadFile(filePath: string) {
562+
const maxBytes = resolveQaCredentialPayloadFileMaxBytes();
563+
const stat = await fs.stat(filePath);
564+
if (!stat.isFile()) {
565+
throw new Error("Payload file must be a regular JSON file.");
566+
}
567+
if (stat.size > maxBytes) {
568+
throw new Error(
569+
`Payload file exceeds ${QA_CREDENTIAL_PAYLOAD_MAX_BYTES_ENV} (${maxBytes} bytes).`,
570+
);
571+
}
547572
const text = await fs.readFile(filePath, "utf8");
548573
let payload: unknown;
549574
try {

0 commit comments

Comments
 (0)