Skip to content

Commit fd4dd72

Browse files
committed
fix(fleet): reject backslash archive paths, guard stderr pipes, and validate disk-limit labels in doctor
- restore/backup path rules reject literal backslashes so a tampered entry cannot validate as one path and extract as another on POSIX - fleet logs handles broken pipes on stderr as well as stdout - fleet doctor fails malformed disk-limit labels that would break upgrade/restore replay instead of reporting them as passing
1 parent 815e1d6 commit fd4dd72

4 files changed

Lines changed: 53 additions & 23 deletions

File tree

‎src/fleet/backup.runtime.ts‎

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -398,12 +398,14 @@ async function publishArchive(tempArchivePath: string, archivePath: string): Pro
398398
}
399399

400400
function isAllowedRestorePath(rawPath: string): boolean {
401-
const normalized = path.posix.normalize(rawPath.replaceAll("\\", "/"));
402-
if (
403-
normalized !== rawPath.replaceAll("\\", "/") ||
404-
normalized.startsWith("/") ||
405-
normalized.startsWith("../")
406-
) {
401+
// Fleet archives use POSIX separators only. A literal backslash would
402+
// validate as one path but extract as another on POSIX, so it is rejected
403+
// outright at both backup and restore time.
404+
if (rawPath.includes("\\")) {
405+
return false;
406+
}
407+
const normalized = path.posix.normalize(rawPath);
408+
if (normalized !== rawPath || normalized.startsWith("/") || normalized.startsWith("../")) {
407409
return false;
408410
}
409411
return (

‎src/fleet/containers.runtime.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -574,6 +574,7 @@ const defaultFleetContainerStreamExecutor: FleetContainerStreamExecutor = (
574574
child.kill("SIGTERM");
575575
};
576576
process.stdout.once("error", onTargetError);
577+
process.stderr.once("error", onTargetError);
577578
// Honor target backpressure: pause the child stream while the terminal or
578579
// pipe drains so a noisy follow stream cannot buffer without bound.
579580
const pipeWithBackpressure = (
@@ -595,6 +596,7 @@ const defaultFleetContainerStreamExecutor: FleetContainerStreamExecutor = (
595596
stdout.flush();
596597
stderr.flush();
597598
process.stdout.removeListener("error", onTargetError);
599+
process.stderr.removeListener("error", onTargetError);
598600
resolve({ code, signal });
599601
});
600602
});

‎src/fleet/doctor.runtime.test.ts‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,15 @@ describe("fleet doctor", () => {
220220
inspection.storageOpt = {};
221221
},
222222
],
223+
[
224+
"disk-limit",
225+
"fail",
226+
(inspection: ReturnType<typeof healthyInspection>) => {
227+
// Malformed label would break upgrade/restore replay on any runtime.
228+
inspection.labels["openclaw.fleet.disk-limit"] = "not-a-size";
229+
inspection.storageOpt = { size: "not-a-size" };
230+
},
231+
],
223232
[
224233
"container-running",
225234
"warn",

‎src/fleet/doctor.runtime.ts‎

Lines changed: 34 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
cellNetworkName,
66
cellOwnerId,
77
FLEET_DISK_LIMIT_LABEL,
8+
validateDiskSize,
89
FLEET_GATEWAY_PORT,
910
FLEET_OWNER_LABEL,
1011
FLEET_TENANT_LABEL,
@@ -73,6 +74,36 @@ async function directoryFindings(params: {
7374
}
7475
}
7576

77+
function diskLimitFinding(
78+
runtime: "docker" | "podman",
79+
diskLimit: string,
80+
applied: string | undefined,
81+
): FleetDoctorFinding {
82+
try {
83+
validateDiskSize(diskLimit);
84+
} catch {
85+
return finding(
86+
"disk-limit",
87+
"fail",
88+
`Container disk limit label is malformed and would break upgrade/restore replay: ${diskLimit}.`,
89+
);
90+
}
91+
if (runtime === "docker" && applied !== diskLimit) {
92+
return finding(
93+
"disk-limit",
94+
"fail",
95+
`Container disk limit label is ${diskLimit} but the applied storage option is ${applied ?? "unset"}.`,
96+
);
97+
}
98+
return finding(
99+
"disk-limit",
100+
"pass",
101+
runtime === "docker"
102+
? `Container writable-layer disk limit is ${diskLimit}.`
103+
: `Container writable-layer disk limit was requested as ${diskLimit}; Podman does not expose the applied storage option for verification.`,
104+
);
105+
}
106+
76107
export async function runFleetDoctor(params: {
77108
env: NodeJS.ProcessEnv;
78109
containers: FleetContainerRuntime;
@@ -244,23 +275,9 @@ export async function runFleetDoctor(params: {
244275
const diskLimit = inspection.labels[FLEET_DISK_LIMIT_LABEL];
245276
if (diskLimit !== undefined) {
246277
// Docker reports the applied quota via HostConfig.StorageOpt; Podman's
247-
// inspect schema has no such field, so only the label can be checked there.
248-
const applied = inspection.storageOpt.size;
249-
findings.push(
250-
record.runtime === "docker" && applied !== diskLimit
251-
? finding(
252-
"disk-limit",
253-
"fail",
254-
`Container disk limit label is ${diskLimit} but the applied storage option is ${applied ?? "unset"}.`,
255-
)
256-
: finding(
257-
"disk-limit",
258-
"pass",
259-
record.runtime === "docker"
260-
? `Container writable-layer disk limit is ${diskLimit}.`
261-
: `Container writable-layer disk limit was requested as ${diskLimit}; Podman does not expose the applied storage option for verification.`,
262-
),
263-
);
278+
// inspect schema has no such field, so only the label can be checked
279+
// there. A malformed label would also break upgrade/restore replay.
280+
findings.push(diskLimitFinding(record.runtime, diskLimit, inspection.storageOpt.size));
264281
} else if (inspection.storageOpt.size !== undefined) {
265282
findings.push(
266283
finding(

0 commit comments

Comments
 (0)