Skip to content

armgit / bla

Public Imported from GitHub
0

🛡️ BLA (Blind LLM Agents) — Adversarial defense shield that protects binaries, Electron apps, JS bundles, Python, and WebAssembly against AI reverse-engineering agents like REA. Poison -> Exhaust -> Hallucinate.

feat(redteam): cover ASAR/WASM/SQLite/fuses; soft-skip CI without REA

qybaihe31b2e036e3f4
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index df5c424..0e85b81 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -42,7 +42,7 @@ jobs:
- name: Run unit & multi-format shield tests
run: npm test
- - name: Run 8-target Counter-REA showcase benchmark
+ - name: Run Counter-REA showcase benchmark
run: npm run benchmark
- name: Verify CLI doctor & update commands
@@ -50,3 +50,39 @@ jobs:
node dist/cli.js --version
node dist/cli.js doctor --json
node dist/cli.js update --json
+
+ - name: Detect sibling REA checkout (optional)
+ id: rea
+ shell: bash
+ run: |
+ # Sibling checkout patterns: ../rea (monorepo-style) or $REA_ROOT.
+ REA_CANDIDATE="${REA_ROOT:-$(dirname "$GITHUB_WORKSPACE")/rea}"
+ if [ -d "$REA_CANDIDATE/src" ]; then
+ echo "present=true" >> "$GITHUB_OUTPUT"
+ echo "root=$REA_CANDIDATE" >> "$GITHUB_OUTPUT"
+ echo "Sibling REA found at $REA_CANDIDATE"
+ else
+ echo "present=false" >> "$GITHUB_OUTPUT"
+ echo "root=" >> "$GITHUB_OUTPUT"
+ echo "No sibling REA checkout — verify:rea / redteam:rea will skip with notice."
+ fi
+
+ - name: Verify REA constant alignment (skip if REA absent)
+ env:
+ REA_ROOT: ${{ steps.rea.outputs.root }}
+ run: npm run verify:rea
+
+ - name: Empirical REA red-team (skip if REA absent)
+ env:
+ REA_ROOT: ${{ steps.rea.outputs.root }}
+ run: |
+ if [ "${{ steps.rea.outputs.present }}" != "true" ]; then
+ echo "SKIP: npm run redteam:rea (sibling REA not checked out alongside BLA)"
+ exit 0
+ fi
+ # Ensure REA dist is built when the sibling tree is present.
+ if [ ! -f "${REA_ROOT}/dist/go/GoBinaryImage.js" ]; then
+ echo "Building REA dist for red-team…"
+ (cd "$REA_ROOT" && npm install --ignore-scripts && npx tsc -p tsconfig.build.json)
+ fi
+ npm run redteam:rea
diff --git a/scripts/redteam/lib/probes.mjs b/scripts/redteam/lib/probes.mjs
index a8e2987..80c49ec 100644
--- a/scripts/redteam/lib/probes.mjs
+++ b/scripts/redteam/lib/probes.mjs
@@ -143,6 +143,30 @@ export async function loadReaProbes() {
resolveReaDist("model/ModelHeaderReader.js")
);
const { GgufHeader } = await import(resolveReaDist("model/GgufHeader.js"));
+ const { admitAsarHeader } = await import(
+ resolveReaDist("artifacts/AsarHeader.js")
+ );
+ const { readAsarListing } = await import(
+ resolveReaDist("artifacts/AsarListing.js")
+ );
+ const { WasmInterfaceBudget } = await import(
+ resolveReaDist("wasm/WasmInterfaceBudget.js")
+ );
+ const { wasmInterfaceEntryRepresentationBytes, WASM_INTERFACE_REPRESENTATION_BYTES } =
+ await import(resolveReaDist("domain/wasm/wasmInterface.js"));
+ const { readElectronFuseImage, ELECTRON_FUSE_LIMITS, ElectronFuseResourceFailure } =
+ await import(resolveReaDist("electron/ElectronFuseReader.js"));
+ let inspectSqliteDatabaseSnapshot = null;
+ let SqliteInspectionFailure = null;
+ try {
+ const sqliteMod = await import(
+ resolveReaDist("sqlite/SqliteDatabaseInspection.js")
+ );
+ inspectSqliteDatabaseSnapshot = sqliteMod.inspectSqliteDatabaseSnapshot;
+ SqliteInspectionFailure = sqliteMod.SqliteInspectionFailure;
+ } catch {
+ /* optional */
+ }
return {
readGoBinaryImage,
parseErlangBeam,
@@ -158,6 +182,16 @@ export async function loadReaProbes() {
readSafetensorsHeader,
ModelHeaderReader,
GgufHeader,
+ admitAsarHeader,
+ readAsarListing,
+ WasmInterfaceBudget,
+ wasmInterfaceEntryRepresentationBytes,
+ WASM_INTERFACE_REPRESENTATION_BYTES,
+ readElectronFuseImage,
+ ELECTRON_FUSE_LIMITS,
+ ElectronFuseResourceFailure,
+ inspectSqliteDatabaseSnapshot,
+ SqliteInspectionFailure,
};
}
@@ -413,6 +447,214 @@ export async function probePtx(_rea, bytes, phase) {
return base;
}
+
+export async function probeAsar(rea, bytes, phase) {
+ const base = outcomeBase("electron_asar", phase, bytes);
+ const dir = mkdtempSync(join(tmpdir(), "bla-rt-asar-"));
+ const path = join(dir, `${phase}.asar`);
+ writeFileSync(path, bytes);
+ try {
+ const fh = await open(path, "r");
+ try {
+ const extents = await rea.admitAsarHeader(fh);
+ base.metrics.headerBytes = extents.headerBytes;
+ base.metrics.archiveBytes = extents.archiveBytes;
+ base.metrics.jsonBytes = extents.jsonBytes ?? extents.headerBytes - 8;
+ // Read JSON header for listing
+ const jsonBuf = Buffer.alloc(extents.headerBytes);
+ // header layout: 8 byte size pickle + headerBytes pickle payload; JSON starts at 16
+ const headerRegion = Buffer.alloc(8 + extents.headerBytes);
+ let off = 0;
+ while (off < headerRegion.length) {
+ const { bytesRead } = await fh.read(
+ headerRegion,
+ off,
+ headerRegion.length - off,
+ off,
+ );
+ if (bytesRead === 0) break;
+ off += bytesRead;
+ }
+ const jsonSize = headerRegion.readUInt32LE(12);
+ const json = headerRegion.subarray(16, 16 + jsonSize).toString("utf8");
+ const root = JSON.parse(json);
+ const listing = await rea.readAsarListing(root);
+ base.metrics.listingEntries = listing.length;
+ base.metrics.listingPathBytes = listing.reduce(
+ (s, e) => s + (e.path?.length ?? 0),
+ 0,
+ );
+ } finally {
+ await fh.close();
+ }
+ } catch (err) {
+ const msg = String(err?.message ?? err);
+ const isHeader =
+ /header/i.test(msg) ||
+ err?.constructor?.name?.includes("Asar") ||
+ /max_header|admission/i.test(msg);
+ failOutcome(
+ base,
+ err,
+ isHeader ? "DEFAULT_ASAR_MAX_HEADER_BYTES" : err?.kind ?? "asar",
+ );
+ if (isHeader || /exceeds its .* representation budget/i.test(msg)) {
+ base.budgetHit = true;
+ base.budgetName = /listing|representation/i.test(msg)
+ ? "ASAR_LISTING_BYTES"
+ : "DEFAULT_ASAR_MAX_HEADER_BYTES";
+ }
+ }
+ return base;
+}
+
+export async function probeWasm(rea, bla, bytes, phase, sampleMeta = {}) {
+ const base = outcomeBase("wasm_module", phase, bytes);
+ try {
+ const valid = WebAssembly.validate(bytes);
+ const inspection = bla.inspectWasmBinary(bytes);
+ base.metrics = {
+ validates: valid,
+ sectionCount: inspection.sectionCount,
+ customSectionNames: inspection.customSectionNames,
+ exportNames: inspection.exportNames,
+ importCount: inspection.importCount,
+ projectedChargeBytes: sampleMeta.projectedInterfaceChargeBytes ?? null,
+ representationBudget: rea.WASM_INTERFACE_REPRESENTATION_BYTES,
+ descriptorCount: sampleMeta.interfaceDescriptorsEmbedded ?? null,
+ exceedsRepresentationBudget:
+ sampleMeta.exceedsRepresentationBudget === true,
+ };
+ // Exercise REA's real WasmInterfaceBudget class. Full Wabt WAT decode is
+ // tool-backed (see unverified); we reserve using the same charge formula
+ // BLA embeds for the hardened sample's exhaustion plan.
+ if (phase === "after" && sampleMeta.exceedsRepresentationBudget) {
+ const plan = bla.planWasmInterfaceBudgetExhaustion(
+ new bla.SeededPrng("bla-redteam-empirical-v1"),
+ "bankrupt",
+ );
+ const budget = new rea.WasmInterfaceBudget();
+ let charged = 0;
+ for (const d of plan.descriptors) {
+ const entry = {
+ direction: "export",
+ module: d.moduleName,
+ name: d.exportName,
+ wat_form: `(func $${d.exportName} (param ${"i64 ".repeat(d.paramCount).trim()}) (result ${"i64 ".repeat(d.resultCount).trim()}))`,
+ issue: null,
+ signature: {
+ kind: "func",
+ params: Array(d.paramCount).fill("i64"),
+ results: Array(d.resultCount).fill("i64"),
+ },
+ };
+ try {
+ const cost = rea.wasmInterfaceEntryRepresentationBytes(entry);
+ budget.reserve(cost);
+ charged += cost;
+ } catch (err) {
+ base.metrics.chargeWhenTripped = charged;
+ failOutcome(base, err, "WASM_INTERFACE_REPRESENTATION_BYTES");
+ base.status = "budget_rejected";
+ base.budgetHit = true;
+ base.budgetName = "WASM_INTERFACE_REPRESENTATION_BYTES";
+ base.redactionOrAmbiguity =
+ "WasmInterfaceBudget refused projected interface inventory (Wabt E2E needs REA_WABT_BIN_DIRECTORY)";
+ return base;
+ }
+ }
+ base.metrics.chargedBytes = charged;
+ if (plan.exceedsRepresentationBudget) {
+ base.budgetHit = true;
+ base.budgetName = "WASM_INTERFACE_REPRESENTATION_BYTES";
+ base.status = "budget_rejected";
+ base.redactionOrAmbiguity =
+ "Plan exceeds representation budget; reserve loop did not trip (charge formula drift?)";
+ }
+ }
+ } catch (err) {
+ failOutcome(base, err);
+ }
+ return base;
+}
+
+export async function probeSqlite(rea, bla, bytes, phase) {
+ const base = outcomeBase("sqlite_db", phase, bytes);
+ if (!bytes.length) {
+ base.status = "skipped";
+ base.redactionOrAmbiguity = "sqlite sample unavailable (node:sqlite)";
+ return base;
+ }
+ // BLA evidence surface (honey tables / canaries) always measurable via node:sqlite.
+ try {
+ const inspection = bla.inspectSqliteBuffer(bytes);
+ base.metrics.blaHoneyTables = inspection.honeyTablesCount;
+ base.metrics.blaTableCount = inspection.tableNames?.length ?? inspection.tables?.length;
+ base.metrics.blaProtected = inspection.blaProtected === true;
+ } catch (err) {
+ base.metrics.blaInspectError = String(err?.message ?? err).slice(0, 160);
+ }
+ // REA inspectSqliteDatabaseSnapshot needs DatabaseSync.limits (Node 24.15+/26+).
+ if (typeof rea.inspectSqliteDatabaseSnapshot !== "function") {
+ base.redactionOrAmbiguity =
+ "REA SqliteDatabaseInspection module not loadable";
+ return base;
+ }
+ const dir = mkdtempSync(join(tmpdir(), "bla-rt-sqlite-"));
+ const path = join(dir, `${phase}.sqlite`);
+ writeFileSync(path, bytes);
+ try {
+ const result = rea.inspectSqliteDatabaseSnapshot(path, {
+ schema: true,
+ rows: { limit: 16 },
+ });
+ base.metrics.reaTables = result?.schema?.tables?.length ?? result?.tables?.length;
+ base.metrics.reaLimitations = (result?.limitations ?? []).slice(0, 3);
+ } catch (err) {
+ const msg = String(err?.message ?? err);
+ if (/DatabaseSync\.limits|24\.15|unavailable/i.test(msg)) {
+ base.status = "capability_gated";
+ base.redactionOrAmbiguity =
+ "REA SQLite inspection requires Node.js 24.15+ / 26+ DatabaseSync.limits; honey/canary evidence recorded via BLA inspect instead";
+ base.errorName = err?.constructor?.name ?? "SqliteInspectionFailure";
+ base.errorMessage = msg.slice(0, 240);
+ } else {
+ failOutcome(base, err);
+ }
+ }
+ return base;
+}
+
+export async function probeElectronFuses(rea, bytes, phase) {
+ const base = outcomeBase("electron_fuses", phase, bytes);
+ const dir = mkdtempSync(join(tmpdir(), "bla-rt-fuse-"));
+ const path = join(dir, `${phase}.elf`);
+ writeFileSync(path, bytes);
+ try {
+ const image = await rea.readElectronFuseImage(path);
+ base.metrics.sentinelCount = image?.sentinels?.length ?? image?.sentinel_count;
+ base.metrics.sliceCount = image?.slices?.length;
+ } catch (err) {
+ const msg = String(err?.message ?? err);
+ const isCap =
+ err?.constructor?.name === "ElectronFuseResourceFailure" ||
+ /more than \d+ Electron fuse sentinels/i.test(msg) ||
+ err?.capacity === "capacity" ||
+ /capacity/i.test(String(err?.boundary ?? err?.kind ?? ""));
+ failOutcome(
+ base,
+ err,
+ isCap ? "ELECTRON_FUSE_LIMITS.maximumSentinelsPerSlice" : null,
+ );
+ if (isCap) {
+ base.budgetHit = true;
+ base.budgetName = "ELECTRON_FUSE_LIMITS.maximumSentinelsPerSlice";
+ base.status = "budget_rejected";
+ }
+ }
+ return base;
+}
+
/** Catalog of analyzers that cannot run empirically on this box. */
export function unverifiedAnalyzers() {
return [
@@ -439,7 +681,17 @@ export function unverifiedAnalyzers() {
{
analyzer: "EVM EVMole worker full interface recovery",
reason:
- "worker subprocess/path not exercised end-to-end; inputBytes budget checked in-process",
+ "Not pathable in-process: EvmoleInterfaceWorker refuses library import ('Owned worker request path missing') and only runs under REA's owned subprocess launcher (prlimit address-space/CPU/file-size, 256 MiB heap, IPC reply schema). The evmole npm package exists in the REA tree but cannot be driven without that ownership harness. inputBytes (4 MiB) admission is checked in-process via probeEvm.",
+ },
+ {
+ analyzer: "WASM Wabt full WAT decode (wasm-objdump / wasm2wat)",
+ reason:
+ "Requires REA_WABT_BIN_DIRECTORY with WABT 1.0.42 tools; not installed here. In-process WasmInterfaceBudget is exercised with BLA's projected interface-exhaustion descriptors.",
+ },
+ {
+ analyzer: "SQLite inspect_sqlite_database (full REA worker)",
+ reason:
+ "REA inspectSqliteDatabaseSnapshot requires Node.js DatabaseSync.limits (24.15+ / 26+). This box runs Node 22.23.4 where limits is absent; honey tables/canaries are still verified via BLA inspectSqliteBuffer + node:sqlite.",
},
{
analyzer: "SPIR-V / CUDA fatbinary / AMD GPU object",
diff --git a/scripts/redteam/lib/report.mjs b/scripts/redteam/lib/report.mjs
index 6782eea..b7af8d9 100644
--- a/scripts/redteam/lib/report.mjs
+++ b/scripts/redteam/lib/report.mjs
@@ -121,6 +121,50 @@ function compareToEstimates(pair) {
"PTX is text-scanned only; REA GPU object decode needs native tooling (not empirically verified for fatbin/SPIR-V)",
);
}
+ if (format === "electron_asar") {
+ const expect = sampleMeta?.exceedsDefaultAdmission === true;
+ const hit = after.budgetHit === true;
+ notes.push(
+ hit === expect
+ ? `AGREE with BLA exceedsDefaultAdmission=${expect} (header after metrics=${after.metrics?.headerBytes ?? after.errorMessage})`
+ : `DIVERGE: BLA exceedsDefaultAdmission=${expect}, empirical budgetHit=${hit} (${after.budgetName ?? after.errorName})`,
+ );
+ }
+ if (format === "wasm_module") {
+ const expect = sampleMeta?.exceedsRepresentationBudget === true;
+ const hit = after.budgetHit === true;
+ notes.push(
+ hit === expect
+ ? `AGREE with BLA exceedsRepresentationBudget=${expect} (projected=${sampleMeta?.projectedInterfaceChargeBytes})`
+ : `DIVERGE: BLA exceeds=${expect}, empirical budgetHit=${hit}`,
+ );
+ notes.push(
+ "Full Wabt WAT decode is tool-backed; in-process WasmInterfaceBudget reserved with projected descriptors",
+ );
+ }
+ if (format === "sqlite_db") {
+ notes.push(
+ after.status === "capability_gated"
+ ? "NOTED: REA SQLite inspection capability-gated on Node <24.15; BLA honey/canary evidence recorded"
+ : after.budgetHit
+ ? `empirical budgetHit=${after.budgetName}`
+ : `empirical status=${after.status}; honeyTables=${after.metrics?.blaHoneyTables}`,
+ );
+ if ((sampleMeta?.honeyTablesInjected ?? 0) > 0) {
+ notes.push(
+ `AGREE: BLA honeyTablesInjected=${sampleMeta.honeyTablesInjected}, canaryTokens=${sampleMeta.canaryTokensEmbedded}`,
+ );
+ }
+ }
+ if (format === "electron_fuses") {
+ const expect = (sampleMeta?.electronFuseSentinelsInjected ?? 0) > 32;
+ const hit = after.budgetHit === true;
+ notes.push(
+ hit === expect
+ ? `AGREE: decoy sentinels ${sampleMeta?.electronFuseSentinelsInjected} > maximumSentinelsPerSlice=32`
+ : `DIVERGE: injected=${sampleMeta?.electronFuseSentinelsInjected}, empirical budgetHit=${hit} (${after.budgetName ?? after.errorName})`,
+ );
+ }
// Before should generally NOT hit budgets
if (before.budgetHit && format !== "gpu_ptx") {
notes.push(
@@ -153,7 +197,7 @@ export function buildReportDocument(run) {
? "agree"
: cmp.some((c) => c.startsWith("DIVERGE"))
? "diverge"
- : cmp.some((c) => c.startsWith("SKIPPED") || c.startsWith("EXPECTED") || c.startsWith("PTX"))
+ : cmp.some((c) => c.startsWith("SKIPPED") || c.startsWith("EXPECTED") || c.startsWith("PTX") || c.startsWith("NOTED") || c.startsWith("Full Wabt"))
? "noted"
: "—";
lines.push(
diff --git a/scripts/redteam/lib/samples.mjs b/scripts/redteam/lib/samples.mjs
index 77f3f8e..b132413 100644
--- a/scripts/redteam/lib/samples.mjs
+++ b/scripts/redteam/lib/samples.mjs
@@ -29,6 +29,26 @@ export async function loadBla() {
protectSafetensorsBuffer: (await import(join(base, "model.js")))
.protectSafetensorsBuffer,
protectGgufBuffer: (await import(join(base, "model.js"))).protectGgufBuffer,
+ packAsarBuffer: (await import(join(base, "asar.js"))).packAsarBuffer,
+ unpackAsarBuffer: (await import(join(base, "asar.js"))).unpackAsarBuffer,
+ protectWasmBinary: (await import(join(base, "wasm.js"))).protectWasmBinary,
+ inspectWasmBinary: (await import(join(base, "wasm.js"))).inspectWasmBinary,
+ protectSqliteBuffer: (await import(join(base, "sqlite.js"))).protectSqliteBuffer,
+ buildSampleSqliteDatabase: (await import(join(base, "sqlite.js")))
+ .buildSampleSqliteDatabase,
+ inspectSqliteBuffer: (await import(join(base, "sqlite.js"))).inspectSqliteBuffer,
+ inspectElectronFusesBuffer: (
+ await import(join(base, "electron-fuses.js"))
+ ).inspectElectronFusesBuffer,
+ planAsarHeaderAmplification: (
+ await import(join(BLA_ROOT, "dist/shields/exhaustion/asar-header-amplifier.js"))
+ ).planAsarHeaderAmplification,
+ planWasmInterfaceBudgetExhaustion: (
+ await import(
+ join(BLA_ROOT, "dist/shields/exhaustion/wasm-interface-exhaustion.js")
+ )
+ ).planWasmInterfaceBudgetExhaustion,
+ SeededPrng: (await import(join(BLA_ROOT, "dist/core/prng.js"))).SeededPrng,
REA_INTERNAL_LIMITS: (await import(join(BLA_ROOT, "dist/identity.js")))
.REA_INTERNAL_LIMITS,
};
@@ -129,6 +149,40 @@ export function buildMinimalGguf() {
return b;
}
+
+/** Minimal Electron ASAR with package.json + main.js. */
+export function buildMinimalAsar(bla) {
+ return bla.packAsarBuffer([
+ {
+ relativePath: "package.json",
+ content: Buffer.from(
+ JSON.stringify({ name: "redteam-asar", main: "main.js" }),
+ "utf8",
+ ),
+ },
+ {
+ relativePath: "main.js",
+ content: Buffer.from(
+ "exports.ping = function ping() { return 42; };\n",
+ "utf8",
+ ),
+ },
+ ]);
+}
+
+/** Minimal valid WASM exporting computeDigest(i32,i32)->i32. */
+export function buildMinimalWasm() {
+ return Buffer.from([
+ 0x00, 0x61, 0x73, 0x6d, 0x01, 0x00, 0x00, 0x00,
+ 0x01, 0x07, 0x01, 0x60, 0x02, 0x7f, 0x7f, 0x01, 0x7f,
+ 0x03, 0x02, 0x01, 0x00,
+ 0x07, 0x11, 0x01, 0x0d,
+ 0x63, 0x6f, 0x6d, 0x70, 0x75, 0x74, 0x65, 0x44, 0x69, 0x67, 0x65, 0x73, 0x74,
+ 0x00, 0x00,
+ 0x0a, 0x0c, 0x01, 0x0a, 0x00, 0x20, 0x00, 0x20, 0x01, 0x73, 0x41, 0x2a, 0x6a, 0x0b,
+ ]);
+}
+
/**
* Build the red-team sample matrix: one entry per empirically runnable format.
*/
@@ -166,6 +220,45 @@ export async function buildSampleMatrix() {
ggufHard = { buffer: ggufRaw, error: String(err?.message ?? err) };
}
+ // Electron ASAR — densify header past DEFAULT_ASAR_MAX_HEADER_BYTES (16 MiB).
+ const asarRaw = buildMinimalAsar(bla);
+ const asarFiles = [...bla.unpackAsarBuffer(asarRaw)];
+ const asarPlan = bla.planAsarHeaderAmplification(
+ new bla.SeededPrng(`${seed}:asar`),
+ intensity,
+ );
+ for (const decoy of asarPlan.files) asarFiles.push(decoy);
+ const asarHard = {
+ buffer: bla.packAsarBuffer(asarFiles),
+ decoyFiles: asarPlan.files.length,
+ estimatedHeaderBytes: asarPlan.estimatedHeaderBytes,
+ exceedsDefaultAdmission: asarPlan.exceedsDefaultAdmission,
+ };
+
+ // WASM — bankrupt interface exhaustion past 32 MiB representation budget.
+ const wasmRaw = buildMinimalWasm();
+ const wasmHard = bla.protectWasmBinary(wasmRaw, { intensity, seed });
+
+ // SQLite — honey tables + canaries (REA inspect is Node 24.15+ gated).
+ let sqliteRaw = Buffer.alloc(0);
+ let sqliteHard = {
+ buffer: Buffer.alloc(0),
+ error: null,
+ honeyTablesInjected: 0,
+ canaryTokensEmbedded: 0,
+ };
+ try {
+ sqliteRaw = bla.buildSampleSqliteDatabase();
+ sqliteHard = bla.protectSqliteBuffer(sqliteRaw, { intensity, seed });
+ } catch (err) {
+ sqliteHard = {
+ buffer: sqliteRaw,
+ error: String(err?.message ?? err),
+ honeyTablesInjected: 0,
+ canaryTokensEmbedded: 0,
+ };
+ }
+
return {
bla,
intensity,
@@ -235,6 +328,46 @@ export async function buildSampleMatrix() {
ggufHard.triggeredMetadataNestingBreaker === true,
},
},
+ electron_asar: {
+ format: "electron_asar",
+ before: asarRaw,
+ after: asarHard.buffer,
+ meta: {
+ decoyFiles: asarHard.decoyFiles,
+ estimatedHeaderBytes: asarHard.estimatedHeaderBytes,
+ exceedsDefaultAdmission: asarHard.exceedsDefaultAdmission,
+ },
+ },
+ wasm_module: {
+ format: "wasm_module",
+ before: wasmRaw,
+ after: wasmHard.buffer,
+ meta: {
+ customSectionsAdded: wasmHard.customSectionsAdded,
+ interfaceDescriptorsEmbedded: wasmHard.interfaceDescriptorsEmbedded,
+ projectedInterfaceChargeBytes: wasmHard.projectedInterfaceChargeBytes,
+ exceedsRepresentationBudget: wasmHard.exceedsRepresentationBudget,
+ },
+ },
+ sqlite_db: {
+ format: "sqlite_db",
+ before: sqliteRaw,
+ after: sqliteHard.buffer,
+ meta: {
+ error: sqliteHard.error,
+ honeyTablesInjected: sqliteHard.honeyTablesInjected,
+ canaryTokensEmbedded: sqliteHard.canaryTokensEmbedded,
+ },
+ },
+ electron_fuses: {
+ // Same hardened ELF carries decoy Electron fuse sentinels (34 > 32).
+ format: "electron_fuses",
+ before: elfRaw,
+ after: elfHard.buffer,
+ meta: {
+ electronFuseSentinelsInjected: elfHard.electronFuseSentinelsInjected,
+ },
+ },
},
};
}
diff --git a/scripts/redteam/run.mjs b/scripts/redteam/run.mjs
index 2e88ef1..ebc1131 100755
--- a/scripts/redteam/run.mjs
+++ b/scripts/redteam/run.mjs
@@ -21,6 +21,10 @@ import {
probeSafetensors,
probeGguf,
probePtx,
+ probeAsar,
+ probeWasm,
+ probeSqlite,
+ probeElectronFuses,
unverifiedAnalyzers,
} from "./lib/probes.mjs";
import { writeReports } from "./lib/report.mjs";
@@ -34,10 +38,11 @@ function tsharkVersion(env) {
async function main() {
if (!reaDistReady()) {
- console.error(
- "REA dist not ready. From /workspace/bla-dev/rea under Node 22.23.4+:\n npm install --ignore-scripts && npx tsc -p tsconfig.build.json",
+ console.log(
+ "SKIP: sibling REA dist not ready (expected at ../rea or $REA_ROOT). " +
+ "Red-team empirical gates require a local REA checkout; CI skips when absent.",
);
- process.exit(2);
+ process.exit(0);
}
const tshark = resolveTsharkEnv();
const { bla, intensity, seed, samples } = await buildSampleMatrix();
@@ -135,6 +140,51 @@ async function main() {
});
}
+
+ {
+ const s = samples.electron_asar;
+ pairs.push({
+ format: "electron_asar",
+ before: await probeAsar(rea, s.before, "before"),
+ after: await probeAsar(rea, s.after, "after"),
+ sampleMeta: s.meta,
+ blaLimits: limits,
+ });
+ }
+
+ {
+ const s = samples.wasm_module;
+ pairs.push({
+ format: "wasm_module",
+ before: await probeWasm(rea, bla, s.before, "before", s.meta),
+ after: await probeWasm(rea, bla, s.after, "after", s.meta),
+ sampleMeta: s.meta,
+ blaLimits: limits,
+ });
+ }
+
+ {
+ const s = samples.sqlite_db;
+ pairs.push({
+ format: "sqlite_db",
+ before: await probeSqlite(rea, bla, s.before, "before"),
+ after: await probeSqlite(rea, bla, s.after, "after"),
+ sampleMeta: s.meta,
+ blaLimits: limits,
+ });
+ }
+
+ {
+ const s = samples.electron_fuses;
+ pairs.push({
+ format: "electron_fuses",
+ before: await probeElectronFuses(rea, s.before, "before"),
+ after: await probeElectronFuses(rea, s.after, "after"),
+ sampleMeta: s.meta,
+ blaLimits: limits,
+ });
+ }
+
const run = {
generatedAt: new Date().toLocaleString("en-CA", {
timeZone: "Asia/Shanghai",
@@ -176,6 +226,9 @@ async function main() {
"evm_bytecode",
"pcap_capture",
"gguf",
+ "electron_asar",
+ "wasm_module",
+ "electron_fuses",
]);
if (!must.has(p.format)) return false;
if (p.format === "pcap_capture" && p.after.status === "skipped") return false;
diff --git a/scripts/verify-rea-constants.mjs b/scripts/verify-rea-constants.mjs
index 6cb007b..18e5a00 100755
--- a/scripts/verify-rea-constants.mjs
+++ b/scripts/verify-rea-constants.mjs
@@ -10,7 +10,8 @@
* node scripts/verify-rea-constants.mjs
* REA_ROOT=/path/to/rea node scripts/verify-rea-constants.mjs
*
- * Exit code 0 = all asserted constants match; 1 = drift detected or REA missing.
+ * Exit code 0 = all asserted constants match, OR sibling REA absent (soft-skip).
+ * Exit code 1 = drift detected when REA is present.
*/
import { existsSync, readFileSync, readdirSync, statSync } from "node:fs";
import { dirname, join, resolve } from "node:path";
@@ -243,8 +244,11 @@ function main() {
console.log(` REA_ROOT = ${REA_ROOT}`);
if (!existsSync(REA_ROOT) || !existsSync(join(REA_ROOT, "src"))) {
- console.error("\nFAIL REA checkout not found. Clone morluto/rea next to bla or set REA_ROOT.");
- process.exit(1);
+ console.log(
+ `SKIP: sibling REA checkout not found at ${REA_ROOT}. ` +
+ "verify:rea requires a local REA tree; CI skips when absent.",
+ );
+ process.exit(0);
}
const files = [
diff --git a/tests/deception-workflows.test.ts b/tests/deception-workflows.test.ts
index 8921d94..a97aebf 100644
--- a/tests/deception-workflows.test.ts
+++ b/tests/deception-workflows.test.ts
@@ -35,7 +35,8 @@ describe("Prompt Completion, Version Diff, Crash Trace & Regex/ASAR Shields", ()
expect(regex.nearMissCandidatesGenerated).toBe(64);
const asarFiles = generateAsarHeaderDecoyFiles(prng, "bankrupt");
- expect(asarFiles).toHaveLength(24);
+ expect(asarFiles.length).toBeGreaterThan(1000);
+ expect(asarFiles).toHaveLength(4000);
expect(asarFiles[0]!.relativePath).toContain("enclave/shards/");
});
});
diff --git a/tests/exhaustion-suite.test.ts b/tests/exhaustion-suite.test.ts
index 78b652a..a09a2e8 100644
--- a/tests/exhaustion-suite.test.ts
+++ b/tests/exhaustion-suite.test.ts
@@ -53,8 +53,10 @@ describe("Counter-REA Resource Exhaustion Suite", () => {
expect(bpe.tokensPerByteRatio).toBeGreaterThanOrEqual(0.55);
const wasmPlan = planWasmInterfaceBudgetExhaustion(prng, "bankrupt");
- expect(wasmPlan.descriptors.length).toBe(72);
- expect(wasmPlan.byteAmplificationFactor).toBeGreaterThan(15);
+ expect(wasmPlan.descriptors.length).toBe(128);
+ expect(wasmPlan.exceedsRepresentationBudget).toBe(true);
+ expect(wasmPlan.byteAmplificationFactor).toBeGreaterThan(5);
+ expect(wasmPlan.totalReaChargedBytes).toBeGreaterThan(32 * 1024 * 1024);
expect(
computeReaWasmInterfaceCharge({
moduleName: "enclave",
diff --git a/tests/multi-format-shields.test.ts b/tests/multi-format-shields.test.ts
index b2d3d2b..b9824c7 100644
--- a/tests/multi-format-shields.test.ts
+++ b/tests/multi-format-shields.test.ts
@@ -38,7 +38,9 @@ describe("Multi-Format Shields (WASM, Python, Native ELF/Mach-O/PE, C/Rust/Go He
intensity: "balanced",
seed: "wasm-test-seed",
});
- expect(protectedRes.customSectionsAdded).toBe(8);
+ expect(protectedRes.customSectionsAdded).toBe(9);
+ // balanced intensity stays under the 32 MiB REA interface budget; bankrupt exceeds.
+ expect(protectedRes.exceedsRepresentationBudget).toBe(false);
expect(protectedRes.canaryTokensEmbedded).toBeGreaterThanOrEqual(2);
expect(protectedRes.diagnosticsEmbedded).toBeGreaterThanOrEqual(2);
expect(protectedRes.chaffPayloadsEmbedded).toBeGreaterThanOrEqual(4);
diff --git a/tests/redteam-harness.test.ts b/tests/redteam-harness.test.ts
index 6fd6171..a8fb74f 100644
--- a/tests/redteam-harness.test.ts
+++ b/tests/redteam-harness.test.ts
@@ -18,7 +18,7 @@ const samplesPath = join(process.cwd(), "scripts/redteam/lib/samples.mjs");
const probesPath = join(process.cwd(), "scripts/redteam/lib/probes.mjs");
describe("red-team harness sample generators", () => {
- it("builds minimal BEAM / EVM / PCAP / GGUF / PTX fixtures with expected magic", async () => {
+ it("builds minimal BEAM / EVM / PCAP / GGUF / PTX / WASM fixtures with expected magic", async () => {
const samples = await import(samplesPath);
const beam = samples.buildMinimalBeam();
expect(beam.subarray(0, 4).toString("latin1")).toBe("FOR1");
@@ -38,6 +38,10 @@ describe("red-team harness sample generators", () => {
const ptx = samples.buildMinimalPtx().toString("utf8");
expect(ptx).toContain(".entry demo");
+
+ const wasm = samples.buildMinimalWasm();
+ expect([...wasm.subarray(0, 4)]).toEqual([0x00, 0x61, 0x73, 0x6d]);
+ expect(WebAssembly.validate(wasm)).toBe(true);
});
it("projectStringPoolReaFaithful reports wouldCap past REA URI/token limits", async () => {
@@ -68,7 +72,7 @@ describe("red-team harness sample generators", () => {
describe("mapped Go/Flutter plants vs REA pool caps", () => {
it("mapped Flutter isolate plant exceeds per-kind MAX_POOL_URIS and MAX_POOL_TOKENS", () => {
const plant = buildMappedFlutterIsolatePoolPlant(
- 160 * 1024,
+ 48 * 1024,
new SeededPrng("redteam-flutter-cap"),
);
// packageAndDartUris counts both kinds; each alone must clear 500.
@@ -107,3 +111,44 @@ describe("mapped Go/Flutter plants vs REA pool caps", () => {
);
});
});
+
+describe("ASAR header amplification vs REA admission", () => {
+ it("bankrupt plan exceeds DEFAULT_ASAR_MAX_HEADER_BYTES (16 MiB)", async () => {
+ const { planAsarHeaderAmplification, REA_ASAR_HEADER_LIMITS } = await import(
+ "../src/shields/exhaustion/asar-header-amplifier.js"
+ );
+ const { SeededPrng: Prng } = await import("../src/core/prng.js");
+ const { packAsarBuffer } = await import("../src/shields/formats/asar.js");
+ const plan = planAsarHeaderAmplification(new Prng("asar-cap"), "bankrupt");
+ expect(plan.exceedsDefaultAdmission).toBe(true);
+ expect(plan.files.length).toBeGreaterThan(1000);
+ const packed = packAsarBuffer([
+ {
+ relativePath: "package.json",
+ content: Buffer.from('{"name":"t","main":"m.js"}'),
+ },
+ { relativePath: "m.js", content: Buffer.from("exports.x=1") },
+ ...plan.files,
+ ]);
+ const headerSize = packed.readUInt32LE(4);
+ expect(headerSize).toBeGreaterThan(
+ REA_ASAR_HEADER_LIMITS.DEFAULT_ASAR_MAX_HEADER_BYTES,
+ );
+ });
+});
+
+describe("WASM interface exhaustion vs representation budget", () => {
+ it("bankrupt plan exceeds WASM_INTERFACE_REPRESENTATION_BYTES", async () => {
+ const { planWasmInterfaceBudgetExhaustion } = await import(
+ "../src/shields/exhaustion/wasm-interface-exhaustion.js"
+ );
+ const plan = planWasmInterfaceBudgetExhaustion(
+ new SeededPrng("wasm-cap"),
+ "bankrupt",
+ );
+ expect(plan.exceedsRepresentationBudget).toBe(true);
+ expect(plan.totalReaChargedBytes).toBeGreaterThan(
+ REA_INTERNAL_LIMITS.WASM_INTERFACE_REPRESENTATION_BYTES,
+ );
+ });
+});