Files
rea/src/browser/history/MitmproxyCaptureAdapter.ts
T
Kaoru0822andClaude Opus 5.5 170d0bf9e2 fix: name host and tool requirements in optional adapter refusals
Host and tool-configuration refusals from the pwntools, EVMole, firmware,
mitmproxy, Wakaru, LLDB and xcrun adapters carried no userMessage, so CLI
and MCP callers saw the generic "This analysis is unavailable for the
current target. Choose another analysis or target." as both message and
remediation. Choosing another target cannot satisfy a Linux-only profile
or an unset REA_*_COMMAND. The actual requirement appeared only in
details.reason.

Pass each refusal's reason as its userMessage, as the adapters' other
configuration refusals (EVMole limits, JADX, pwndbg) already do.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-09 08:12:25 +00:00

61 lines
2.1 KiB
TypeScript

import { access } from "node:fs/promises";
import { constants } from "node:fs";
import { isAbsolute } from "node:path";
import { fileURLToPath } from "node:url";
import { AnalysisCapabilityUnavailableError } from "../../domain/analysisErrorCore.js";
import type { HistoricalCaptureFormatAdapter } from "./HistoricalCaptureFormatAdapter.js";
import { MITMPROXY_CAPTURE_PROVIDER_IDENTITY } from "./CaptureRelease.js";
const OPERATION = "inspect_web_network_capture";
const MITMDUMP_REQUIREMENT =
"Native capture decoding requires Linux and an absolute REA_MITMDUMP_COMMAND path to caller-supplied mitmdump 12.2.3; HAR needs no external engine.";
/** Native mitmproxy decoding is offline and uses only an explicitly configured Linux tool. */
export class MitmproxyCaptureAdapter implements HistoricalCaptureFormatAdapter {
readonly format = "mitmproxy";
readonly identity = MITMPROXY_CAPTURE_PROVIDER_IDENTITY;
constructor(readonly environment: Readonly<NodeJS.ProcessEnv>) {}
async command(
requestPath: string,
runtimePath: string,
): Promise<{ command: string; arguments: readonly string[] }> {
const command = this.environment.REA_MITMDUMP_COMMAND;
if (
process.platform !== "linux" ||
command === undefined ||
!isAbsolute(command)
)
throw new AnalysisCapabilityUnavailableError(
"mitmproxy",
OPERATION,
MITMDUMP_REQUIREMENT,
{ userMessage: MITMDUMP_REQUIREMENT },
);
try {
await access(command, constants.R_OK | constants.X_OK);
} catch (cause: unknown) {
const reason = `Configured mitmdump executable is unavailable: ${command}.`;
throw new AnalysisCapabilityUnavailableError(
"mitmproxy",
OPERATION,
reason,
{ cause, userMessage: reason },
);
}
return {
command,
arguments: [
"--no-server",
"-q",
"--set",
`confdir=${runtimePath}`,
"--set",
`rea_request_path=${requestPath}`,
"-s",
fileURLToPath(
new URL("../../../bridge/mitmproxy/capture.py", import.meta.url),
),
],
};
}
}