mirror of
https://github.com/morluto/rea.git
synced 2026-11-18 04:34:13 +00:00
* refactor(browser): take the host in Chromium, Electron and capture adapters chromiumSandboxEnabled and safeElectronEnvironment take a required platform. The scenario browser, native module resolver, Electron provider and capture cleanup, mitmproxy adapter and web script artifacts take an optional platform seam (default HOST_PLATFORM); Electron fuses read the host architecture from HOST_PLATFORM. Their tests inject the platform instead of redefining process.platform. src/browser no longer reads process.platform or process.arch. * refactor(pcap): take the host platform in the packet tools, native bound and batch launch (#11141) * refactor(pcap): take the host platform in the packet tools, native bound and batch launch * test(pcap): cover the selected host in batch launch and capture-host support * refactor(apktool): take the host platform in launcher selection, version probe and decode (#11164) * refactor(apktool): take the host platform in launcher selection, version probe and decode * test(apktool): cover the provider's selected host in launcher selection * refactor(hopper): give the launcher the provider's host platform * refactor(native): inject the host into the pwntools decoders and native capability defaults (#11173) * refactor(native): inject the host into the pwntools decoders and native capability defaults * fix(native): give composed pwntools services the capability host and drop empty test hooks * refactor(adb): take the host platform in binary selection and pulled file names (#11176) * refactor(adb): take the host platform in binary selection and pulled file names * refactor(cli): pass the resolved host platform through rea mcp add (#11179) * refactor(cli): pass the resolved host platform through rea mcp add * refactor(composition): default composition entry points to HOST_PLATFORM and pass it to Hopper and IDA (#11183) * refactor(kuna): require the host platform in admission and installation, and give it to the session client (#11186) * refactor(kuna): require the host platform in admission and installation, and give it to the session client * fix(kuna): pass the host platform from the JavaScript installation callers verify-real-kuna, both native oracle helpers and the command-lifetime child script call inspectKunaInstallation from dist, where TypeScript cannot see the now-required platform. They passed undefined and got unsupported_host on supported hosts. * refactor(server): give createServer a host option and pass it to session tools, sigrok and EVM (#11203) * refactor(server): give createServer a host option and pass it to session tools, sigrok and EVM createServer read process.platform and process.arch live for its capability services, and registerSessionTools read process.platform for process capture. A host option (default HOST_PLATFORM) now selects both, and composition passes the capability host to the sigrok provider and the EVM provider (execution gate, limiter probe and environment rules), as it does for pwntools. hostRestrictedAvailabilityMcp selects its host through the option instead of redefining process.platform and process.arch, and moves to the MCP boundary lane since it no longer touches process-global state. evmCleanupRetry passes SIMULATED_LINUX_X64 to the provider instead of 52 property redefinitions; the fixture moves to tests/fixtures/simulatedHost.ts. * refactor(desktop): require the host platform in build computer and secret folder paths (#11210) * refactor(desktop): require the host platform in build computer and secret folder paths buildComputerArchiveDirectory, defaultBuildComputerArchive, resolveBuildComputerEnvironment and buildSecretsDirectory defaulted to process.platform. Every caller but DesktopBuildComputers' secret folder already passed the platform; it now passes HOST_PLATFORM.platform, which it reads for the build environment. * refactor(filesystem): default caller paths and ChangeTime settling to HOST_PLATFORM (#11212) appendCallerPath, absoluteCallerPath and the ChangeTime settle seams defaulted to a live process.platform read. Their defaults now come from HOST_PLATFORM: the 59 callers that omit the platform join or settle paths they open on this host, and callers describing another host's layout already pass it. The webScriptExport case that redefined process.platform to reach the Windows settle budget moves to its own file, which selects Windows by mocking HostPlatform. * fix(server): report process capture availability for the server's host sessionAvailabilityPolicy imported platform from node:process, so with a selected host binary_session reported capture_process_scenario from the running host while planning and capture used the selected one. It takes the platform from createServer and registerSessionTools. hostRestrictedAvailabilityMcp checks discovery against a dry-run plan on win32 and linux hosts. * build(guards): count platform and arch imports from node:process and node:os as ambient host reads sessionAvailabilityPolicy's named import of platform from node:process escaped the ambient-host-platform guard. The guards now also match named platform/arch imports from node:process or node:os and os.platform()/os.arch(). The one other site, DesktopApplicationCapture's os.arch(), records the capturing host and now reads HOST_PLATFORM.architecture. * refactor(config): take the host platform in parseConfig and give debugger managers the capability host (#11237) * refactor(config): take the host platform in parseConfig and give debugger managers the capability host parseConfig read process.platform for the default Hopper launcher; it takes the platform (default HOST_PLATFORM). GdbSessionManager and RizinDebugSessionManager default their platform to HOST_PLATFORM, and composition passes the capability host that already decides their availability. GDB's /proc descriptor check reads HOST_PLATFORM explicitly: it inspects this host's /proc whatever host the manager models. * refactor(firmware): give the firmware and Wakaru providers the capability host (#11239) * refactor(firmware): give the firmware and Wakaru providers the capability host resolveFirmwareCommand and resolveWakaruCommand read process.platform (and process.arch) for their host gate. They take the platform or host as a parameter; FirmwareProvider and WakaruProvider take a host (default HOST_PLATFORM) for the gate and their environment snapshots, and composition passes the capability host that already decides their availability. The JavaScript analysis source transfer defaults to HOST_PLATFORM. artifactSelectedCommand passes SIMULATED_LINUX_X64 to both providers instead of redefining process.platform and process.arch, and the Wakaru limiter configuration cases now run on any POSIX host. * refactor(captures): give tshark the capability host and default Cutter to HOST_PLATFORM (#11240) * refactor(captures): give tshark the capability host and default Cutter to HOST_PLATFORM TsharkCaptureProvider and CutterBridgeClient defaulted their platform to process.platform. Both default to HOST_PLATFORM now, and composition passes the capability host to the packet capture service, which already decides its availability. * refactor(platform): read HOST_PLATFORM explicitly in host-only path checks (#11241) * refactor(platform): read HOST_PLATFORM explicitly in host-only path checks Electron's readlink target split, IDA's host path comparison, the inspector's reported runtime path, the server identity check and WABT's executable names all describe paths on the running host. They read HOST_PLATFORM instead of process.platform. * test(native): select the native UI verifier's host through HostPlatform (#11242) verify-native-ui.mjs reads its macOS requirement from HOST_PLATFORM, and its action test resolves the script's HostPlatform import to a simulated darwin host instead of redefining process.platform in the child preload. Simulating linux there fails the macOS requirement, so the redirect is effective. * test(mcp): check that composition forwards the selected host to execution hostRestrictedAvailabilityMcp ran execution only on darwin, where the runner's own host also refuses. The new case calls the firmware, Wakaru, tshark, sigrok and EVM tools under a darwin and a linux x64 host and requires different outcomes, so dropping a provider's host forwarding fails on any runner (checked by removing the firmware forwarding). * fix(composition): give the pcap, Apktool and ADB providers the capability host createServer's selected host decided pcap capture discovery, but the default pcap, Apktool and ADB factories built their providers with HOST_PLATFORM. The factories take the platform (default HOST_PLATFORM) and capabilityServices passes its context platform, so availability and execution follow one host. * test: import moved resources owners in host-platform fixtures * refactor(config): drop the unused host parameter from parseConfig
386 lines
13 KiB
TypeScript
386 lines
13 KiB
TypeScript
import { HOST_PLATFORM } from "../platform/HostPlatform.js";
|
|
import { decodeStrictUtf8 } from "../domain/strictUtf8.js";
|
|
import { assertArtifactReadActive } from "../resources/index.js";
|
|
import type { BigIntStats } from "node:fs";
|
|
import { lstat, readlink } from "node:fs/promises";
|
|
import { basename, dirname, isAbsolute, sep } from "node:path";
|
|
|
|
import { isPathWithinRoot } from "../domain/localPath.js";
|
|
|
|
const FRAMEWORK_NAME = "Electron Framework.framework";
|
|
const BINARY_NAME = "Electron Framework";
|
|
const MAX_SYMLINK_HOPS = 32;
|
|
|
|
/** Filesystem facts owned by path admission and consumed unchanged by the reader. */
|
|
export interface ElectronFusePathNode {
|
|
readonly path: string;
|
|
readonly metadata: BigIntStats;
|
|
}
|
|
export interface ResolvedElectronFuseFile {
|
|
readonly path: string;
|
|
readonly metadata: BigIntStats;
|
|
readonly nodes: readonly ElectronFusePathNode[];
|
|
}
|
|
export interface ResolvedElectronFuseTarget {
|
|
readonly selectedPath: string;
|
|
readonly file: ResolvedElectronFuseFile;
|
|
}
|
|
|
|
/** A selected path is not an admitted Electron bundle or regular file. */
|
|
export class ElectronFusePathFailure extends Error {
|
|
constructor(
|
|
readonly reason: "invalid_value" | "invalid_format",
|
|
message: string,
|
|
) {
|
|
super(message);
|
|
this.name = "ElectronFusePathFailure";
|
|
}
|
|
}
|
|
|
|
type WalkResult =
|
|
| ({ readonly kind: "file" } & ResolvedElectronFuseFile)
|
|
| { readonly kind: "absent" | "escapes" | "not-file" | "loop" };
|
|
|
|
/**
|
|
* Admit a regular executable, a macOS app bundle, or an Electron Framework
|
|
* binary reached through `Versions/Current` without leaving the framework.
|
|
*/
|
|
export const resolveElectronFuseTarget = async (
|
|
selectedPath: string,
|
|
signal?: AbortSignal,
|
|
): Promise<ResolvedElectronFuseTarget> => {
|
|
assertArtifactReadActive(signal);
|
|
const metadata = await lstat(selectedPath, { bigint: true });
|
|
let file: ResolvedElectronFuseFile;
|
|
if (metadata.isSymbolicLink())
|
|
file = await resolveFrameworkSymlink(selectedPath, signal);
|
|
else if (metadata.isFile())
|
|
file =
|
|
frameworkRootOf(selectedPath) === null
|
|
? { path: selectedPath, metadata, nodes: [] }
|
|
: await resolveFrameworkSymlink(selectedPath, signal);
|
|
else if (metadata.isDirectory()) {
|
|
file = await resolveBundleBinary(selectedPath, signal);
|
|
file = {
|
|
...file,
|
|
nodes: [{ path: selectedPath, metadata }, ...file.nodes],
|
|
};
|
|
} else
|
|
throw new ElectronFusePathFailure(
|
|
"invalid_format",
|
|
`Expected a regular file or Electron app bundle: ${selectedPath}`,
|
|
);
|
|
return { selectedPath, file };
|
|
};
|
|
|
|
const resolveFrameworkSymlink = async (
|
|
selectedPath: string,
|
|
signal?: AbortSignal,
|
|
): Promise<ResolvedElectronFuseFile> => {
|
|
const root = frameworkRootOf(selectedPath);
|
|
if (root === null)
|
|
throw new ElectronFusePathFailure(
|
|
"invalid_format",
|
|
`Expected a regular file without a symlink: ${selectedPath}`,
|
|
);
|
|
const nodes = await requireFrameworkRoot(root, selectedPath);
|
|
const relativePath = relativeInside(root, selectedPath);
|
|
if (relativePath === null)
|
|
throw new ElectronFusePathFailure(
|
|
"invalid_value",
|
|
`Framework symlink escapes ${FRAMEWORK_NAME}: ${selectedPath}`,
|
|
);
|
|
return requireFile(
|
|
await resolveInside(root, relativePath, signal),
|
|
selectedPath,
|
|
nodes,
|
|
);
|
|
};
|
|
|
|
const resolveBundleBinary = async (
|
|
selectedPath: string,
|
|
signal?: AbortSignal,
|
|
): Promise<ResolvedElectronFuseFile> => {
|
|
const directory = await resolveDirectorySuffix(selectedPath, signal);
|
|
const name = basename(directory.path);
|
|
let file: ResolvedElectronFuseFile;
|
|
if (name === FRAMEWORK_NAME)
|
|
file = await resolveKnownBinary(directory.path, selectedPath, signal);
|
|
else if (name.endsWith(".app"))
|
|
file = await resolveKnownBinary(
|
|
appendPath(directory.path, "Contents", "Frameworks", FRAMEWORK_NAME),
|
|
selectedPath,
|
|
signal,
|
|
);
|
|
else
|
|
throw new ElectronFusePathFailure(
|
|
"invalid_format",
|
|
`Expected an Electron .app bundle, ${FRAMEWORK_NAME} directory, or executable file: ${selectedPath}`,
|
|
);
|
|
return { ...file, nodes: [...directory.nodes, ...file.nodes] };
|
|
};
|
|
|
|
/** Reduce directory suffixes only when doing so preserves filesystem selection. */
|
|
const resolveDirectorySuffix = async (
|
|
selectedPath: string,
|
|
signal?: AbortSignal,
|
|
): Promise<{
|
|
readonly path: string;
|
|
readonly nodes: readonly ElectronFusePathNode[];
|
|
}> => {
|
|
let path = selectedPath;
|
|
const pending: string[] = [];
|
|
const nodes: ElectronFusePathNode[] = [];
|
|
while (true) {
|
|
assertArtifactReadActive(signal);
|
|
const name = basename(path);
|
|
// lstat("link/") follows a link; inspect the named component itself.
|
|
if (name !== "") while (path.endsWith(sep)) path = path.slice(0, -1);
|
|
if (name === "." || name === "..") {
|
|
pending.push(name);
|
|
path = dirname(path);
|
|
continue;
|
|
}
|
|
const component = pending.pop();
|
|
if (component === undefined) return { path, nodes };
|
|
if (component === ".") continue;
|
|
const metadata = await lstat(path, { bigint: true });
|
|
if (!metadata.isDirectory() || metadata.isSymbolicLink())
|
|
throw new ElectronFusePathFailure(
|
|
"invalid_value",
|
|
`A bundle path ending in '..' requires a real directory before each parent segment: ${selectedPath}`,
|
|
);
|
|
nodes.push({ path, metadata });
|
|
path = dirname(path);
|
|
}
|
|
};
|
|
|
|
/** `root` is the framework directory for both an `.app` and a framework selection. */
|
|
const resolveKnownBinary = async (
|
|
root: string,
|
|
bundle: string,
|
|
signal: AbortSignal | undefined,
|
|
): Promise<ResolvedElectronFuseFile> => {
|
|
const nodes = await requireFrameworkRoot(root, bundle);
|
|
for (const candidate of [
|
|
BINARY_NAME,
|
|
`Versions/Current/${BINARY_NAME}`,
|
|
`Versions/A/${BINARY_NAME}`,
|
|
]) {
|
|
const selected = await resolveInside(root, candidate, signal);
|
|
if (selected.kind === "file") return requireFile(selected, bundle, nodes);
|
|
if (selected.kind !== "absent")
|
|
throw pathWalkFailure(selected.kind, bundle);
|
|
}
|
|
throw new ElectronFusePathFailure(
|
|
"invalid_value",
|
|
`Electron Framework binary was not found inside ${bundle}.`,
|
|
);
|
|
};
|
|
|
|
const resolveInside = async (
|
|
root: string,
|
|
relativePath: string,
|
|
signal?: AbortSignal,
|
|
): Promise<WalkResult> => {
|
|
const pending = relativePath.split("/").filter((segment) => segment !== "");
|
|
const resolved: string[] = [];
|
|
const nodes: ElectronFusePathNode[] = [];
|
|
let fileMetadata: BigIntStats | undefined;
|
|
let hops = 0;
|
|
let last: "file" | "directory" | undefined;
|
|
while (pending.length > 0) {
|
|
assertArtifactReadActive(signal);
|
|
const segment = pending.shift() ?? "";
|
|
if (segment === ".") continue;
|
|
if (segment === "..") {
|
|
if (resolved.length === 0) return { kind: "escapes" };
|
|
resolved.pop();
|
|
last = "directory";
|
|
continue;
|
|
}
|
|
const absolute = appendPath(root, ...resolved, segment);
|
|
if (!isPathWithinRoot(root, absolute)) return { kind: "escapes" };
|
|
let metadata;
|
|
try {
|
|
metadata = await lstat(absolute, { bigint: true });
|
|
} catch (cause: unknown) {
|
|
if (isMissing(cause)) return { kind: "absent" };
|
|
throw cause;
|
|
}
|
|
if (metadata.isSymbolicLink()) {
|
|
nodes.push({ path: absolute, metadata });
|
|
hops += 1;
|
|
if (hops > MAX_SYMLINK_HOPS) return { kind: "loop" };
|
|
const rawTarget = await readlink(absolute, { encoding: "buffer" });
|
|
let target: string;
|
|
try {
|
|
// A replacement character can alias a different, valid sibling name.
|
|
// Preserve a literal UTF-8 BOM too: it is part of a filesystem name.
|
|
target = decodeStrictUtf8(rawTarget, "preserve");
|
|
} catch {
|
|
throw new ElectronFusePathFailure(
|
|
"invalid_value",
|
|
`Framework symlink target is not valid UTF-8 (raw target bytes: ${rawTarget.toString("hex")}): ${absolute}`,
|
|
);
|
|
}
|
|
// Lexical only: another alias of this root (/tmp vs /private/tmp)
|
|
// is still an escape. Later hops stay lstat- and containment-checked.
|
|
const absoluteTarget = isAbsolute(target);
|
|
const relativeTarget = absoluteTarget
|
|
? relativeInside(root, target)
|
|
: target;
|
|
if (relativeTarget === null) return { kind: "escapes" };
|
|
if (absoluteTarget) resolved.length = 0;
|
|
pending.unshift(...symlinkTargetSegments(relativeTarget));
|
|
continue;
|
|
}
|
|
if (metadata.isDirectory()) {
|
|
nodes.push({ path: absolute, metadata });
|
|
resolved.push(segment);
|
|
last = "directory";
|
|
continue;
|
|
}
|
|
if (!metadata.isFile() || pending.length > 0) return { kind: "not-file" };
|
|
resolved.push(segment);
|
|
fileMetadata = metadata;
|
|
last = "file";
|
|
}
|
|
if (last !== "file" || fileMetadata === undefined)
|
|
return { kind: "not-file" };
|
|
const path = appendPath(root, ...resolved);
|
|
return isPathWithinRoot(root, path)
|
|
? { kind: "file", path, metadata: fileMetadata, nodes }
|
|
: { kind: "escapes" };
|
|
};
|
|
|
|
/** Validate the app-parent chain equally for app, framework, and binary selection. */
|
|
const requireFrameworkRoot = async (
|
|
root: string,
|
|
selectedPath: string,
|
|
): Promise<readonly ElectronFusePathNode[]> => {
|
|
const frameworks = dirname(root);
|
|
const contents = dirname(frameworks);
|
|
const app = dirname(contents);
|
|
if (
|
|
basename(frameworks) === "Frameworks" &&
|
|
basename(contents) === "Contents" &&
|
|
basename(app).endsWith(".app")
|
|
)
|
|
return requireRealDirectories(
|
|
dirname(app),
|
|
[basename(app), "Contents", "Frameworks", FRAMEWORK_NAME],
|
|
selectedPath,
|
|
);
|
|
else
|
|
return requireRealDirectories(
|
|
dirname(root),
|
|
[basename(root)],
|
|
selectedPath,
|
|
);
|
|
};
|
|
|
|
/**
|
|
* Each named directory below `anchor` must be a real directory, so the
|
|
* framework root cannot redirect the walk outside the selected bundle.
|
|
*/
|
|
const requireRealDirectories = async (
|
|
anchor: string,
|
|
segments: readonly string[],
|
|
selectedPath: string,
|
|
): Promise<readonly ElectronFusePathNode[]> => {
|
|
let current = anchor;
|
|
const nodes: ElectronFusePathNode[] = [];
|
|
for (const segment of segments) {
|
|
current = appendPath(current, segment);
|
|
let metadata;
|
|
try {
|
|
metadata = await lstat(current, { bigint: true });
|
|
} catch (cause: unknown) {
|
|
if (isMissing(cause))
|
|
throw new ElectronFusePathFailure(
|
|
"invalid_value",
|
|
`Electron Framework binary was not found inside ${selectedPath}.`,
|
|
);
|
|
throw cause;
|
|
}
|
|
nodes.push({ path: current, metadata });
|
|
if (metadata.isSymbolicLink())
|
|
throw pathWalkFailure("escapes", selectedPath);
|
|
if (!metadata.isDirectory())
|
|
throw pathWalkFailure("not-file", selectedPath);
|
|
}
|
|
return nodes;
|
|
};
|
|
|
|
const requireFile = (
|
|
walk: WalkResult,
|
|
selectedPath: string,
|
|
nodes: readonly ElectronFusePathNode[],
|
|
): ResolvedElectronFuseFile => {
|
|
if (walk.kind === "file")
|
|
return {
|
|
path: walk.path,
|
|
metadata: walk.metadata,
|
|
nodes: [...nodes, ...walk.nodes],
|
|
};
|
|
if (walk.kind === "absent")
|
|
throw new ElectronFusePathFailure(
|
|
"invalid_value",
|
|
`Electron Framework symlink target was not found: ${selectedPath}`,
|
|
);
|
|
throw pathWalkFailure(walk.kind, selectedPath);
|
|
};
|
|
|
|
const pathWalkFailure = (
|
|
kind: "escapes" | "not-file" | "loop",
|
|
path: string,
|
|
): ElectronFusePathFailure =>
|
|
new ElectronFusePathFailure(
|
|
"invalid_value",
|
|
kind === "escapes"
|
|
? `Framework symlink escapes ${FRAMEWORK_NAME}: ${path}`
|
|
: kind === "loop"
|
|
? `Framework symlink hop limit exceeded: ${path}`
|
|
: `Electron Framework path is not a regular file: ${path}`,
|
|
);
|
|
|
|
const frameworkRootOf = (path: string): string | null => {
|
|
let current = dirname(path);
|
|
while (basename(current) !== FRAMEWORK_NAME) {
|
|
const parent = dirname(current);
|
|
if (parent === current) return null;
|
|
current = parent;
|
|
}
|
|
return current;
|
|
};
|
|
|
|
const relativeInside = (root: string, path: string): string | null => {
|
|
// Keep dot segments until resolveInside has followed preceding symlinks.
|
|
// Lexical normalization would select a different file for link/../ paths.
|
|
const prefix = root.endsWith(sep) ? root : `${root}${sep}`;
|
|
if (!path.startsWith(prefix)) return null;
|
|
const value = path.slice(prefix.length);
|
|
return value === "" ? null : value.split(sep).join("/");
|
|
};
|
|
|
|
/** Append known components without normalizing a caller-selected parent path. */
|
|
const appendPath = (parent: string, ...segments: readonly string[]): string =>
|
|
`${parent}${parent.endsWith(sep) ? "" : sep}${segments.join(sep)}`;
|
|
|
|
const isMissing = (cause: unknown): boolean =>
|
|
cause instanceof Error &&
|
|
"code" in cause &&
|
|
["ENOENT", "ENOTDIR"].includes(String(cause.code));
|
|
|
|
/**
|
|
* Preserve a link target's terminal separator as a directory requirement.
|
|
* The target came from this host's readlink, so this host's separators apply.
|
|
*/
|
|
const symlinkTargetSegments = (target: string): readonly string[] => {
|
|
const separator = HOST_PLATFORM.platform === "win32" ? /[\\/]/u : /\//u;
|
|
const parts = target.split(separator).filter((part) => part !== "");
|
|
if (separator.test(target.slice(-1))) parts.push(".");
|
|
return parts;
|
|
};
|