Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 13 additions & 11 deletions src/engine/wasm-seal-xor-known-plaintext-lint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ export interface WasmSealXorKnownPlaintextReport {
readonly findings: readonly WasmSealXorKnownPlaintextFinding[];
readonly looksExposed: boolean;
readonly shouldRefuseBankrupt: boolean;
/** True when the module was larger than the scan window (only a prefix was linted). */
readonly truncated?: boolean;
readonly oneLineAdvice: string;
}

Expand Down Expand Up @@ -226,18 +228,14 @@ export function lintWasmSealXorKnownPlaintextBuffer(
revisionPrefix,
);
}
if (buffer.length > MAX_SCAN_BYTES) {
return emptyReport(
pathLabel,
sealPath,
sha256Prefix,
"WASM too large for seal XOR known-plaintext lint.",
revisionPrefix,
);
}
// An oversized module is still linted over the window instead of skipped, so
// a caller that already holds the bytes never gets an empty report that reads
// like a clean scan.
const truncated = buffer.length > MAX_SCAN_BYTES;
const scanned = truncated ? buffer.subarray(0, MAX_SCAN_BYTES) : buffer;

const findings: WasmSealXorKnownPlaintextFinding[] = [];
const payloads = extractWasmDataPayloads(buffer);
const payloads = extractWasmDataPayloads(scanned);
for (const { memOff, payload } of payloads) {
const bases = [0];
if (payload.length > 256) bases.push(64, 128, 256);
Expand All @@ -262,9 +260,12 @@ export function lintWasmSealXorKnownPlaintextBuffer(

const looksExposed = findings.length > 0;
const shouldRefuseBankrupt = findings.some((f) => f.severity === "error");
const oneLineAdvice = shouldRefuseBankrupt
const advice = shouldRefuseBankrupt
? "ERROR: Do not place public seal.revision bytes under a repeating XOR mask in WASM data; use a one-way mask KDF (SHA-256) and keep public digests out of the masked plaintext prefix. Harden refuses unless allowWasmSealXorKnownPlaintext / --allow-wasm-seal-xor-known-plaintext / allow_wasm_seal_xor_known_plaintext."
: "No seal.revision-as-XOR-known-plaintext entitlement pack detected (heuristic).";
const oneLineAdvice = truncated
? `${advice} The scan window was truncated at ${MAX_SCAN_BYTES} bytes; the rest of the module was not linted.`
: advice;

return {
schema: WASM_SEAL_XOR_KNOWN_PLAINTEXT_SCHEMA,
Expand All @@ -275,6 +276,7 @@ export function lintWasmSealXorKnownPlaintextBuffer(
findings,
looksExposed,
shouldRefuseBankrupt,
...(truncated ? { truncated: true } : {}),
oneLineAdvice,
};
}
Expand Down
18 changes: 13 additions & 5 deletions src/engine/wasm-xor-mask-sidecar-lint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ export interface WasmXorMaskSidecarReport {
readonly looksExposed: boolean;
/** True when bankrupt harden/protect should refuse (error findings). */
readonly shouldRefuseBankrupt: boolean;
/** True when the module was larger than the scan window (only a prefix was linted). */
readonly truncated?: boolean;
readonly oneLineAdvice: string;
}

Expand Down Expand Up @@ -297,12 +299,14 @@ export function lintWasmXorMaskSidecarBuffer(
if (buffer.length < 8 || !buffer.subarray(0, 4).equals(WASM_MAGIC)) {
return emptyReport(pathLabel, sha256Prefix, "Not a WASM module — XOR-mask sidecar lint skipped.");
}
if (buffer.length > MAX_SCAN_BYTES) {
return emptyReport(pathLabel, sha256Prefix, "WASM too large for XOR-mask sidecar lint.");
}
// An oversized module is still linted over the window instead of skipped, so
// a caller that already holds the bytes never gets an empty report that reads
// like a clean scan.
const truncated = buffer.length > MAX_SCAN_BYTES;
const scanned = truncated ? buffer.subarray(0, MAX_SCAN_BYTES) : buffer;

const findings: WasmXorMaskSidecarFinding[] = [];
const payloads = extractWasmDataPayloads(buffer);
const payloads = extractWasmDataPayloads(scanned);
for (const { memOff, payload } of payloads) {
// Scan a few bases inside the payload (data@0 is the common case).
const bases = [0];
Expand All @@ -328,9 +332,12 @@ export function lintWasmXorMaskSidecarBuffer(

const looksExposed = findings.length > 0;
const shouldRefuseBankrupt = findings.some((f) => f.severity === "error");
const oneLineAdvice = shouldRefuseBankrupt
const advice = shouldRefuseBankrupt
? "ERROR: Prefer key-dependent unmask / omit plaintext XOR masks from WASM data; use one-way commitments instead of reversible expected words. Harden refuses unless allowWasmXorMaskSidecar / --allow-wasm-xor-mask-sidecar / allow_wasm_xor_mask_sidecar."
: "No XOR-mask-beside-blob entitlement pack detected in WASM data sections (heuristic).";
const oneLineAdvice = truncated
? `${advice} The scan window was truncated at ${MAX_SCAN_BYTES} bytes; the rest of the module was not linted.`
: advice;

return {
schema: WASM_XOR_MASK_SIDECAR_SCHEMA,
Expand All @@ -339,6 +346,7 @@ export function lintWasmXorMaskSidecarBuffer(
findings,
looksExposed,
shouldRefuseBankrupt,
...(truncated ? { truncated: true } : {}),
oneLineAdvice,
};
}
Expand Down
39 changes: 39 additions & 0 deletions tests/lint-scan-window-honesty.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,28 @@ import { lintJsAesUnwrapSource } from "../src/engine/js-aes-unwrap-lint.js";
import { lintJsWasmHydrateDumpSource } from "../src/engine/js-wasm-hydrate-dump-lint.js";
import { lintPanelDeriveAbiSource } from "../src/engine/panel-derive-abi-lint.js";
import { lintWasmParamCarrierBuffer } from "../src/engine/wasm-param-carrier-lint.js";
import { lintWasmXorMaskSidecarBuffer } from "../src/engine/wasm-xor-mask-sidecar-lint.js";
import { lintWasmSealXorKnownPlaintextBuffer } from "../src/engine/wasm-seal-xor-known-plaintext-lint.js";

/** A valid module just over the 32 MiB scan window (one oversized custom section). */
function oversizedWasm(): Buffer {
const payload = Buffer.alloc(32 * 1024 * 1024);
payload[0] = 1; // custom-section name length
payload[1] = 0x78; // "x"
const size: number[] = [];
let value = payload.length >>> 0;
do {
let byte = value & 0x7f;
value >>>= 7;
if (value) byte |= 0x80;
size.push(byte);
} while (value);
return Buffer.concat([
Buffer.from([0x00, 0x61, 0x73, 0x6d, 0x01, 0x00, 0x00, 0x00]),
Buffer.from([0x00, ...size]),
payload,
]);
}

describe("lint scan-window honesty", () => {
it("reports the window when the JS AES lint truncates", () => {
Expand All @@ -28,4 +50,21 @@ describe("lint scan-window honesty", () => {
expect(report.truncated).toBe(true);
expect(report.oneLineAdvice).toMatch(/window|truncat/i);
});

it("reports the window when the WASM XOR-mask lint truncates", () => {
const report = lintWasmXorMaskSidecarBuffer(oversizedWasm(), { path: "oversized.wasm" });
expect(report.truncated).toBe(true);
expect(report.oneLineAdvice).toMatch(/window|truncat/i);
expect(report.shouldRefuseBankrupt).toBe(false);
});

it("reports the window when the WASM seal-XOR lint truncates", () => {
const report = lintWasmSealXorKnownPlaintextBuffer(oversizedWasm(), {
path: "oversized.wasm",
sealRaw: JSON.stringify({ revision: "ab".repeat(32) }),
});
expect(report.truncated).toBe(true);
expect(report.oneLineAdvice).toMatch(/window|truncat/i);
expect(report.shouldRefuseBankrupt).toBe(false);
});
});
Loading