🛡️ 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.
JavaScript adversarial-aiclaude-codecursorelectron-securityllm-securitymcpmcp-serverobfuscationreverse-engineeringwebassembly
feat(harden): refuse bankrupt when reversible plaintext seals present
qybaihe549a449b736a
diff --git a/src/core/config.ts b/src/core/config.tsindex a1ee647..12d1296 100644--- a/src/core/config.ts+++ b/src/core/config.ts@@ -24,6 +24,8 @@ export interface BlaProjectConfig {readonly wasmPreserveExports?: readonly string[];/** When true, allow harden/defend of lane-independent JS gates (issue #40.1). Default false. */readonly allowLaneIndependentGates?: boolean;+ /** When true, allow bankrupt harden despite plaintext/reversible seal sidecars (red-blue round-2). Default false. */+ readonly allowPlaintextSeal?: boolean;}/**diff --git a/src/core/types.ts b/src/core/types.tsindex ff8e325..f7affb0 100644--- a/src/core/types.ts+++ b/src/core/types.ts@@ -180,6 +180,11 @@ export interface ProtectionOptions {* Default false: protect/defend/harden refuse such gates (red-blue round-1).*/readonly allowLaneIndependentGates?: boolean;+ /**+ * When true, allow bankrupt harden/protect despite plaintext/reversible seal+ * sidecars (red-blue round-2). Default false — refuse.+ */+ readonly allowPlaintextSeal?: boolean;}export interface ProtectionMetrics {diff --git a/src/engine/defender.ts b/src/engine/defender.tsindex 5527b0e..a6a7e14 100644--- a/src/engine/defender.ts+++ b/src/engine/defender.ts@@ -31,6 +31,8 @@ export interface OneClickDefenseOptions {readonly wasmPreserveExports?: readonly string[];/** Allow lane-independent JS gates (issue #40.1). Default false. */readonly allowLaneIndependentGates?: boolean;+ /** Allow bankrupt despite plaintext/reversible seal sidecars (red-blue round-2). Default false. */+ readonly allowPlaintextSeal?: boolean;}export interface OneClickDefenseStageSummary {@@ -125,6 +127,7 @@ export function defendTarget(options: OneClickDefenseOptions): OneClickDefenseRe...(options.allowLaneIndependentGates === true? { allowLaneIndependentGates: true }: {}),+ ...(options.allowPlaintextSeal === true ? { allowPlaintextSeal: true } : {}),honeySourceMaps: true,});diff --git a/src/engine/harden.ts b/src/engine/harden.tsindex 1638325..0c32f1f 100644--- a/src/engine/harden.ts+++ b/src/engine/harden.ts@@ -13,6 +13,11 @@ import {defendTarget,type OneClickDefenseReport,} from "./defender.js";+import {+ discoverAndLintSealSidecars,+ intensityEnforcesSealRefusal,+ sealCommitmentRefuseMessage,+} from "./seal-commitment-lint.js";import {computeHardenRunId,HARDEN_SUMMARY_FILE_NAME,@@ -105,6 +110,8 @@ export interface HardenProjectOptions {readonly wasmPreserveExports?: readonly string[];/** Allow lane-independent JS gates (issue #40.1). Default false — refuse. */readonly allowLaneIndependentGates?: boolean;+ /** Allow bankrupt despite plaintext/reversible seal sidecars (red-blue round-2). Default false — refuse. */+ readonly allowPlaintextSeal?: boolean;/** Optional output root; defaults to `<dir>/.bla-hardened`. */readonly outputDirectory?: string;readonly maxArtifacts?: number;@@ -328,6 +335,12 @@ export function hardenProject(const dryRun = options.dryRun === true;const discovery = discoverHardenTargets(absDir, { maxArtifacts });const discovered = discovery.artifacts;++ const sealReports = discoverAndLintSealSidecars(absDir);+ const blockingSeals =+ intensityEnforcesSealRefusal(intensity) && options.allowPlaintextSeal !== true+ ? sealReports.filter((r) => r.shouldRefuseBankrupt)+ : [];const outputRoot = resolve(options.outputDirectory ??(statSync(absDir).isDirectory()@@ -370,6 +383,44 @@ export function hardenProject(runId,} as const;+ if (blockingSeals.length > 0) {+ const sealArtifacts = blockingSeals.map((r) => ({+ inputPath: r.path,+ relativePath: (relative(absDir, r.path) || basename(r.path)).split(sep).join("/"),+ format: "unknown" as const,+ outputPath: r.path,+ success: false,+ defenseScore: 0,+ tokenAmplificationFactor: 0,+ costAmplificationFactor: 0,+ outputExisted: false,+ error: sealCommitmentRefuseMessage(r, r.path),+ }));+ return {+ ...reportBase,+ overallSuccess: false,+ hardenedCount: 0,+ failedCount: sealArtifacts.length,+ artifacts: [+ ...plannedOutputs.map(({ artifact, outputPath, outputExisted }) => ({+ inputPath: artifact.path,+ relativePath: artifact.relativePath,+ format: artifact.format,+ outputPath,+ success: false,+ defenseScore: 0,+ tokenAmplificationFactor: 0,+ costAmplificationFactor: 0,+ outputExisted,+ error: dryRun+ ? "skipped: plaintext/reversible seal sidecar blocked bankrupt harden"+ : "skipped: plaintext/reversible seal sidecar blocked bankrupt harden",+ })),+ ...sealArtifacts,+ ],+ };+ }+if (dryRun) {// Preview only: never claim overallSuccess — nothing was hardened.return {@@ -420,6 +471,7 @@ export function hardenProject(...(options.allowLaneIndependentGates === true? { allowLaneIndependentGates: true }: {}),+ ...(options.allowPlaintextSeal === true ? { allowPlaintextSeal: true } : {}),emitManifest,});summaries.push({diff --git a/src/engine/protector.ts b/src/engine/protector.tsindex 2dd674f..f34a7ce 100644--- a/src/engine/protector.ts+++ b/src/engine/protector.ts@@ -51,6 +51,12 @@ import {laneIndependenceRefuseMessage,lintLaneIndependence,} from "./lane-independence-lint.js";+import {+ findSiblingSealSidecars,+ intensityEnforcesSealRefusal,+ lintSealCommitmentFile,+ sealCommitmentRefuseMessage,+} from "./seal-commitment-lint.js";/*** Crash-safe output write: write to a temp file in the same directory, then@@ -212,6 +218,18 @@ function protectTargetInner(options: ProtectionOptions): ProtectionResult {let inlineScriptsFailed = 0;const counteredVectors = new Set<ReaAttackVectorId>();+ if (+ intensityEnforcesSealRefusal(intensity) &&+ options.allowPlaintextSeal !== true+ ) {+ for (const sealPath of findSiblingSealSidecars(dirname(absInput))) {+ const sealReport = lintSealCommitmentFile(sealPath);+ if (sealReport.shouldRefuseBankrupt) {+ throw new Error(sealCommitmentRefuseMessage(sealReport, sealPath));+ }+ }+ }+if (format === "javascript" || format === "typescript") {const raw = readFileSync(absInput, "utf8");if (diff --git a/tests/seal-commitment-harden-gate.test.ts b/tests/seal-commitment-harden-gate.test.tsnew file mode 100644index 0000000..a2dc603--- /dev/null+++ b/tests/seal-commitment-harden-gate.test.ts@@ -0,0 +1,117 @@+import { mkdtempSync, mkdirSync, rmSync, writeFileSync } from "node:fs";+import { tmpdir } from "node:os";+import { join } from "node:path";+import { afterEach, describe, expect, it } from "vitest";+import { hardenProject } from "../src/engine/harden.js";+import { protectTarget } from "../src/engine/protector.js";++const dirs: string[] = [];+afterEach(() => {+ for (const d of dirs.splice(0)) rmSync(d, { recursive: true, force: true });+});++const ROUND2_SEAL = {+ schema: "bla-redblue-r2-seal/v1",+ rounds: 28,+ scheduleSalt: 1374179543,+ revision: "7f325fec37206b637a224e9630b67c4a",+ certificateCipherHex: "0cd3dfe5e342eb542a3666d6e706ede34c58416b00bb853921b9c82397ff716237",+};++const ONE_WAY_SEAL = {+ schema: "bla-entitlement-seal/v1",+ algorithm: "sha256",+ revision: "b38091d4a394ded9012846e8d4b647083b260beb6ee5ad1e42265fe6f107c660",+};++const SAFE_JS = `+ export function activate(key) {+ let h = 2166136261;+ for (let i = 0; i < key.length; i++) {+ h ^= key.charCodeAt(i);+ h = Math.imul(h, 16777619);+ }+ return (h >>> 0).toString(16);+ }+`;++describe("harden/protect seal-sidecar gate (red-blue round-2 P1)", () => {+ it("bankrupt harden refuses reversible plaintext seal.json by default", () => {+ const root = mkdtempSync(join(tmpdir(), "bla-seal-refuse-"));+ dirs.push(root);+ writeFileSync(join(root, "gate.js"), SAFE_JS, "utf8");+ writeFileSync(join(root, "seal.json"), JSON.stringify(ROUND2_SEAL), "utf8");+ const report = hardenProject({+ directory: root,+ intensity: "bankrupt",+ seed: "seal-refuse",+ outputDirectory: join(root, "out"),+ });+ expect(report.overallSuccess).toBe(false);+ expect(+ report.artifacts.some(+ (a) => a.error && /allowPlaintextSeal|plaintext\/reversible seal|reversible/i.test(a.error),+ ),+ ).toBe(true);+ });++ it("bankrupt harden allows one-way sha256 seal.json", () => {+ const root = mkdtempSync(join(tmpdir(), "bla-seal-ok-"));+ dirs.push(root);+ writeFileSync(join(root, "gate.js"), SAFE_JS, "utf8");+ writeFileSync(join(root, "seal.json"), JSON.stringify(ONE_WAY_SEAL), "utf8");+ const report = hardenProject({+ directory: root,+ intensity: "bankrupt",+ seed: "seal-ok",+ outputDirectory: join(root, "out"),+ });+ expect(report.overallSuccess).toBe(true);+ expect(report.hardenedCount).toBeGreaterThanOrEqual(1);+ });++ it("allowPlaintextSeal overrides bankrupt refuse", () => {+ const root = mkdtempSync(join(tmpdir(), "bla-seal-allow-"));+ dirs.push(root);+ writeFileSync(join(root, "gate.js"), SAFE_JS, "utf8");+ writeFileSync(join(root, "seal.json"), JSON.stringify(ROUND2_SEAL), "utf8");+ const report = hardenProject({+ directory: root,+ intensity: "bankrupt",+ seed: "seal-allow",+ outputDirectory: join(root, "out"),+ allowPlaintextSeal: true,+ });+ expect(report.overallSuccess).toBe(true);+ });++ it("balanced intensity does not refuse (warning path only via lint)", () => {+ const root = mkdtempSync(join(tmpdir(), "bla-seal-bal-"));+ dirs.push(root);+ writeFileSync(join(root, "gate.js"), SAFE_JS, "utf8");+ writeFileSync(join(root, "seal.json"), JSON.stringify(ROUND2_SEAL), "utf8");+ const report = hardenProject({+ directory: root,+ intensity: "balanced",+ seed: "seal-bal",+ outputDirectory: join(root, "out"),+ });+ expect(report.overallSuccess).toBe(true);+ });++ it("bankrupt protect refuses sibling seal.json", () => {+ const root = mkdtempSync(join(tmpdir(), "bla-seal-prot-"));+ dirs.push(root);+ const src = join(root, "gate.js");+ writeFileSync(src, SAFE_JS, "utf8");+ writeFileSync(join(root, "seal.json"), JSON.stringify(ROUND2_SEAL), "utf8");+ expect(() =>+ protectTarget({+ inputPath: src,+ outputPath: join(root, "out.js"),+ intensity: "bankrupt",+ seed: "seal-prot",+ }),+ ).toThrow(/allowPlaintextSeal|plaintext\/reversible seal/i);+ });+});