🛡️ 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
fix(harden): discover root-level artifacts when dist/ exists
qybaihecb4419e85425
diff --git a/src/cli.ts b/src/cli.tsindex 49dfd4e..43ad5b2 100644--- a/src/cli.ts+++ b/src/cli.ts@@ -39,6 +39,11 @@ Usage:npx bla-shield <command> [options]bla <command> [options]+Quick start:+ npx bla-agents setup -y # register bla_harden with your agent+ bla harden . # one-sentence Counter-REA hardening+ # or tell your agent: "Harden my software against REA"+Commands:setup Configure agent MCP integrations & install the BLA skillharden [dir] DEFAULT: auto-discover build outputs under a project/build dir and bankrupt-harden all of them@@ -47,7 +52,7 @@ Commands:audit <target> Pre-flight REA exposure & vulnerability scanprotect <target> Inject multi-layer Counter-REA adversarial shieldverify <target> [original] Verify Counter-REA defense invariants & token amplification- benchmark Run the 8-target Counter-REA Showcase Benchmark suite+ benchmark Run the 14-target Counter-REA Showcase Benchmark suiteemit-headers Generate compile-time C/C++, Rust, or Go defense headersdoctor Check readiness of BLA engines & agent registrationsupdate Update global bla-shield installation & print setup refresh instructions@@ -57,7 +62,8 @@ Commands:Options:-o, --output <path> Output file or directory path (for protect / emit-headers)--in-place Overwrite input target in-place (for protect)- --intensity <preset> Protection preset: stealth | balanced | maximum | bankrupt (default: balanced)+ --intensity <preset> stealth | balanced | maximum | bankrupt+ (harden/defend default: bankrupt; protect default: balanced)--seed <seed> Deterministic PRNG seed for reproducible protection--lang <c|rust|go> Target language for emit-headers (default: c)--client <id> Agent client ID for setup (repeatable: claude_code, cursor, codex, etc.)diff --git a/src/engine/harden.ts b/src/engine/harden.tsindex 07a71a9..4d1fce9 100644--- a/src/engine/harden.ts+++ b/src/engine/harden.ts@@ -39,6 +39,26 @@ const SKIP_DIR_NAMES = new Set(["venv",]);+/**+ * Source / docs trees skipped only on the *supplemental* project-root walk+ * (when dist/build/… already exist). Full-tree walks with no build dir still+ * descend into these so pure-source projects harden cleanly.+ */+const SUPPLEMENTAL_SKIP_DIR_NAMES = new Set([+ ...SKIP_DIR_NAMES,+ ...BLA_BUILD_OUTPUT_DIR_NAMES,+ "src",+ "lib",+ "test",+ "tests",+ "docs",+ "examples",+ "__tests__",+ "fixtures",+ "scripts",+ "benchmarks",+]);+const MAX_DISCOVERED_ARTIFACTS = 64;const MAX_WALK_DEPTH = 8;@@ -79,6 +99,7 @@ export interface HardenProjectReport {readonly discoveredCount: number;readonly hardenedCount: number;readonly failedCount: number;+ readonly outputDirectory: string;readonly artifacts: readonly HardenArtifactSummary[];readonly oneSentenceUsage: string;}@@ -91,7 +112,10 @@ function isProtectableFormat(format: ArtifactFormat): boolean {* Prefer known build-output directories when present; otherwise walk the project* root. Always skips VCS/dependency caches.*/-function resolveSearchRoots(absRoot: string): readonly string[] {+function resolveSearchRoots(absRoot: string): {+ readonly preferred: readonly string[];+ readonly includeProjectRootSupplemental: boolean;+} {const preferred: string[] = [];for (const name of BLA_BUILD_OUTPUT_DIR_NAMES) {const candidate = join(absRoot, name);@@ -110,7 +134,12 @@ function resolveSearchRoots(absRoot: string): readonly string[] {} catch {/* absent */}- return preferred.length > 0 ? preferred : [absRoot];+ if (preferred.length === 0) {+ return { preferred: [absRoot], includeProjectRootSupplemental: false };+ }+ // Build dirs win for deep discovery, but also scan the project root so+ // root-level .sqlite / .safetensors / .wasm / binaries / .py are not skipped.+ return { preferred, includeProjectRootSupplemental: true };}function walkCollect(@@ -119,6 +148,7 @@ function walkCollect(depth: number,out: DiscoveredArtifact[],maxArtifacts: number,+ skipDirs: ReadonlySet<string> = SKIP_DIR_NAMES,): void {if (out.length >= maxArtifacts || depth > MAX_WALK_DEPTH) return;let entries;@@ -134,8 +164,8 @@ function walkCollect(if (entry.isDirectory()) continue;}if (entry.isDirectory()) {- if (SKIP_DIR_NAMES.has(entry.name)) continue;- walkCollect(join(dir, entry.name), root, depth + 1, out, maxArtifacts);+ if (skipDirs.has(entry.name)) continue;+ walkCollect(join(dir, entry.name), root, depth + 1, out, maxArtifacts, skipDirs);continue;}const full = join(dir, entry.name);@@ -154,8 +184,9 @@ function walkCollect(/*** Auto-discovers protectable build artifacts under a project or build directory.- * Recognises dist/build/out/release/.asar/native/.wasm/.py/.pyc/.sqlite/- * .safetensors/.gguf/.dex/.class/.dll and magic-byte formats.+ * Prefers dist/build/out/release/…, and also picks up root-level+ * .asar/native/.wasm/.py/.pyc/.sqlite/.safetensors/.gguf/.dex/.class/.dll+ * and magic-byte formats even when a build directory exists.*/export function discoverHardenableArtifacts(directory: string = process.cwd(),@@ -179,9 +210,12 @@ export function discoverHardenableArtifacts(}const found: DiscoveredArtifact[] = [];- const roots = resolveSearchRoots(abs);- for (const root of roots) {- walkCollect(root, abs, 0, found, maxArtifacts);+ const { preferred, includeProjectRootSupplemental } = resolveSearchRoots(abs);+ for (const root of preferred) {+ walkCollect(root, abs, 0, found, maxArtifacts, SKIP_DIR_NAMES);+ }+ if (includeProjectRootSupplemental) {+ walkCollect(abs, abs, 0, found, maxArtifacts, SUPPLEMENTAL_SKIP_DIR_NAMES);}// De-dupe by absolute path (cargo release may overlap target/)const seen = new Set<string>();@@ -303,6 +337,7 @@ export function hardenProject(discoveredCount: discovered.length,hardenedCount,failedCount,+ outputDirectory: outputRoot,artifacts: summaries,oneSentenceUsage:'Harden my software against REA — call bla_harden with { "directory": "." } (or `bla harden .`).',@@ -324,7 +359,12 @@ export function formatHardenProjectReport(report: HardenProjectReport): string {}if (report.discoveredCount === 0) {lines.push(- " (no protectable build artifacts found — place outputs under dist/, build/, out/, or release/)",+ " (no protectable artifacts found — put build outputs under dist/, build/, out/, or release/, or place .wasm/.sqlite/.safetensors/binaries at the project root)",+ );+ } else {+ lines.push(`Output: ${report.outputDirectory}`);+ lines.push(+ "Next: ship or point your release at the hardened copies above (originals are untouched). See DISCLAIMER.md.",);}lines.push(`Tip: ${report.oneSentenceUsage}`);diff --git a/tests/harden-autodiscover.test.ts b/tests/harden-autodiscover.test.tsindex 697aaa0..3e70f2a 100644--- a/tests/harden-autodiscover.test.ts+++ b/tests/harden-autodiscover.test.ts@@ -11,11 +11,13 @@ import { join } from "node:path";import { afterEach, describe, expect, it } from "vitest";import {discoverHardenableArtifacts,+ formatHardenProjectReport,hardenProject,} from "../src/engine/harden.js";import { handleMcpRequest } from "../src/mcp/server.js";import { runCli } from "../src/cli.js";import { writeZipArchive } from "../src/shields/formats/archive.js";+import { buildSampleSqliteDatabase } from "../src/shields/formats/sqlite.js";const tempDirs: string[] = [];function createTempDir(): string {@@ -200,6 +202,34 @@ describe("bla_harden auto-discovery + one-sentence UX", () => {expect(cliReport.hardenedCount).toBeGreaterThanOrEqual(1);});+ it("also discovers root-level artifacts when dist/ already exists", () => {+ const root = createTempDir();+ const dist = join(root, "dist");+ mkdirSync(dist, { recursive: true });+ writeFileSync(join(dist, "app.js"), `export const x = 1;\n`, "utf8");+ writeFileSync(join(root, "tools.py"), "def helper():\n return 1\n", "utf8");+ writeFileSync(join(root, "local.sqlite"), buildSampleSqliteDatabase());+ // Source tree must NOT be swept when dist/ exists+ mkdirSync(join(root, "src"), { recursive: true });+ writeFileSync(join(root, "src", "internal.js"), `export const secret = 1;\n`, "utf8");++ const discovered = discoverHardenableArtifacts(root);+ const rels = discovered.map((d) => d.relativePath).sort();+ expect(rels).toEqual(expect.arrayContaining(["dist/app.js", "tools.py", "local.sqlite"]));+ expect(rels.some((r) => r.includes("src/"))).toBe(false);++ const report = hardenProject({+ directory: root,+ intensity: "stealth",+ seed: "root-supplemental",+ emitManifest: false,+ });+ expect(report.overallSuccess).toBe(true);+ expect(report.hardenedCount).toBeGreaterThanOrEqual(3);+ expect(report.outputDirectory).toContain(".bla-hardened");+ expect(formatHardenProjectReport(report)).toContain("Output:");+ });+it("hardens DEX members inside an unsigned APK-shaped ZIP discovered under release/", () => {const root = createTempDir();const release = join(root, "release");