fix(release-exposure)!: omit checks that cannot apply to the detected formats (#14240)

* fix(release-exposure)!: omit checks that cannot apply to the detected formats

audit-release-exposure always returned all 15 checks. On a single PE it
reported Mach-O hardened runtime and the Android manifest as not_assessed,
and the four Electron fuse checks as not_applicable, each with a next probe
for another format. Agents following those probes would run Mach-O,
Android, or Electron tools on a Windows image.

The report now omits a check that cannot apply and names it in
coverage.inapplicable_checks. Applicability comes from the reader's format
facts: native image formats, the target kind, embedded package formats,
and whether a native image may have gone unread. A check stays whenever a
member it could apply to may be unread. checks and inapplicable_checks
always split the fixed table, in order, and the report schema enforces it.

On a public x64 SDL2.dll the JSON report drops from 10,451 to 6,256 bytes.

BREAKING CHANGE: release-exposure checks no longer use the not_applicable
status, and summary.by_status has no not_applicable count. A check that
cannot apply is absent from checks and listed in
coverage.inapplicable_checks.

Fixes #14163

* fix(release-exposure): keep format checks when a package may hold them

A selected executable that embeds a package, such as a .NET bundle or
PyInstaller archive, may store native images and other members that the
audit does not read. Applicability ignored those for executables, so a PE
bundle with a packaged Mach-O helper lost macho.hardened_runtime and its
inspect_signature probe.

Unread or packaged native images and embedded packages now keep the
Mach-O, native hardening and Android checks for every target kind. Direct
schema cases cover duplicate, overlapping, missing and reordered splits.

* fix(release-exposure): decide native applicability from unread members, not package presence

A fully read ASAR or other package with no native member regained native.hardening, macho.hardened_runtime and android.manifest, because any embedded package format counted as an unread member. Applicability now follows nativeImagesMayBeUnread, which already covers native images stored inside a package that went unread. Android stays limited to directory and file selections.
This commit is contained in:
morluto authored and GitHub committed 2026-11-24 03:29:27 +00:00
1 parent 6d408c0480
commit 5f63d244e9
7 files changed
+468 -102

No files matched your search

+20 -3
View File
@@ -1,6 +1,6 @@
# Release exposure
`audit_release_exposure` / `audit-release-exposure` reads one shipped artifact and reports what static analysis of that artifact recovers. The input is a macOS `.app` bundle, an install directory, an ASAR, or a single executable. Each check has a stable id, a status, the observation behind that status, and fixed remediation text.
`audit_release_exposure` / `audit-release-exposure` reads one shipped artifact and reports what static analysis of that artifact recovers. The input is a macOS `.app` bundle, an install directory, an ASAR, or a single executable. Each reported check has a stable id, a status, the observation behind that status, and fixed remediation text. A check that cannot apply to the artifact's detected formats is omitted from `checks` and named in `coverage.inapplicable_checks`.
The report does not establish that an application is secure. A check that could not be completed is `unknown` or `not_assessed`, and those counts stay beside the findings. There is no pass verdict and no letter grade.
@@ -54,7 +54,24 @@ padding does not supply an RVA mapping.
`text.credential_markers` matches provider-prefixed forms such as a PEM private-key header and documented vendor token prefixes. The report contains the rule id and location only. Matched bytes, previews, lengths, and hashes of matched bytes are omitted.
`native.hardening`, `macho.hardened_runtime`, and `android.manifest` stay `not_assessed`. Their next probes are `inspect_binary_hardening`, `inspect_signature`, and `inspect_android_package`.
`native.hardening`, `macho.hardened_runtime`, and `android.manifest` are `not_assessed` where they can apply. Their next probes are `inspect_binary_hardening`, `inspect_signature`, and `inspect_android_package`.
## Checks that cannot apply
The report omits a check that cannot apply to the formats the audit detected, and lists its id under `coverage.inapplicable_checks` in table order. `checks` and `coverage.inapplicable_checks` together always name every check in the table above, once each. A check stays in `checks` whenever a member it could apply to may have gone unread, such as a native image past the sample, a native image stored inside a package that was not read, or an incomplete inventory. A fully read package with no native member does not keep the native checks.
| Check | Omitted when |
| -------------------------------------------- | -------------------------------------------------------------------------------------------------------------------- |
| `javascript.*` | The selection is a native executable with no embedded package and complete coverage |
| `electron.*` | The fuse readers ruled Electron out: no Electron Framework in an app bundle, or no fuse sentinel in any native image |
| `native.pdb_path` | No PE image was examined |
| `go.build_paths`, `rust.dependency_metadata` | Every native image read was unsupported by the Go or Rust reader, or there was none |
| `text.credential_markers` | No text member was found |
| `native.hardening` | No native image was found |
| `macho.hardened_runtime` | No Mach-O image was found |
| `android.manifest` | The selection is an app bundle, an ASAR, or a native executable |
On a single Windows PE, for example, the Electron, JavaScript, Mach-O, and Android checks are omitted, and `native.hardening` keeps its `inspect_binary_hardening` probe.
Source map text is counted and then dropped. A selected file is read through the stable artifact reader. Text and source-map members stay inside the allowances listed under `coverage.allowances`, and each kind has its own allowance, so binary members cannot use up the read that a later source map needs. Native images on disk are registered from inventory classification and are not limited to those allowances. Other files and package members are identified from a bounded header. The bytes a package member's text or map read returns decide before its name does, so a PE called `payload.js.map` is read as a PE. A header with no NUL byte, or one that starts with a UTF-16 byte order mark, is scanned as text, so names such as `.env.production`, `server.key`, and `credentials` do not depend on an extension list. UTF-16 without a byte order mark has NUL bytes and is not recognized this way. A member already known to be text, such as a script, is also scanned when it is UTF-8 holding a stray NUL. One whose header is at least an eighth NUL bytes is taken to be wide text. It is not decoded and is counted as skipped, as is UTF-32. A binary plist is decoded, so its strings, dictionary keys and data are scanned in whichever encoding each object uses. One that cannot be decoded still has its bytes scanned and is counted as skipped. A file whose header could not be read leaves `text.credential_markers` undecided. A packaged ELF, Mach-O, or PE image is read in full and written to a temporary copy, removed afterward, so it can be probed for an embedded package. All packaged images share one `max_file_bytes` allowance. An image that does not fit, or whose bytes cannot be read, is not probed and leaves member coverage `unknown`. A packaged PE is also read for its debug records. An SVG file is read for its scripts as an HTML file is. A script that an HTML file loads, or a Node SEA main script, is examined as a script whatever it is called, so a name such as `boot.map` does not make it a map, and an HTML file loaded this way is still examined as HTML. Its bytes still decide over that role: a `.map` or loaded script whose text parses as a source map, a JSON object with `version` and `mappings`, `sources`, or `sections`, is read as a source map, so `<script src="main.map">` pointing at a map with `sourcesContent` still reports `javascript.source_map_sources` exposed. One read before that HTML file, one that is not found, one at a location the audit cannot place, or one past the 1 MiB of resolved script paths the audit keeps (`MAX_RELEASE_EXPOSURE_SCRIPT_TARGET_BYTES`) leaves `javascript.source_map_sources` undecided. A `.map` read before the HTML file that loads it is not reported as a linker map. Skipped members are listed under `coverage.omitted`. The report keeps the first eight scan limitations; a `limitations` entry under `coverage.omitted` counts the reports past them, including repeats. When the selection is a file, the parent directory is listed up to a fixed entry allowance for sibling `.pdb`, `.dSYM`, `.debug`, and linker `.map` debug companions. A sibling source map that the selected file declares, such as `app.js.map`, or a sibling script that a selected HTML file loads, such as `app.js`, is not read as part of the artifact, so it leaves `javascript.source_map_sources` undecided.
@@ -72,7 +89,7 @@ A map read counts against the source-map allowance when it starts, so an oversiz
## Status
`exposed` means the check's condition was observed. `not_observed` means that condition was absent in a completed scan. `not_applicable` means the check does not apply to this artifact, for example Electron fuses on an app bundle with no Electron Framework, or on a directory whose native images were all read and hold no fuse sentinel. `unknown` means the check could not be decided, including a directory with no ASAR layout where those reads are missing or incomplete (an `asar: false` Electron build has no ASAR to find), safe fuses from an incomplete inventory, an unopened packaged native image, or a dropped image when the sample did not read an executable named as the Electron host or every executable that could be it, a missing fuse sentinel on an Electron target, a universal binary with a slice that has no sentinel or an undecided fuse, a file that changed after inventory, Electron fuses on a selected ASAR (which does not include the executable that holds them), a PE inside a package that was too large to read, Go or Rust metadata on a native image stored inside a package, and Go or Rust metadata that was not present. Absence of that metadata is not proof the binary is something else. `not_assessed` means this audit did not run the check.
`exposed` means the check's condition was observed. `not_observed` means that condition was absent in a completed scan. A check that does not apply to this artifact, for example Electron fuses on an app bundle with no Electron Framework, or on a directory whose native images were all read and hold no fuse sentinel, is omitted as described under [checks that cannot apply](#checks-that-cannot-apply). `unknown` means the check could not be decided, including a directory with no ASAR layout where those reads are missing or incomplete (an `asar: false` Electron build has no ASAR to find), safe fuses from an incomplete inventory, an unopened packaged native image, or a dropped image when the sample did not read an executable named as the Electron host or every executable that could be it, a missing fuse sentinel on an Electron target, a universal binary with a slice that has no sentinel or an undecided fuse, a file that changed after inventory, Electron fuses on a selected ASAR (which does not include the executable that holds them), a PE inside a package that was too large to read, Go or Rust metadata on a native image stored inside a package, and Go or Rust metadata that was not present. Absence of that metadata is not proof the binary is something else. `not_assessed` means this audit did not run the check.
Cancellation during a Go, Rust, fuse, or desktop read returns a typed cancellation error. Its partial observation holds the report with completed facts, and checks whose readers did not run are `unknown`. Cancellation during the member scan returns the same typed cancellation error. Its partial observation holds the members examined before the cancellation, with member coverage `unknown` and a limitation saying the scan was cancelled. Cancellation before the scan can be assembled, such as during inventory, returns no partial report. If a reader still owns a resource that could not be closed, the workflow returns `cleanup_incomplete` with that owner and any partial report it could assemble. See [lifecycle completion](development/tool-design.md#own-the-lifecycle).
+1 -1
View File
@@ -286,7 +286,7 @@ await withVerifierFixture(fixture, async () => {
Ran \`node scripts/verify-release-exposure.mjs\` with Node ${process.version}. The package script is \`npm run verify:release-exposure\`, which runs \`npm run build:cached\` first because \`scripts/rea.mjs\` loads the compiled CLI. \`@electron/fuses\` ${version} was installed into a temporary prefix and \`flipFuses\` was called on the after framework binary.
The fixture is \`MyApp.app\`. \`Contents/Resources/app.asar\` holds \`app.js\`. Before, it also holds \`app.js.map\` with \`sourcesContent\`. \`Contents/Frameworks/Electron Framework.framework/Electron Framework\` is an ELF larger than 256 KiB with the Electron fuse sentinel and a version-1 fuse wire. After, the archive is rebuilt without the map and \`flipFuses\` disables \`RunAsNode\` and \`EnableNodeCliInspectArguments\` and enables \`OnlyLoadAppFromAsar\` and \`EnableEmbeddedAsarIntegrityValidation\`. \`app.js\` remains, so \`packaging.extractable_payload\` stays exposed. Embedded ASAR integrity stays \`unknown\` on ELF. Go and Rust stay \`unknown\` because the framework binary is registered and has no build metadata; that is not \`not_applicable\`.
The fixture is \`MyApp.app\`. \`Contents/Resources/app.asar\` holds \`app.js\`. Before, it also holds \`app.js.map\` with \`sourcesContent\`. \`Contents/Frameworks/Electron Framework.framework/Electron Framework\` is an ELF larger than 256 KiB with the Electron fuse sentinel and a version-1 fuse wire. After, the archive is rebuilt without the map and \`flipFuses\` disables \`RunAsNode\` and \`EnableNodeCliInspectArguments\` and enables \`OnlyLoadAppFromAsar\` and \`EnableEmbeddedAsarIntegrityValidation\`. \`app.js\` remains, so \`packaging.extractable_payload\` stays exposed. Embedded ASAR integrity stays \`unknown\` on ELF. Go and Rust stay \`unknown\` because the framework binary is registered and has no build metadata; they are not omitted as inapplicable.
\`--fail_on high\` on the before app exited ${String(gated.status)}.
@@ -190,10 +190,12 @@ describe("ReleaseExposureService", () => {
status: string;
observation: { samples: string[] };
}[];
coverage: { inapplicable_checks: string[] };
};
expect(report.coverage.inapplicable_checks).toContain("go.build_paths");
expect(
report.checks.find((check) => check.id === "go.build_paths")?.status,
).toBe("not_applicable");
report.checks.find((check) => check.id === "go.build_paths"),
).toBeUndefined();
expect(
report.checks.find((check) => check.id === "rust.dependency_metadata")
?.status,
@@ -723,9 +725,13 @@ describe("ReleaseExposureService fuse slice coverage", () => {
electronFuses.inspect.mockResolvedValue(ok(evidence(fuseReport(slices))));
const result = await service.inspect({ path: "/work/app" });
if (!result.ok) throw result.error;
return releaseExposureReportSchema
.parse(result.value.normalized_result)
.checks.find((item) => item.id === "electron.run_as_node")?.status;
const report = releaseExposureReportSchema.parse(
result.value.normalized_result,
);
return report.coverage.inapplicable_checks.includes("electron.run_as_node")
? "inapplicable"
: report.checks.find((item) => item.id === "electron.run_as_node")
?.status;
};
it("needs every slice to decide before a check is not observed", async () => {
@@ -749,7 +755,7 @@ describe("ReleaseExposureService fuse slice coverage", () => {
});
it("leaves a file with no sentinel without fuse implications", async () => {
expect(await status([slice(0, { sentinels: 0 })])).toBe("not_applicable");
expect(await status([slice(0, { sentinels: 0 })])).toBe("inapplicable");
});
});
@@ -942,9 +948,12 @@ const runAsNode = async (
) => {
const result = await service.inspect({ path });
if (!result.ok) throw result.error;
return releaseExposureReportSchema
.parse(result.value.normalized_result)
.checks.find((check) => check.id === "electron.run_as_node");
const report = releaseExposureReportSchema.parse(
result.value.normalized_result,
);
return report.coverage.inapplicable_checks.includes("electron.run_as_node")
? { status: "inapplicable" as const }
: report.checks.find((check) => check.id === "electron.run_as_node");
};
describe("ReleaseExposureService packaged native images", () => {
@@ -1725,7 +1734,7 @@ describe("ReleaseExposureService Electron applicability", () => {
directoryScan(["/work/app/one", "/work/app/two"]),
);
electronFuses.inspect.mockResolvedValue(noSentinel);
expect((await runAsNode(service))?.status).toBe("not_applicable");
expect((await runAsNode(service))?.status).toBe("inapplicable");
});
it.each([
@@ -1775,14 +1784,17 @@ describe("ReleaseExposureService Electron applicability", () => {
result.value.normalized_result,
);
expect(
report.checks
.filter(({ id }) => id.startsWith("electron."))
.map(({ status }) => status),
report.checks.filter(({ id }) => id.startsWith("electron.")),
).toEqual([]);
expect(
report.coverage.inapplicable_checks.filter((id) =>
id.startsWith("electron."),
),
).toEqual([
"not_applicable",
"not_applicable",
"not_applicable",
"not_applicable",
"electron.run_as_node",
"electron.asar_integrity",
"electron.only_load_from_asar",
"electron.node_cli_inspect",
]);
});
@@ -1861,8 +1873,12 @@ describe("ReleaseExposureService app bundle with a sidecar", () => {
: safeFramework,
);
const check = await runAsNode(service, "/work/App.app");
expect(check?.status).toBe("exposed");
expect(JSON.stringify(check?.locations)).toContain(SIDECAR);
expect(check).toMatchObject({
status: "exposed",
locations: expect.arrayContaining([
expect.objectContaining({ path: SIDECAR }),
]),
});
expect(readPaths(electronFuses.inspect)).toEqual([
"/work/App.app",
SIDECAR,
@@ -2403,11 +2419,14 @@ describe("ReleaseExposureService undecoded metadata", () => {
);
const result = await service.inspect({ path: "/work/app" });
if (!result.ok) throw result.error;
const { checks } = releaseExposureReportSchema.parse(
const { checks, coverage } = releaseExposureReportSchema.parse(
result.value.normalized_result,
);
return ["go.build_paths", "rust.dependency_metadata"].map(
(id) => checks.find((check) => check.id === id)?.status,
return (["go.build_paths", "rust.dependency_metadata"] as const).map(
(id) =>
coverage.inapplicable_checks.includes(id)
? "inapplicable"
: checks.find((check) => check.id === id)?.status,
);
};
@@ -2416,7 +2435,7 @@ describe("ReleaseExposureService undecoded metadata", () => {
});
it("stays not applicable when the target itself is unsupported", async () => {
expect(await statuses(false)).toEqual(["not_applicable", "not_applicable"]);
expect(await statuses(false)).toEqual(["inapplicable", "inapplicable"]);
});
});
@@ -22,7 +22,7 @@ export const RELEASE_EXPOSURE_TOOL_CONTRACTS = [
),
kind: "artifact-provider",
description:
"Report what static analysis of a shipped application artifact recovers. Accepts one local .app bundle, installation directory, ASAR, or executable. Each check has a stable id, a status, the observation behind it, and fixed remediation text. Unknown and unassessed checks stay in the report. This does not establish that an application is secure. Reads the selected artifact. When the selection is a file, the parent directory is listed for sibling .pdb, .dSYM, .debug, and .map debug companions.",
"Report what static analysis of a shipped application artifact recovers. Accepts one local .app bundle, installation directory, ASAR, or executable. Each check has a stable id, a status, the observation behind it, and fixed remediation text. Unknown and unassessed checks stay in the report. Checks that cannot apply to the detected formats are omitted and listed in coverage.inapplicable_checks. This does not establish that an application is secure. Reads the selected artifact. When the selection is a file, the parent directory is listed for sibling .pdb, .dSYM, .debug, and .map debug companions.",
inputSchema: auditReleaseExposureInputSchema,
outputSchema: evidenceResultOf(releaseExposureReportSchema),
examples: [
+248 -27
View File
@@ -4,6 +4,7 @@ import {
assembleReleaseExposureReport,
exposureMeetsFailOn,
PACKAGED_NATIVE_IMAGES,
releaseExposureReportSchema,
type ReleaseExposureCheckId,
type ReleaseExposureOwnerFacts,
type ReleaseExposureScan,
@@ -61,42 +62,263 @@ const reportFor = (
ownerFacts: ReleaseExposureOwnerFacts = owners(),
) => assembleReleaseExposureReport(scanned, ownerFacts);
/** A reported check's status, or `inapplicable` when the check was omitted. */
const statusOf = (
report: ReturnType<typeof reportFor>,
id: ReleaseExposureCheckId,
) => report.checks.find((check) => check.id === id)?.status;
) =>
report.coverage.inapplicable_checks.includes(id)
? "inapplicable"
: report.checks.find((check) => check.id === id)?.status;
const ALL_CHECKS: readonly ReleaseExposureCheckId[] = [
"javascript.source_map_sources",
"javascript.source_maps",
"electron.run_as_node",
"electron.asar_integrity",
"electron.only_load_from_asar",
"electron.node_cli_inspect",
"packaging.extractable_payload",
"native.debug_companions",
"native.pdb_path",
"go.build_paths",
"rust.dependency_metadata",
"text.credential_markers",
"native.hardening",
"macho.hardened_runtime",
"android.manifest",
];
const executable = (
format: "pe" | "mach-o",
overrides: Partial<ReleaseExposureScan> = {},
) =>
scan({
target: {
selected_path: "/work/app.bin",
kind: "executable",
format,
sha256: SHA,
},
subject: { path: "/work/app.bin", sha256: SHA, format },
native_images: [{ path: "/work/app.bin", format, sha256: SHA }],
pdb: { examined: format === "pe" ? 1 : 0, paths: [], failed: 0 },
text_members: { scanned: 0, skipped: 0 },
...overrides,
});
describe("release exposure checks", () => {
it("keeps the fixed check order and the security limitation", () => {
const report = reportFor();
expect(report.checks.map((check) => check.id)).toEqual([
it("splits the fixed check table between rows and inapplicable checks, in order", () => {
const report = reportFor(
scan({
native_images: [{ path: "/work/app/bin", format: "elf" }],
pdb: { examined: 1, paths: [], failed: 0 },
}),
owners({
electron_family: "unknown",
go_images: [{ kind: "absent" }],
rust_images: [{ kind: "absent" }],
}),
);
expect(report.checks.map((check) => check.id)).toEqual(
ALL_CHECKS.filter((id) => id !== "macho.hardened_runtime"),
);
expect(report.coverage.inapplicable_checks).toEqual([
"macho.hardened_runtime",
]);
expect(report.limitations[0]).toMatch(
/static analysis.*does not establish.*secure/u,
);
expect(report.summary.no_exposure_observed_in_assessed_checks).toBe(true);
expect(report.summary.by_status.not_assessed).toBe(2);
expect(report.summary.highest_exposed_severity).toBeNull();
expect(statusOf(report, "native.hardening")).toBe("not_assessed");
expect(statusOf(report, "android.manifest")).toBe("not_assessed");
});
});
describe("release exposure format applicability", () => {
it("omits checks that cannot apply to a single PE and names them in coverage", () => {
const report = reportFor(
executable("pe", {
pdb: { examined: 1, paths: ["C:\\build\\app.pdb"], failed: 0 },
}),
owners({
electron_family: "not_a_directory",
go_images: [{ kind: "absent" }],
rust_images: [{ kind: "absent" }],
}),
);
expect(report.coverage.inapplicable_checks).toEqual([
"javascript.source_map_sources",
"javascript.source_maps",
"electron.run_as_node",
"electron.asar_integrity",
"electron.only_load_from_asar",
"electron.node_cli_inspect",
"packaging.extractable_payload",
"native.debug_companions",
"native.pdb_path",
"go.build_paths",
"rust.dependency_metadata",
"text.credential_markers",
"native.hardening",
"macho.hardened_runtime",
"android.manifest",
]);
expect(report.limitations[0]).toMatch(
/static analysis.*does not establish.*secure/u,
expect(statusOf(report, "native.pdb_path")).toBe("exposed");
expect(statusOf(report, "native.hardening")).toBe("not_assessed");
expect(report.summary.by_status).toEqual({
exposed: 1,
not_observed: 2,
unknown: 2,
not_assessed: 1,
});
expect(
report.checks.flatMap((check) =>
check.next_probe === null ? [] : [check.next_probe],
),
).toEqual([
"inspect_artifact",
"inspect_go_binary",
"inspect_rust_binary",
"inspect_binary_hardening",
]);
});
it("keeps the Mach-O check on a Mach-O executable and omits the PE one", () => {
const report = reportFor(
executable("mach-o"),
owners({ electron_family: "not_a_directory" }),
);
expect(statusOf(report, "macho.hardened_runtime")).toBe("not_assessed");
expect(statusOf(report, "native.pdb_path")).toBe("inapplicable");
expect(statusOf(report, "android.manifest")).toBe("inapplicable");
});
it("keeps JavaScript checks on an executable that embeds a package", () => {
const report = reportFor(
executable("pe", {
extractable: {
formats: ["node-sea"],
readable_members: 0,
unreadable_members: 0,
samples: [],
},
}),
owners({ electron_family: "not_a_directory" }),
);
expect(statusOf(report, "javascript.source_map_sources")).toBe(
"not_observed",
);
expect(statusOf(report, "javascript.source_maps")).toBe("not_observed");
});
it("keeps the Mach-O check on a PE bundle whose packaged images are unread", () => {
const report = reportFor(
executable("pe", {
extractable: {
formats: ["dotnet-bundle"],
readable_members: 1,
unreadable_members: 0,
samples: ["helper"],
},
omitted: [
{
subject: PACKAGED_NATIVE_IMAGES,
count: 1,
reason: "stored inside a package",
},
],
}),
owners({ electron_family: "not_a_directory" }),
);
expect(statusOf(report, "macho.hardened_runtime")).toBe("not_assessed");
expect(statusOf(report, "android.manifest")).toBe("inapplicable");
expect(
report.checks.find(({ id }) => id === "macho.hardened_runtime")
?.next_probe,
).toBe("inspect_signature");
});
it("omits native and Android checks on a fully read ASAR with only text", () => {
const report = reportFor(
scan({
target: {
selected_path: "/work/app.asar",
kind: "asar",
format: "asar",
sha256: SHA,
},
subject: { path: "/work/app.asar", sha256: SHA, format: "asar" },
extractable: {
formats: ["asar"],
readable_members: 2,
unreadable_members: 0,
samples: ["app.js"],
},
}),
);
expect(statusOf(report, "native.hardening")).toBe("inapplicable");
expect(statusOf(report, "macho.hardened_runtime")).toBe("inapplicable");
expect(statusOf(report, "android.manifest")).toBe("inapplicable");
expect(statusOf(report, "packaging.extractable_payload")).toBe("exposed");
});
});
describe("release exposure report split invariant", () => {
it("rejects reports whose rows and inapplicable checks do not split the table", () => {
const valid = reportFor(
executable("pe"),
owners({ electron_family: "not_a_directory" }),
);
expect(releaseExposureReportSchema.safeParse(valid).success).toBe(true);
const [first, second] = valid.coverage.inapplicable_checks;
if (first === undefined || second === undefined)
throw new Error("Expected inapplicable checks");
const reported = valid.checks[0];
if (reported === undefined) throw new Error("Expected a reported check");
const variants = {
duplicate: [first, first, ...valid.coverage.inapplicable_checks.slice(1)],
overlapping: [...valid.coverage.inapplicable_checks, reported.id],
missing: valid.coverage.inapplicable_checks.slice(1),
reordered: [
second,
first,
...valid.coverage.inapplicable_checks.slice(2),
],
};
for (const [label, inapplicable] of Object.entries(variants))
expect(
releaseExposureReportSchema.safeParse({
...valid,
coverage: { ...valid.coverage, inapplicable_checks: inapplicable },
}).success,
label,
).toBe(false);
expect(
releaseExposureReportSchema.safeParse({
...valid,
checks: [...valid.checks].reverse(),
}).success,
).toBe(false);
});
});
describe("release exposure applicability with unread members", () => {
it("keeps format-gated checks on a directory whose native images may be unread", () => {
const report = reportFor(
scan({
omitted: [
{
subject: "native images",
count: 1,
reason: "later native images were dropped",
},
],
}),
);
expect(report.summary.no_exposure_observed_in_assessed_checks).toBe(true);
expect(report.summary.by_status.not_assessed).toBe(3);
expect(report.summary.highest_exposed_severity).toBeNull();
expect(statusOf(report, "native.hardening")).toBe("not_assessed");
expect(statusOf(report, "macho.hardened_runtime")).toBe("not_assessed");
expect(statusOf(report, "android.manifest")).toBe("not_assessed");
});
});
describe("release exposure check outcomes", () => {
it("grades shipped source maps separately from embedded sources", () => {
const embedded = reportFor(
scan({
@@ -236,7 +458,7 @@ describe("release exposure fuse and package checks", () => {
],
}),
);
expect(statusOf(plain, "electron.run_as_node")).toBe("not_applicable");
expect(statusOf(plain, "electron.run_as_node")).toBe("inapplicable");
const bundle = reportFor(
scan(),
@@ -267,10 +489,8 @@ describe("release exposure fuse and package checks", () => {
],
}),
);
expect(statusOf(nativeApp, "electron.run_as_node")).toBe("not_applicable");
expect(statusOf(nativeApp, "electron.asar_integrity")).toBe(
"not_applicable",
);
expect(statusOf(nativeApp, "electron.run_as_node")).toBe("inapplicable");
expect(statusOf(nativeApp, "electron.asar_integrity")).toBe("inapplicable");
});
});
@@ -641,8 +861,8 @@ describe("release exposure native and text checks", () => {
rust_images: [{ kind: "unsupported" }],
}),
);
expect(statusOf(other, "go.build_paths")).toBe("not_applicable");
expect(statusOf(other, "rust.dependency_metadata")).toBe("not_applicable");
expect(statusOf(other, "go.build_paths")).toBe("inapplicable");
expect(statusOf(other, "rust.dependency_metadata")).toBe("inapplicable");
});
});
@@ -660,7 +880,7 @@ describe("release exposure gate and undecided checks", () => {
}),
);
expect(report.summary.by_status.unknown).toBeGreaterThan(0);
expect(report.summary.by_status.not_assessed).toBe(3);
expect(report.summary.by_status.not_assessed).toBe(1);
expect(exposureMeetsFailOn(report, "low")).toBe(false);
expect(report.summary.no_exposure_observed_in_assessed_checks).toBe(true);
});
@@ -669,7 +889,7 @@ describe("release exposure gate and undecided checks", () => {
const report = reportFor(
scan({ text_members: { scanned: 0, skipped: 0 } }),
);
expect(statusOf(report, "text.credential_markers")).toBe("not_applicable");
expect(statusOf(report, "text.credential_markers")).toBe("inapplicable");
const scanned = reportFor();
expect(statusOf(scanned, "text.credential_markers")).toBe("not_observed");
const skipped = reportFor(
@@ -705,9 +925,10 @@ describe("release exposure gate and undecided checks", () => {
});
it("names the real @electron/fuses option on every fuse remediation", () => {
const fuses = reportFor().checks.filter((check) =>
check.id.startsWith("electron."),
);
const fuses = reportFor(
scan(),
owners({ electron_family: "unknown" }),
).checks.filter((check) => check.id.startsWith("electron."));
expect(fuses).toHaveLength(4);
for (const check of fuses) {
expect(check.remediation).toContain("FuseV1Options.");
+97 -41
View File
@@ -56,7 +56,6 @@ export const RELEASE_EXPOSURE_ALLOWANCES = [
export const RELEASE_EXPOSURE_STATUSES = [
"exposed",
"not_observed",
"not_applicable",
"unknown",
"not_assessed",
] as const;
@@ -89,6 +88,11 @@ const RELEASE_EXPOSURE_CHECK_IDS = [
const statusSchema = z.enum(RELEASE_EXPOSURE_STATUSES);
const severitySchema = z.enum(RELEASE_EXPOSURE_SEVERITIES);
type Status = z.infer<typeof statusSchema>;
/**
* A builder's outcome. `not_applicable` is never reported as a row: the check
* is omitted and named in `coverage.inapplicable_checks` instead.
*/
type Outcome = Status | "not_applicable";
type Severity = z.infer<typeof severitySchema>;
export type ReleaseExposureCheckId =
(typeof RELEASE_EXPOSURE_CHECK_IDS)[number];
@@ -230,7 +234,6 @@ const releaseExposureCheckSchema = z.strictObject({
const countSchema = z.strictObject({
exposed: z.int().nonnegative(),
not_observed: z.int().nonnegative(),
not_applicable: z.int().nonnegative(),
unknown: z.int().nonnegative(),
not_assessed: z.int().nonnegative(),
});
@@ -258,6 +261,11 @@ export const releaseExposureReportSchema = z
}),
coverage: z.strictObject({
allowances: z.array(z.string().min(1)),
inapplicable_checks: z
.array(z.enum(RELEASE_EXPOSURE_CHECK_IDS))
.describe(
"Checks that cannot apply to this artifact's detected formats. They are omitted from checks.",
),
omitted: z.array(
z.strictObject({
subject: z.string().min(1),
@@ -269,16 +277,25 @@ export const releaseExposureReportSchema = z
limitations: z.array(z.string().min(1)),
})
.superRefine((report, context) => {
const inapplicable = new Set(report.coverage.inapplicable_checks);
const expected = RELEASE_EXPOSURE_CHECK_IDS.filter(
(id) => !inapplicable.has(id),
);
const omitted = RELEASE_EXPOSURE_CHECK_IDS.filter((id) =>
inapplicable.has(id),
);
if (
report.checks.length !== RELEASE_EXPOSURE_CHECK_IDS.length ||
report.checks.some(
(check, index) => check.id !== RELEASE_EXPOSURE_CHECK_IDS[index],
report.checks.length !== expected.length ||
report.checks.some((check, index) => check.id !== expected[index]) ||
report.coverage.inapplicable_checks.some(
(id, index) => id !== omitted[index],
)
)
context.addIssue({
code: "custom",
path: ["checks"],
message: "Checks must be the fixed release-exposure table, in order.",
message:
"Checks and coverage.inapplicable_checks must split the fixed release-exposure table, in order.",
});
for (const [index, check] of report.checks.entries()) {
const policy = CHECK_TABLE[check.id];
@@ -484,14 +501,22 @@ const boundLocations = (
// sample-cap: illustrative locations; observation.counts reports the totals
): EvidenceLocation[] => locations.slice(0, MAX_RELEASE_EXPOSURE_SAMPLES);
/** A check that cannot apply to the artifact's detected formats. */
interface InapplicableCheck {
readonly id: ReleaseExposureCheckId;
readonly status: "not_applicable";
}
type CheckResult = ReleaseExposureCheck | InapplicableCheck;
const makeCheck = (
id: ReleaseExposureCheckId,
status: Status,
status: Outcome,
confidence: "observed" | "inferred",
counts: Record<string, number>,
samples: readonly string[],
locations: readonly EvidenceLocation[],
): ReleaseExposureCheck => {
): CheckResult => {
if (status === "not_applicable") return { id, status };
const policy = CHECK_TABLE[id];
return {
id,
@@ -524,10 +549,10 @@ const sourceMapCheck = (
id: ReleaseExposureCheckId,
present: number,
scan: ReleaseExposureScan,
): ReleaseExposureCheck => {
): CheckResult => {
const { source_maps: maps, coverage, target } = scan;
const unresolved = maps.unparsed + maps.skipped > 0 || coverage === "unknown";
const status: Status =
const status: Outcome =
present > 0 ? "exposed" : unresolved ? "unknown" : "not_observed";
const findingPaths =
id === "javascript.source_map_sources"
@@ -604,7 +629,7 @@ const fuseCheck = (
id: keyof typeof FUSE_SUBJECTS,
scan: ReleaseExposureScan,
owners: ReleaseExposureOwnerFacts,
): ReleaseExposureCheck => {
): CheckResult => {
const path = scan.target.selected_path;
const spec = FUSE_SUBJECTS[id];
const images = owners.fuse_images;
@@ -630,7 +655,7 @@ const fuseCheck = (
packagedNativeImagesUnread(scan) ||
(nativeImagesMayBeUnread(scan) &&
owners.electron_executable_included !== true);
let status: Status;
let status: Outcome;
if (outcomes.includes(spec.exposed)) status = "exposed";
else if (owners.electron_family === "not_electron")
status = nativeImagesMayBeUnread(scan) ? "unknown" : "not_applicable";
@@ -673,9 +698,9 @@ const fuseCheck = (
);
};
const extractableCheck = (scan: ReleaseExposureScan): ReleaseExposureCheck => {
const extractableCheck = (scan: ReleaseExposureScan): CheckResult => {
const { extractable, coverage, target } = scan;
let status: Status;
let status: Outcome;
if (extractable.readable_members > 0) status = "exposed";
else if (
extractable.unreadable_members > 0 ||
@@ -700,9 +725,9 @@ const extractableCheck = (scan: ReleaseExposureScan): ReleaseExposureCheck => {
);
};
const companionCheck = (scan: ReleaseExposureScan): ReleaseExposureCheck => {
const companionCheck = (scan: ReleaseExposureScan): CheckResult => {
const { debug_companions: companions, coverage, target } = scan;
const status: Status =
const status: Outcome =
companions.paths.length > 0
? "exposed"
: companions.skipped > 0 || coverage === "unknown"
@@ -721,11 +746,11 @@ const companionCheck = (scan: ReleaseExposureScan): ReleaseExposureCheck => {
);
};
const pdbCheck = (scan: ReleaseExposureScan): ReleaseExposureCheck => {
const pdbCheck = (scan: ReleaseExposureScan): CheckResult => {
const { pdb, coverage, target } = scan;
const rawPaths = pdb.path_bytes ?? [];
const paths = pdb.paths.length + rawPaths.length;
let status: Status;
let status: Outcome;
if (paths > 0) status = "exposed";
else if (pdb.failed > 0 || coverage !== "complete") status = "unknown";
else if (pdb.examined === 0) status = "not_applicable";
@@ -741,7 +766,7 @@ const pdbCheck = (scan: ReleaseExposureScan): ReleaseExposureCheck => {
? findingLocations(imagePaths, target.selected_path)
: targetLocation(target.selected_path),
);
return rawPaths.length === 0
return rawPaths.length === 0 || check.status === "not_applicable"
? check
: {
...check,
@@ -753,7 +778,7 @@ const metadataStatus = (
images: readonly MetadataImageFact[],
present: (image: MetadataImageFact) => boolean,
unresolved: boolean,
): Status => {
): Outcome => {
if (images.some(present)) return "exposed";
if (
unresolved ||
@@ -771,7 +796,7 @@ const retainsBuildPaths = (image: MetadataImageFact): boolean =>
const goCheck = (
scan: ReleaseExposureScan,
images: readonly MetadataImageFact[],
): ReleaseExposureCheck => {
): CheckResult => {
const path = scan.target.selected_path;
const paths = images.flatMap((image) =>
image.kind === "paths" ? image.paths : [],
@@ -805,7 +830,7 @@ const goCheck = (
const rustCheck = (
scan: ReleaseExposureScan,
images: readonly MetadataImageFact[],
): ReleaseExposureCheck => {
): CheckResult => {
const path = scan.target.selected_path;
const packages = images.flatMap((image) =>
image.kind === "packages" ? image.packages : [],
@@ -836,7 +861,7 @@ const rustCheck = (
const credentialCheck = (
scan: ReleaseExposureScan,
markers: ReleaseExposureOwnerFacts["credential_markers"],
): ReleaseExposureCheck => {
): CheckResult => {
const { text_members: members, coverage, target } = scan;
const counts: Record<string, number> = {
scanned_members: members.scanned,
@@ -845,7 +870,7 @@ const credentialCheck = (
};
for (const hit of markers.hits)
counts[hit.rule_id] = (counts[hit.rule_id] ?? 0) + 1;
const status: Status =
const status: Outcome =
markers.hits.length > 0
? "exposed"
: members.skipped > 0 || coverage === "unknown"
@@ -871,33 +896,59 @@ const credentialCheck = (
const notAssessed = (
id: "native.hardening" | "macho.hardened_runtime" | "android.manifest",
path: string,
): ReleaseExposureCheck =>
applies: boolean,
): CheckResult =>
makeCheck(
id,
"not_assessed",
applies ? "not_assessed" : "not_applicable",
"inferred",
{ assessed: 0 },
[],
targetLocation(path),
);
/**
* Which format-gated checks can apply, from the reader's format facts. A check
* stays when a member it could apply to may have gone unread.
*/
const formatApplicability = (scan: ReleaseExposureScan) => {
const formats = new Set(scan.native_images.map((image) => image.format));
// Member formats decide applicability. A native image that may have gone
// unread, including one stored inside a package, keeps the native checks;
// a fully read package with no native member does not.
const unread = nativeImagesMayBeUnread(scan);
return {
native: formats.size > 0 || unread,
macho: formats.has("mach-o") || formats.has("mach-o-universal") || unread,
// The audit does not recognize Android packages, so a directory or an
// unclassified file may hold one. An app bundle, an ASAR, or a native
// executable cannot be one.
android: scan.target.kind === "directory" || scan.target.kind === "file",
// A native executable carries JavaScript only inside an embedded package.
javascript:
scan.target.kind !== "executable" ||
scan.extractable.formats.length > 0 ||
scan.coverage !== "complete",
};
};
/** Build the fixed check list from reader facts and owner results. */
export const assembleReleaseExposureReport = (
scan: ReleaseExposureScan,
owners: ReleaseExposureOwnerFacts,
): ReleaseExposureReport => {
const path = scan.target.selected_path;
const checks = [
sourceMapCheck(
"javascript.source_map_sources",
scan.source_maps.embedded,
scan,
),
sourceMapCheck(
"javascript.source_maps",
scan.source_maps.without_sources,
scan,
),
const applies = formatApplicability(scan);
const sourceMaps = (
id: "javascript.source_map_sources" | "javascript.source_maps",
present: number,
): CheckResult =>
applies.javascript || present > 0
? sourceMapCheck(id, present, scan)
: { id, status: "not_applicable" };
const results: CheckResult[] = [
sourceMaps("javascript.source_map_sources", scan.source_maps.embedded),
sourceMaps("javascript.source_maps", scan.source_maps.without_sources),
fuseCheck("electron.run_as_node", scan, owners),
fuseCheck("electron.asar_integrity", scan, owners),
fuseCheck("electron.only_load_from_asar", scan, owners),
@@ -908,16 +959,22 @@ export const assembleReleaseExposureReport = (
goCheck(scan, owners.go_images),
rustCheck(scan, owners.rust_images),
credentialCheck(scan, owners.credential_markers),
notAssessed("native.hardening", path),
notAssessed("macho.hardened_runtime", path),
notAssessed("android.manifest", path),
notAssessed("native.hardening", path, applies.native),
notAssessed("macho.hardened_runtime", path, applies.macho),
notAssessed("android.manifest", path, applies.android),
];
const checks = results.filter(
(check): check is ReleaseExposureCheck => check.status !== "not_applicable",
);
return releaseExposureReportSchema.parse({
target: scan.target,
checks,
summary: summarizeReleaseExposureChecks(checks),
coverage: {
allowances: [...RELEASE_EXPOSURE_ALLOWANCES],
inapplicable_checks: results.flatMap((check) =>
check.status === "not_applicable" ? [check.id] : [],
),
omitted: scan.omitted.filter((item) => item.count > 0),
},
limitations: [
@@ -939,7 +996,6 @@ export const summarizeReleaseExposureChecks = (
const byStatus = {
exposed: 0,
not_observed: 0,
not_applicable: 0,
unknown: 0,
not_assessed: 0,
};
+59 -6
View File
@@ -6,6 +6,11 @@ import { expect } from "vitest";
import { RELEASE_EXPOSURE_TOOL_CONTRACTS } from "../../src/contracts/releaseExposureToolContracts.js";
import { createTestTempDirectory } from "../fixtures/temporaryDirectory.js";
import { cliTest } from "../support/cli/cliFixture.js";
import { pe } from "../../src/domain/binaryTarget.fixture.js";
import { expectCliMcpEvidenceParity } from "../fixtures/cliMcpEvidenceParity.js";
import { lazyLocalToolsMcp } from "../fixtures/localToolsMcp.js";
const connectLocalToolsMcp = lazyLocalToolsMcp();
const PLANTED_SOURCE = "release-exposure-planted-secret-7c2e9a";
const releaseExposureContract = RELEASE_EXPOSURE_TOOL_CONTRACTS.find(
@@ -127,12 +132,14 @@ cliTest("exits 3 when a shipped source map embeds sources", async ({ cli }) => {
expect(
report.checks.find((check) => check.id === "electron.run_as_node")?.status,
).toBe("unknown");
expect(report.coverage.inapplicable_checks).toEqual(
expect.arrayContaining(["native.pdb_path", "go.build_paths"]),
);
expect(
report.checks.find((check) => check.id === "native.pdb_path")?.status,
).toBe("not_applicable");
expect(
report.checks.find((check) => check.id === "go.build_paths")?.status,
).toBe("not_applicable");
report.checks.filter(({ id }) =>
report.coverage.inapplicable_checks.includes(id),
),
).toEqual([]);
expect(JSON.stringify(evidence)).not.toContain(PLANTED_SOURCE);
const gated = await cli.run({
arguments: ["audit-release-exposure", root, "--fail_on", "high", "--json"],
@@ -191,7 +198,8 @@ cliTest(
expect(result.exitCode, result.stderr).toBe(0);
const report = outputSchema.parse(result.json).normalized_result;
expect(report.summary.no_exposure_observed_in_assessed_checks).toBe(true);
expect(report.summary.by_status.not_assessed).toBe(3);
expect(report.summary.by_status.not_assessed).toBe(1);
expect(report.checks.map(({ id }) => id)).toContain("android.manifest");
},
);
@@ -269,3 +277,48 @@ cliTest(
});
},
);
cliTest(
"omits checks that cannot apply to a single PE through CLI and MCP",
async ({ cli }) => {
const root = await createTestTempDirectory("rea-release-exposure-pe-");
const image = join(root, "app.exe");
await writeFile(
image,
pe(0x8664, 64, 2, false, { pdbPath: Buffer.from("C:\\b\\app.pdb") }),
);
const result = await cli.run({
arguments: ["audit-release-exposure", image, "--json"],
});
expect(result.exitCode, result.stderr).toBe(0);
const evidence = outputSchema.parse(result.json);
const report = evidence.normalized_result;
expect(report.target).toMatchObject({ kind: "executable", format: "pe" });
expect(report.coverage.inapplicable_checks).toEqual(
expect.arrayContaining([
"electron.run_as_node",
"electron.asar_integrity",
"electron.only_load_from_asar",
"electron.node_cli_inspect",
"macho.hardened_runtime",
"android.manifest",
]),
);
const reported = report.checks.map(({ id }) => id);
expect(reported).toContain("native.pdb_path");
expect(reported).toContain("native.hardening");
expect(
reported.filter((id) => report.coverage.inapplicable_checks.includes(id)),
).toEqual([]);
expect(report.checks.map(({ next_probe }) => next_probe)).not.toContain(
"inspect_electron_fuses",
);
expect(report.checks.map(({ next_probe }) => next_probe)).not.toContain(
"inspect_signature",
);
const { call } = await connectLocalToolsMcp();
const response = await call("audit_release_exposure", { path: image });
expect(response.isError, JSON.stringify(response)).not.toBe(true);
expectCliMcpEvidenceParity(evidence, response.structuredContent, image);
},
);