🛡️ 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(archive): reserve output capacity and reject parent-name collisions
Codex25b307861af6
diff --git a/docs/archive-integrity.md b/docs/archive-integrity.mdindex cd2679a..80af153 100644--- a/docs/archive-integrity.md+++ b/docs/archive-integrity.md@@ -24,9 +24,13 @@ unsupported encodings/compression, prepended executables, gaps and signing blockare unsupported. `readZipEntries` also enforces this subset; therefore auditingunsupported archives fails explicitly instead of returning a partial inventory.+Protection reserves nine output entries below the classic ZIP count sentinel, so+inputs may contain at most 65,525 entries regardless of intensity.+Protection additionally refuses AndroidManifest.xml, signature entries underMETA-INF (`.SF`, `.RSA`, `.DSA`, `.EC`) and existing entries in the reserved-`assets/enclave/` or `enclave/` output namespaces. These checks are conservative+`assets/enclave/` or `enclave/` output namespaces, including regular files named+exactly `assets`, `assets/enclave`, or `enclave` that would collide with new descendants. These checks are conservativeadmission rules, not a universal signature detector or signature verification.## APKs and failure behaviordiff --git a/src/shields/formats/archive.ts b/src/shields/formats/archive.tsindex 6aa332e..2107437 100644--- a/src/shields/formats/archive.ts+++ b/src/shields/formats/archive.ts@@ -195,10 +195,15 @@ export function writeZipArchive(/** Admission shared with the file engine, before any output paths are created. */export function validateZipProtectionInput(bytes: Buffer): readonly ZipEntryInfo[] {const existingEntries = readZipEntries(bytes);+ // Reserve the largest existing transformation (eight entries plus its manifest).+ // 0xffff is a ZIP64 sentinel, not a usable classic-ZIP entry count.+ if (existingEntries.length > 0xfffe - 9) {+ throw new UnsupportedArchiveError("insufficient classic ZIP entry-count capacity for output");+ }if (existingEntries.some((e) => e.name === "AndroidManifest.xml" || /^META-INF\/.*\.(SF|RSA|DSA|EC)$/i.test(e.name))) {throw new UnsupportedArchiveError("APK or signed archive requires a signing-aware pipeline");}- if (existingEntries.some((e) => e.name.startsWith("assets/enclave/") || e.name.startsWith("enclave/"))) {+ if (existingEntries.some((e) => ["assets", "assets/enclave", "enclave"].includes(e.name) || e.name.startsWith("assets/enclave/") || e.name.startsWith("enclave/"))) {throw new UnsupportedArchiveError("existing entries overlap the reserved output namespace");}return existingEntries;diff --git a/tests/archive-integrity.test.ts b/tests/archive-integrity.test.tsindex ae349a3..161e5fd 100644--- a/tests/archive-integrity.test.ts+++ b/tests/archive-integrity.test.ts@@ -2,7 +2,7 @@ import { afterEach, describe, expect, it } from "vitest";import { existsSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs";import { tmpdir } from "node:os";import { join } from "node:path";-import { protectZipOrApkBuffer, readZipEntries, UnsupportedApkProtectionError, UnsupportedArchiveError, writeZipArchive } from "../src/shields/formats/archive.js";+import { protectZipOrApkBuffer, readZipEntries, UnsupportedApkProtectionError, UnsupportedArchiveError, validateZipProtectionInput, writeZipArchive } from "../src/shields/formats/archive.js";import { protectTarget } from "../src/engine/protector.js";const fixture = () => writeZipArchive([{ name: "file.txt", data: Buffer.from("harmless content ".repeat(8)) }]);@@ -75,6 +75,35 @@ describe("archive admission preserves bytes or fails closed", () => {expect(() => protectZipOrApkBuffer(writeZipArchive([{ name: "META-INF/TEST.RSA", data: Buffer.from("not a real signature") }]))).toThrow(/signing-aware/);expect(() => readZipEntries(writeZipArchive([{ name: "a", data: Buffer.from("1") }, { name: "a", data: Buffer.from("2") }]))).toThrow(/duplicate/);});+ it("reserves output entries below the classic ZIP sentinel before filesystem changes", () => {+ const files = Array.from({ length: 65_526 }, (_, i) => ({ name: `f${i}`, data: Buffer.alloc(0) }));+ const accepted = writeZipArchive(files.slice(0, -1));+ expect(validateZipProtectionInput(accepted)).toHaveLength(65_525);+ const rejected = writeZipArchive(files); const original = Buffer.from(rejected);+ expect(readZipEntries(rejected)).toHaveLength(65_526);+ expect(() => protectZipOrApkBuffer(rejected, { intensity: "stealth" })).toThrow(/entry-count capacity/);+ expect(rejected.equals(original)).toBe(true);+ const dir = mkdtempSync(join(tmpdir(), "bla-archive-count-")); dirs.push(dir);+ const input = join(dir, "input.zip"); const output = join(dir, "output.zip");+ writeFileSync(input, rejected); writeFileSync(output, "existing");+ expect(() => protectTarget({ inputPath: input, outputPath: output })).toThrow(/entry-count capacity/);+ expect(readFileSync(output, "utf8")).toBe("existing");+ expect(() => protectTarget({ inputPath: input, outputPath: join(dir, "new", "output.zip") })).toThrow(/entry-count capacity/);+ expect(existsSync(join(dir, "new"))).toBe(false);+ expect(readFileSync(input).equals(original)).toBe(true);+ });+ it.each(["assets", "assets/enclave", "enclave"])("refuses reserved parent file %s without modification", (name) => {+ const input = writeZipArchive([{ name, data: Buffer.from("original regular file") }]);+ const original = Buffer.from(input);+ expect(() => protectZipOrApkBuffer(input)).toThrow(/reserved output namespace/);+ expect(input).toEqual(original);+ const dir = mkdtempSync(join(tmpdir(), "bla-archive-parent-")); dirs.push(dir);+ const file = join(dir, "input.zip"); writeFileSync(file, input);+ expect(() => protectTarget({ inputPath: file, inPlace: true })).toThrow(/reserved output namespace/);+ expect(readFileSync(file)).toEqual(original);+ expect(() => protectTarget({ inputPath: file, outputPath: join(dir, "new", "output.zip") })).toThrow(/reserved output namespace/);+ expect(existsSync(join(dir, "new"))).toBe(false);+ });it.each(["bad.zip", "unsigned.apk", "renamed.zip"])("retains input/output and creates no directory for %s", (name) => {const dir = mkdtempSync(join(tmpdir(), "bla-archive-")); dirs.push(dir);const input = join(dir, name); const output = join(dir, "existing.zip");