Files
reverse-engineering-anything/src/composition/optionalObservationProviders.ts
T
Kaoru0822andClaude Opus 5.5 8451b961ad feat(artifacts): make ASAR header admission configurable (#6209)
* 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>
2026-10-21 21:18:22 -07:00

109 lines
3.9 KiB
TypeScript

import { snapshotEnvironment } from "../process/snapshotEnvironment.js";
import type {
OptionalObservationProviders,
OptionalProviderLoadFailure,
OptionalProviderLoadResult,
} from "../application/OptionalObservationProviders.js";
import {
CDP_BROWSER_PROVIDER_IDENTITY,
PLAYWRIGHT_BROWSER_SCENARIO_PROVIDER_IDENTITY,
CDP_ELECTRON_PROVIDER_IDENTITY,
PLAYWRIGHT_ELECTRON_ACTIVE_PROVIDER_IDENTITY,
} from "../browser/providerIdentities.js";
import { V8_INSPECTOR_PROVIDER_IDENTITY } from "../inspector/providerIdentity.js";
import { err, ok, type Result } from "../domain/result.js";
/** Precisely typed startup factories for the five existing observation ports. */
export type OptionalObservationFactories = {
readonly [Port in keyof OptionalObservationProviders]-?: () => Promise<
NonNullable<OptionalObservationProviders[Port]>
>;
};
/** Bind optional provider construction to one caller-selected process environment. */
export const createOptionalObservationFactories = (
selectedEnvironment: Readonly<Record<string, string | undefined>>,
): OptionalObservationFactories => {
const environment = snapshotEnvironment(selectedEnvironment);
return {
browserObservation: async () =>
(
await import("./browserObservation.js")
).createBrowserObservationProvider(),
browserScenarioCapture: async () =>
(await import("./browserScenario.js")).createBrowserScenarioProvider(
environment,
),
electronObservation: async () =>
(
await import("./electronObservation.js")
).createElectronObservationProvider(environment),
electronActiveObservation: async () =>
(await import("./electronScenario.js")).createElectronScenarioProvider(
environment,
),
javascriptRuntimeObservation: async () =>
(
await import("./javascriptRuntimeObservation.js")
).createJavaScriptRuntimeObservationProvider(environment),
};
};
const loadPort = async <Port>(
factory: () => Promise<Port>,
providerId: string,
): Promise<Result<Port, OptionalProviderLoadFailure>> => {
try {
return ok(await factory());
} catch (cause: unknown) {
return err({
providerId,
reason: cause instanceof Error ? cause.message : String(cause),
});
}
};
/** Load each adapter independently, retaining healthy peers and exact failures. */
export const loadOptionalObservationProviders = async (
factories: OptionalObservationFactories,
): Promise<OptionalProviderLoadResult> => {
const [browser, scenario, electron, electronActive, runtime] =
await Promise.all([
loadPort(factories.browserObservation, CDP_BROWSER_PROVIDER_IDENTITY.id),
loadPort(
factories.browserScenarioCapture,
PLAYWRIGHT_BROWSER_SCENARIO_PROVIDER_IDENTITY.id,
),
loadPort(
factories.electronObservation,
CDP_ELECTRON_PROVIDER_IDENTITY.id,
),
loadPort(
factories.electronActiveObservation,
PLAYWRIGHT_ELECTRON_ACTIVE_PROVIDER_IDENTITY.id,
),
loadPort(
factories.javascriptRuntimeObservation,
V8_INSPECTOR_PROVIDER_IDENTITY.id,
),
]);
return {
...(browser.ok ? { browserObservation: browser.value } : {}),
...(scenario.ok ? { browserScenarioCapture: scenario.value } : {}),
...(electron.ok ? { electronObservation: electron.value } : {}),
...(electronActive.ok
? { electronActiveObservation: electronActive.value }
: {}),
...(runtime.ok ? { javascriptRuntimeObservation: runtime.value } : {}),
optionalProviderLoadFailures: {
...(browser.ok ? {} : { browserObservation: browser.error }),
...(scenario.ok ? {} : { browserScenarioCapture: scenario.error }),
...(electron.ok ? {} : { electronObservation: electron.error }),
...(electronActive.ok
? {}
: { electronActiveObservation: electronActive.error }),
...(runtime.ok ? {} : { javascriptRuntimeObservation: runtime.error }),
},
};
};