fix: reject directory paths for the Wakaru limiter and mitmdump

`REA_JAVASCRIPT_PRLIMIT_COMMAND` and `REA_MITMDUMP_COMMAND` were admitted
after an access check alone, which a searchable directory passes. Admission
then succeeded, and the failure surfaced later as a launch-time adapter
error instead of the capability refusal that names the configured path.

Require a regular file, as #751 did for the firmware engine and limiter.
Linux-only tests mirror that change; both checks only run on Linux hosts.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Fazmin
2026-10-11 10:43:48 +08:00
committed by morluto
co-authored by Claude Opus 5.5
parent bd3a9bbbaf
commit a67dbf6a48
4 changed files with 91 additions and 2 deletions
@@ -0,0 +1,47 @@
import { mkdir, symlink, writeFile } from "node:fs/promises";
import { join } from "node:path";
import { expect, it } from "vitest";
import { resolveWakaruCommand } from "../../../src/javascript/recovery/WakaruCommand.js";
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
const linuxX64 = it.skipIf(
process.platform !== "linux" || process.arch !== "x64",
);
linuxX64(
"refuses a directory configured as the Wakaru resource limiter",
async () => {
const root = await createTestTempDirectory("rea-wakaru-limiter-");
const command = join(root, "wakaru");
const limiter = join(root, "prlimit");
await writeFile(command, "#!/bin/sh\n", { mode: 0o700 });
await mkdir(limiter);
await expect(
resolveWakaruCommand({
REA_WAKARU_COMMAND: command,
REA_JAVASCRIPT_PRLIMIT_COMMAND: limiter,
}),
).rejects.toMatchObject({
_tag: "AnalysisCapabilityUnavailableError",
reason: expect.stringContaining(limiter),
});
},
);
linuxX64("allows a symlink to a regular Wakaru resource limiter", async () => {
const root = await createTestTempDirectory("rea-wakaru-limiter-symlink-");
const command = join(root, "wakaru");
const limiter = join(root, "prlimit");
const target = join(root, "prlimit-bin");
await writeFile(command, "#!/bin/sh\n", { mode: 0o700 });
await writeFile(target, "#!/bin/sh\n", { mode: 0o700 });
await symlink(target, limiter);
await expect(
resolveWakaruCommand({
REA_WAKARU_COMMAND: command,
REA_JAVASCRIPT_PRLIMIT_COMMAND: limiter,
}),
).resolves.toMatchObject({ limiter });
});