mirror of
https://github.com/morluto/rea.git
synced 2026-11-05 14:26:07 +00:00
* feat(artifacts): make ASAR header admission configurable ASAR header/index admission was a fixed 16 MiB with no override, so operators with large Electron indexes could only extract the archive. REA_ASAR_MAX_HEADER_BYTES now sets it (default 16777216, maximum 268435456). One owner resolves the effective admission for the classification probe, inventory, ASAR reader and Electron file scope, including the Electron header cache budget. Startup and doctor validate the setting; admission refuses an invalid value instead of falling back. Recovery and error details name the effective value and its source. Fixes #6176 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix(artifacts): resolve ASAR header admission from the caller's environment The admission read process.env, so composition roots that select their own environment (createDirectAnalysis, createServer, CLI, optional observation factories) could not raise or lower it, and an ambient value leaked into callers that left it unset. Nothing reads process.env now. ArtifactProvider and extraction resolve the admission from their environment; JavaScript analysis parses it from the environment its server or CLI caller passes and refuses an invalid value; the Electron and V8 providers receive it from their factories. Inventory, nested ASAR readers, classification probes and Electron page authorization carry that one value. A header cached by Electron under a larger admission is refused for a smaller one. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
143 lines
4.9 KiB
TypeScript
143 lines
4.9 KiB
TypeScript
import { Cli, z } from "incur";
|
|
|
|
import {
|
|
listJavaScriptRuntimeTargets,
|
|
observeJavaScriptRuntime,
|
|
} from "./application/javascript/JavaScriptRuntimeObservationService.js";
|
|
import { createJavaScriptRuntimeObservationProvider } from "./composition/javascriptRuntimeObservation.js";
|
|
import { CLI_COMMANDS } from "./cliCommandNames.js";
|
|
import { logCliCommand } from "./cliLogging.js";
|
|
import {
|
|
javascriptRuntimeKindSchema,
|
|
listJavaScriptRuntimeTargetsInputSchema,
|
|
observeJavaScriptRuntimeInputSchema,
|
|
} from "./domain/javascript/javascriptRuntimeObservation.js";
|
|
import { analysisInputErrorFromIssues } from "./domain/inputIssueProjection.js";
|
|
import { projectAnalysisError } from "./domain/analysisErrorProjection.js";
|
|
import { finishAnalysisCommand } from "./cli/finishAnalysisCommand.js";
|
|
import type { JsonValue } from "./domain/jsonValue.js";
|
|
import type { Logger } from "pino";
|
|
import { withCommandCancellation } from "./cli/commandCancellation.js";
|
|
|
|
const observeOptionsSchema = z.object({
|
|
runtimeKind: javascriptRuntimeKindSchema
|
|
.optional()
|
|
.describe(
|
|
"Declared target role; Inspector cannot authenticate the Electron role",
|
|
),
|
|
observationMs: z
|
|
.number()
|
|
.int()
|
|
.min(0)
|
|
.default(100)
|
|
.describe("Observation window in milliseconds"),
|
|
});
|
|
|
|
/** Register CLI equivalents of passive V8 Inspector tools. */
|
|
export const registerJavaScriptRuntimeObservationCommands = (
|
|
cli: ReturnType<typeof Cli.create>,
|
|
logger: Logger,
|
|
environment: Readonly<Record<string, string | undefined>>,
|
|
): void => {
|
|
cli.command(CLI_COMMANDS.listJavaScriptRuntimeTargets, {
|
|
description: "List Node/Electron V8 Inspector targets",
|
|
args: z.object({
|
|
endpoint: z.string().describe("Literal-loopback Inspector endpoint"),
|
|
}),
|
|
run: ({ args }) =>
|
|
withCommandCancellation((signal) =>
|
|
logCliCommand(
|
|
logger,
|
|
CLI_COMMANDS.listJavaScriptRuntimeTargets,
|
|
async () => {
|
|
const context = runtimeContext(environment);
|
|
const input = {
|
|
inspector_endpoint: args.endpoint,
|
|
};
|
|
const parsed =
|
|
listJavaScriptRuntimeTargetsInputSchema.safeParse(input);
|
|
if (!parsed.success)
|
|
return cliError(
|
|
analysisInputErrorFromIssues(
|
|
"list_javascript_runtime_targets",
|
|
parsed.error.issues,
|
|
input,
|
|
),
|
|
);
|
|
return await finishAnalysisCommand(
|
|
() =>
|
|
listJavaScriptRuntimeTargets(context.provider, parsed.data, {
|
|
signal,
|
|
}),
|
|
{ close: () => context.provider.close?.() ?? Promise.resolve() },
|
|
context.provider.identity().id,
|
|
"list_javascript_runtime_targets",
|
|
signal,
|
|
"V8 Inspector resources",
|
|
);
|
|
},
|
|
),
|
|
),
|
|
});
|
|
|
|
cli.command(CLI_COMMANDS.observeJavaScriptRuntime, {
|
|
description: "Passively observe one exact Node/Electron Inspector target",
|
|
args: z.object({
|
|
endpoint: z.string().describe("Literal-loopback Inspector endpoint"),
|
|
targetId: z
|
|
.string()
|
|
.describe("Target from list-javascript-runtime-targets"),
|
|
}),
|
|
options: observeOptionsSchema,
|
|
run: ({ args, options }) =>
|
|
withCommandCancellation((signal) =>
|
|
logCliCommand(
|
|
logger,
|
|
CLI_COMMANDS.observeJavaScriptRuntime,
|
|
async () => {
|
|
const context = runtimeContext(environment);
|
|
const input = {
|
|
inspector_endpoint: args.endpoint,
|
|
target_id: args.targetId,
|
|
runtime_kind: options.runtimeKind,
|
|
observation_ms: options.observationMs,
|
|
};
|
|
const parsed = observeJavaScriptRuntimeInputSchema.safeParse(input);
|
|
if (!parsed.success)
|
|
return cliError(
|
|
analysisInputErrorFromIssues(
|
|
"observe_javascript_runtime",
|
|
parsed.error.issues,
|
|
input,
|
|
),
|
|
);
|
|
return await finishAnalysisCommand(
|
|
() =>
|
|
observeJavaScriptRuntime(context.provider, parsed.data, {
|
|
signal,
|
|
}),
|
|
{ close: () => context.provider.close?.() ?? Promise.resolve() },
|
|
context.provider.identity().id,
|
|
"observe_javascript_runtime",
|
|
signal,
|
|
"V8 Inspector resources",
|
|
);
|
|
},
|
|
),
|
|
),
|
|
});
|
|
};
|
|
|
|
const runtimeContext = (
|
|
environment: Readonly<Record<string, string | undefined>>,
|
|
) => ({
|
|
provider: createJavaScriptRuntimeObservationProvider(environment),
|
|
});
|
|
|
|
const cliError = (
|
|
error: Parameters<typeof projectAnalysisError>[0],
|
|
): JsonValue => ({
|
|
error: "JavaScript runtime observation failed",
|
|
...projectAnalysisError(error),
|
|
});
|