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>
This commit is contained in:
Kaoru0822
2026-10-21 21:18:22 -07:00
committed by GitHub
parent 4a4bbab3c3
commit 8451b961ad
53 changed files with 660 additions and 130 deletions
@@ -1,3 +1,7 @@
import {
ASAR_HEADER_ADMISSION_SETTING,
parseAsarHeaderAdmission,
} from "../../config/asarHeaderAdmission.js";
import { z } from "zod";
import { ArtifactReaderFailure } from "../../artifacts/ArtifactReader.js";
@@ -29,11 +33,16 @@ import { JAVASCRIPT_APPLICATION_PROVIDER } from "../InvestigationProviders.js";
const OPERATION = "analyze_javascript_application" as const;
/** Execution options plus the composition root's environment for admission settings. */
export interface JavaScriptApplicationOptions extends ExecutionOptions {
readonly environment?: Readonly<Record<string, string | undefined>>;
}
/** Statically analyze one local JavaScript/Electron application. */
export const analyzeJavaScriptApplication = async (
rawInput: unknown,
scope: ArtifactResourceScope,
options: ExecutionOptions = {},
options: JavaScriptApplicationOptions = {},
): Promise<Result<Evidence, AnalysisError>> => {
const parsed = analyzeJavaScriptApplicationInputSchema.safeParse(rawInput);
if (!parsed.success)
@@ -47,8 +56,13 @@ export const analyzeJavaScriptApplication = async (
export const analyzeJavaScriptApplicationValidated = async (
input: z.output<typeof analyzeJavaScriptApplicationInputSchema>,
scope: ArtifactResourceScope,
options: ExecutionOptions = {},
options: JavaScriptApplicationOptions = {},
): Promise<Result<Evidence, AnalysisError>> => {
// An invalid setting is refused before analysis, never replaced by the default.
const asarHeaderAdmission = parseAsarHeaderAdmission(
options.environment?.[ASAR_HEADER_ADMISSION_SETTING],
);
if (!asarHeaderAdmission.ok) return asarHeaderAdmission;
let reconstructed: JavaScriptArtifactReconstructionResult | undefined;
let result: JavaScriptApplicationAnalysisResult | undefined;
let evidence: Evidence | undefined;
@@ -66,6 +80,7 @@ export const analyzeJavaScriptApplicationValidated = async (
scope,
options.signal,
options.progress,
asarHeaderAdmission.value,
);
const { electron_summary: summary, ...application } = reconstructed;
await options.progress?.report({