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.

fix(test): macos-safe strip⇒fail reloads for sidecar entangle

qybaihe03849daebb1b
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 91382dc..8b5a736 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -6,6 +6,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]
+### Fixed
+- **Self-seal missing-sibling hard-fail (#95, CrackMe v8 red 2026-11-06):** when `hardFailOnSiblingMismatch` is on, an unreadable/deleted expected sibling throws `integrity check failed` instead of soft-folding `missing:` into the digest (delete-anchor bypass). Soft mode unchanged.
+
### Added
- **Sidecar entry entanglement JS strip⇒fail (issue #40):** `computeSidecarBindingDigest` + `generateSidecarJsPreamble` / `bindSidecarEntanglement`. Opt-in CLI `--sidecar-entangle` / MCP `sidecar_entangle` / `.blarc sidecarEntangle`. `protectTarget` prepends a Node preamble that re-measures sibling sidecars (sidecars-mode digest is preamble-safe); strip/alter fails closed. `hardenProject` post-pass rewrites the JS entry against FINAL sibling bytes. Python/WASM still open.
- **`bla_harden` progress/cancel (issue #75):** cooperative `AbortSignal` + `onProgress` between artifacts; cancelled reports set `cancelled: true` and list every already-written path (no silent half-harden). MCP `notifications/progress` when `_meta.progressToken` is present; `notifications/cancelled` aborts in-flight harden immediately (stdio fast-path, not behind the serial queue).
diff --git a/STATE.md b/STATE.md
index 60abfde..5116832 100644
--- a/STATE.md
+++ b/STATE.md
@@ -91,9 +91,9 @@ Outside the repo, `npm pack` → install tarball → isolated `HOME`:
Unified `bla lint` / MCP `bla_lint` (`bla-packaging-gates/v1`) aggregates every bankrupt refuse lint from red-blue rounds 1–7; R8–R12 SHA-256 KDF / commitment-outside-XOR / arity+export hygiene live as Skill recipes + WASM protect defaults. Honesty residual: full WASM RE + online/SMT — **not** a new refuse lint. Skill **v2.0.0**. Shipped as **bla-agents 2.0.0** (PR #77).
-## Post-2.0 continuous hardening (2026-11-05)
+## Post-2.0 continuous hardening (2026-11-06)
-CrackMe v8 red team (round-20261105): **NO PRIZE** — key/FLAG not recovered; `redteam:rea` **unverified** (REA dist absent). Last round's public-seed KP and `keySha256` oracle verified closed by harness. New exposure (empirical tamper matrix, not REA): entry `license.cjs` self-tamper was undetected although the coverage matrix claimed `license.cjs#siteN → license.cjs` (paper coverage). Fixed by canonical entry self-digest + `integrityCoverageSelfVerified` honesty downgrade. Residual: unhardened `seal.json` data sidecar not covered (not a prize — public `flagSha256` is the proof); bankrupt `plaintext-secret` lint flags BLA's own decoy literals (false positive, not exploitable). Shipped `challenge/v8` artifacts predate PRs #84–86 + this fix (rebuild needs release secrets).
+CrackMe v8 red team (round-20261106): **NO PRIZE** — key/FLAG not recovered; `redteam:rea` **unverified** (REA dist absent). Prior closed: public-seed KP / `keySha256` (#83), entry self-digest paper coverage (#87). **New exposure closed (#95):** deleting an expected self-seal sibling soft-folded `missing:` and skipped hard-fail — now throws `integrity check failed` when `hardFailOnSiblingMismatch`. Sidecar JS strip⇒fail vertical slice in flight (#93). Residual: unhardened `seal.json` data sidecar not covered (not a prize); bankrupt `plaintext-secret` lint decoy FPs. Shipped `challenge/v8` may predate some fixes (rebuild needs release secrets).
## Nightly roadmap remaining
diff --git a/tests/sidecar-entangle-protect.test.ts b/tests/sidecar-entangle-protect.test.ts
index 38d3fbd..bc12b30 100644
--- a/tests/sidecar-entangle-protect.test.ts
+++ b/tests/sidecar-entangle-protect.test.ts
@@ -4,10 +4,11 @@ import {
writeFileSync,
rmSync,
readFileSync,
+ realpathSync,
} from "node:fs";
import { join } from "node:path";
import { tmpdir } from "node:os";
-import { createRequire } from "node:module";
+import { spawnSync } from "node:child_process";
import { protectTarget } from "../src/engine/protector.js";
import { computeSidecarBindingDigest } from "../src/shields/runtime/sidecar-entangle.js";
@@ -43,11 +44,9 @@ describe("sidecar entangle protectTarget wiring", () => {
const dir = mkdtempSync(join(tmpdir(), "bla-sidecar-on-"));
try {
const entry = join(dir, "main.js");
- const sib = join(dir, "sib.js");
const entrySrc = "module.exports = { v: 99 };\n";
const sibSrc = "sidecar-bytes-v1\n";
writeFileSync(entry, entrySrc, "utf8");
- writeFileSync(sib, sibSrc, "utf8");
const out = join(dir, "main.out.js");
// protect writes next to output; sidecar path resolved from output dir
writeFileSync(join(dir, "sib-for-out.js"), sibSrc, "utf8");
@@ -65,13 +64,18 @@ describe("sidecar entangle protectTarget wiring", () => {
expect(code).toContain("node:crypto");
expect(code).toContain("integrity binding mismatch");
- const req = createRequire(join(dir, "pkg.json"));
- const loaded = req(out) as { v: number };
- expect(loaded.v).toBe(99);
+ const outAbs = realpathSync(out);
+ const intact = spawnSync(process.execPath, ["-e", `console.log(require(${JSON.stringify(outAbs)}).v)`], {
+ encoding: "utf8",
+ });
+ expect(intact.status, intact.stderr).toBe(0);
+ expect((intact.stdout || "").trim()).toBe("99");
rmSync(join(dir, "sib-for-out.js"));
- delete req.cache[out];
- expect(() => req(out)).toThrow(/integrity binding mismatch/);
+ const stripped = spawnSync(process.execPath, [outAbs], { encoding: "utf8" });
+ const strippedOut = `${stripped.stderr || ""}${stripped.stdout || ""}`;
+ expect(stripped.status, strippedOut).not.toBe(0);
+ expect(strippedOut).toMatch(/integrity binding mismatch/);
} finally {
rmSync(dir, { recursive: true, force: true });
}
diff --git a/tests/sidecar-js-inject.test.ts b/tests/sidecar-js-inject.test.ts
index 2642ce6..561e254 100644
--- a/tests/sidecar-js-inject.test.ts
+++ b/tests/sidecar-js-inject.test.ts
@@ -1,8 +1,14 @@
import { describe, expect, it } from "vitest";
-import { mkdtempSync, writeFileSync, rmSync, readFileSync } from "node:fs";
+import {
+ mkdtempSync,
+ writeFileSync,
+ rmSync,
+ realpathSync,
+} from "node:fs";
import { join } from "node:path";
import { tmpdir } from "node:os";
import { createRequire } from "node:module";
+import { spawnSync } from "node:child_process";
import {
bindSidecarEntanglement,
computeSidecarBindingDigest,
@@ -10,6 +16,37 @@ import {
SIDECAR_ENTANGLE_SCHEMA,
} from "../src/shields/runtime/sidecar-entangle.js";
+/** macOS tmpdir is often /var → /private/var; require.cache keys use realpath. */
+function bustRequireCache(req: NodeRequire, target: string): string {
+ let abs: string;
+ try {
+ abs = realpathSync(target);
+ } catch {
+ abs = target;
+ }
+ for (const k of Object.keys(req.cache)) {
+ let rk = k;
+ try {
+ rk = realpathSync(k);
+ } catch {
+ /* keep raw key */
+ }
+ if (rk === abs || k === target || k === abs) delete req.cache[k];
+ }
+ return abs;
+}
+
+function runFresh(entryAbs: string): {
+ status: number | null;
+ out: string;
+} {
+ const r = spawnSync(process.execPath, [entryAbs], { encoding: "utf8" });
+ return {
+ status: r.status,
+ out: `${r.stderr || ""}${r.stdout || ""}`,
+ };
+}
+
describe("sidecar JS inject strip⇒fail (vertical slice)", () => {
it("generateSidecarJsPreamble rejects non-hex expected digests", () => {
expect(() =>
@@ -61,22 +98,19 @@ describe("sidecar JS inject strip⇒fail (vertical slice)", () => {
softFold: false,
});
- // Write entry WITH preamble prepended — sidecars-mode digest still matches.
const protectedEntry = `${inject.preamble}\n${entrySrc}`;
writeFileSync(join(dir, entryPath), protectedEntry, "utf8");
const req = createRequire(join(dir, "pkg.json"));
- const loaded = req(join(dir, entryPath)) as { value: number };
+ const entryAbs = bustRequireCache(req, join(dir, entryPath));
+ const loaded = req(entryAbs) as { value: number };
expect(loaded.value).toBe(42);
- // Strip sidecar → next load must throw.
+ // Strip sidecar → fresh process must hard-fail (avoid require.cache realpath traps).
rmSync(join(dir, sibName));
- expect(() => {
- // Bust require cache
- const abs = join(dir, entryPath);
- delete req.cache[abs];
- req(abs);
- }).toThrow(/integrity binding mismatch/);
+ const stripped = runFresh(entryAbs);
+ expect(stripped.status, stripped.out).not.toBe(0);
+ expect(stripped.out).toMatch(/integrity binding mismatch/);
} finally {
rmSync(dir, { recursive: true, force: true });
}
@@ -105,12 +139,13 @@ describe("sidecar JS inject strip⇒fail (vertical slice)", () => {
writeFileSync(join(dir, entryPath), `${inject.preamble}\n${entrySrc}`, "utf8");
const req = createRequire(join(dir, "pkg.json"));
- expect((req(join(dir, entryPath)) as { value: number }).value).toBe(7);
+ const entryAbs = bustRequireCache(req, join(dir, entryPath));
+ expect((req(entryAbs) as { value: number }).value).toBe(7);
writeFileSync(join(dir, sibName), "TAMPERED\n", "utf8");
- const abs = join(dir, entryPath);
- delete req.cache[abs];
- expect(() => req(abs)).toThrow(/integrity binding mismatch/);
+ const altered = runFresh(entryAbs);
+ expect(altered.status, altered.out).not.toBe(0);
+ expect(altered.out).toMatch(/integrity binding mismatch/);
} finally {
rmSync(dir, { recursive: true, force: true });
}
@@ -121,9 +156,6 @@ describe("sidecar JS inject strip⇒fail (vertical slice)", () => {
try {
const entryPath = "main.js";
const sibName = "sib.js";
- const entrySrc =
- "module.exports = { d: (typeof __blaSidecarDigest === 'number' ? __blaSidecarDigest : 0) };\n";
- // softFold preamble assigns binding as IIFE return — capture via rewrite:
const digest = computeSidecarBindingDigest(
{ pathLabel: entryPath, bytes: new TextEncoder().encode("x") },
[{ pathLabel: sibName, bytes: new TextEncoder().encode("y") }],
@@ -137,16 +169,15 @@ describe("sidecar JS inject strip⇒fail (vertical slice)", () => {
softFold: true,
bindingName: "__blaSidecarDigest",
});
- // Capture IIFE return into the binding name for the module scope.
const preambleAssign = `var __blaSidecarDigest = ${inject.preamble}\n`;
writeFileSync(
join(dir, entryPath),
`${preambleAssign}module.exports = { d: __blaSidecarDigest };\n`,
"utf8",
);
- // No sidecar written → softFold should set flipped/zero digest, not throw.
const req = createRequire(join(dir, "pkg.json"));
- const out = req(join(dir, entryPath)) as { d: number };
+ const entryAbs = bustRequireCache(req, join(dir, entryPath));
+ const out = req(entryAbs) as { d: number };
expect(typeof out.d).toBe("number");
expect(out.d).not.toBe(digest.u32);
} finally {