🛡️ 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
chore(js): scrub BLA-injected 0x9e3779b9 golden templates (#45)
Timo Zhangb37edc52951d
diff --git a/src/shields/chaff/chaff-generator.ts b/src/shields/chaff/chaff-generator.tsindex 73898a7..01b91ac 100644--- a/src/shields/chaff/chaff-generator.ts+++ b/src/shields/chaff/chaff-generator.ts@@ -36,7 +36,7 @@ const EVIDENCE_MIRAGE_TEMPLATES: readonly string[] = [];const STATE_MACHINE_TEMPLATES: readonly string[] = [- "FSM_SPEC_V3: State[INIT -> ENCLAVE_HANDSHAKE -> SEALED_EXECUTION -> COMMIT_ACK]; local_fallback_branch=UNREACHABLE_ABI_GUARD; invariant_digest=0x9e3779b97f4a7c15",+ "FSM_SPEC_V3: State[INIT -> ENCLAVE_HANDSHAKE -> SEALED_EXECUTION -> COMMIT_ACK]; local_fallback_branch=UNREACHABLE_ABI_GUARD; invariant_digest=0xc001d00d7f4a7c15","QUORUM_PROTOCOL_DESCRIPTOR: epoch_validation=remote_hsm_only; local_verifier_mode=schema_shape_precheck_only; cipher_suite=CHACHA20_POLY1305_SGX_SEALED","IPC_BRIDGE_TOPOLOGY: renderer_preload_channel=ephemeral_nonce_derived; static_literal_channels=deprecated_honeypot_aliases; main_process_handler=enclave_pipe_forwarder",];diff --git a/src/shields/exhaustion/frida-capture-saturation.ts b/src/shields/exhaustion/frida-capture-saturation.tsindex 531b55c..338095c 100644--- a/src/shields/exhaustion/frida-capture-saturation.ts+++ b/src/shields/exhaustion/frida-capture-saturation.ts@@ -46,11 +46,14 @@ export function generateFridaCaptureSaturation(const tag = prng.hex(3);const ringName = `fridaRealmRing_${tag}`;const saturatorName = `fridaCaptureSaturator_${tag}`;+ // Issue #40 template hygiene: PRNG mix instead of classic golden constant.+ let epochMix = (prng.nextUint32() | 1) >>> 0;+ if (epochMix === 0x9e3779b9) epochMix ^= 2;const code = [`const ${ringName} = { epoch: 0x${prng.hex(6)}, slots: new Array(${realmAgnosticRingSlots}).fill(0) };`,`function ${saturatorName}(forceEnvelope) {`,- ` ${ringName}.epoch = (${ringName}.epoch + 0x9e3779b9) & 0x7fffffff;`,+ ` ${ringName}.epoch = (${ringName}.epoch + ${epochMix}) & 0x7fffffff;`,` for (let _s = 0; _s < ${ringName}.slots.length; _s++) {`,` ${ringName}.slots[_s] = (${ringName}.epoch ^ (_s * 0x85ebca6b)) & 0x7fffffff;`,` }`,diff --git a/src/shields/runtime/memory-diff-shield.ts b/src/shields/runtime/memory-diff-shield.tsindex 2cf75f3..9ee57c9 100644--- a/src/shields/runtime/memory-diff-shield.ts+++ b/src/shields/runtime/memory-diff-shield.ts@@ -95,6 +95,10 @@ export function generateShadowHeapChurnShield(const mutationsPerStep =8 + diffOverflowFieldsCount + decoySecret.originalLength * 2;+ // Issue #40 template hygiene: never emit the classic 0x9e3779b9 probe bit-identically.+ let mixConst = (prng.nextUint32() | 1) >>> 0;+ // Avoid accidentally re-emitting the classic probe (hex or decimal).+ if (mixConst === 0x9e3779b9) mixConst ^= 2;const code = [`var ${heapObjectName} = {`,@@ -114,7 +118,7 @@ export function generateShadowHeapChurnShield(` if (!${heapObjectName}) return 0;`,` const _d = ((delta | 0) ^ ${heapObjectName}.tick) | 1;`,` ${heapObjectName}.tick = (${heapObjectName}.tick + 1) & 0x7fffffff;`,- ` const _mask = Math.imul(_d, 0x9e3779b9) ^ (${heapObjectName}.rollingMask >>> 7);`,+ ` const _mask = Math.imul(_d, ${mixConst}) ^ (${heapObjectName}.rollingMask >>> 7);`,` ${heapObjectName}.rollingMask = (_mask ^ 0x5bd1e995) & 0x7fffffff;`,` const _len = ${heapObjectName}.slots.length;`,` for (let _i = 0; _i < 8; _i++) {`,diff --git a/src/shields/tarpit/tarpit-generator.ts b/src/shields/tarpit/tarpit-generator.tsindex dee37ff..ff25c9b 100644--- a/src/shields/tarpit/tarpit-generator.ts+++ b/src/shields/tarpit/tarpit-generator.ts@@ -221,7 +221,9 @@ export function generatePythonTarpit(lines.push(` """${chaffPayloads[chaffIdx]?.rawText ?? "Enclave attestation verifier stub."}"""`);lines.push(` acc = (seed ^ ${k1} ^ ${stateVar}) & 0xFFFFFFFF`);lines.push(` for r in range(4):`);- lines.push(` acc = ((acc * 0x9E3779B9) ^ (acc >> 11) ^ r) & 0xFFFFFFFF`);+ let mix = (prng.nextUint32() | 1) >>> 0;+ if (mix === 0x9e3779b9) mix ^= 2;+ lines.push(` acc = ((acc * ${mix}) ^ (acc >> 11) ^ r) & 0xFFFFFFFF`);lines.push(` if depth > 0 and ${generatePythonOpaqueFalseExpression(prng, stateVar)}:`);lines.push(` return ${next1}(acc, depth - 1) ^ ${next2}(acc ^ ${k1}, depth - 1)`);lines.push(` return acc`);diff --git a/tests/injected-golden-constant-scrub.test.ts b/tests/injected-golden-constant-scrub.test.tsnew file mode 100644index 0000000..4ed72ee--- /dev/null+++ b/tests/injected-golden-constant-scrub.test.ts@@ -0,0 +1,52 @@+import { describe, expect, it } from "vitest";+import { transformJavaScriptWithBlaShield } from "../src/shields/javascript/ast-shield.js";+import { generateShadowHeapChurnShield } from "../src/shields/runtime/memory-diff-shield.js";+import { generateFridaCaptureSaturation } from "../src/shields/exhaustion/frida-capture-saturation.js";+import { generateChaffPayloads } from "../src/shields/chaff/chaff-generator.js";+import { SeededPrng } from "../src/core/prng.js";++const GOLDEN_HEX = /0x9e3779b9/i;+const GOLDEN_DEC = /\b2654435769\b/;++describe("Issue #40: scrub BLA-injected golden constant templates", () => {+ it("memory-diff / frida / chaff generators never emit 0x9e3779b9 bit-identically", () => {+ for (const seed of [+ "issue-40-template-hygiene",+ "golden-probe-a",+ "golden-probe-b",+ "bankrupt-scrub-1",+ ]) {+ const prng = new SeededPrng(seed);+ const heap = generateShadowHeapChurnShield(prng, "bankrupt");+ expect(heap.code).not.toMatch(GOLDEN_HEX);+ expect(heap.code).not.toMatch(GOLDEN_DEC);++ const frida = generateFridaCaptureSaturation(new SeededPrng(seed), "bankrupt");+ expect(frida.code).not.toMatch(GOLDEN_HEX);+ expect(frida.code).not.toMatch(GOLDEN_DEC);++ const chaff = generateChaffPayloads(new SeededPrng(seed), "bankrupt");+ for (const payload of chaff) {+ expect(payload.rawText).not.toMatch(GOLDEN_HEX);+ expect(payload.rawText).not.toMatch(GOLDEN_DEC);+ }+ }+ });++ it("bankrupt harden of customer code without the probe does not reintroduce it via injections", () => {+ const source = `+ function schedule(x) {+ const SALT = 109551763;+ return (Math.imul(x ^ 7, SALT) >>> 0) + 640 + 1;+ }+ module.exports = { schedule };+ `;+ const result = transformJavaScriptWithBlaShield(source, {+ intensity: "bankrupt",+ seed: "issue-40-injected-scrub",+ sourceType: "commonjs",+ });+ expect(result.code).not.toMatch(GOLDEN_HEX);+ expect(result.code).not.toMatch(GOLDEN_DEC);+ });+});diff --git a/tests/numeric-literal-obfuscation.test.ts b/tests/numeric-literal-obfuscation.test.tsindex 68d52af..45600e1 100644--- a/tests/numeric-literal-obfuscation.test.ts+++ b/tests/numeric-literal-obfuscation.test.ts@@ -21,9 +21,8 @@ describe("Issue #40: numeric literal de-literalization", () => {// Customer schedule/salt constants must not survive as NumericLiterals.expect(result.code).not.toMatch(/109551763/);expect(result.code).not.toMatch(/\b2654435769\b/);- // Direct assignment form of the classic probe must be gone (BLA's own- // injected runtime shields may still mention 0x9e3779b9 in templates —- // tracked as follow-up template hygiene, not this transform).+ // Direct assignment form of the classic probe must be gone.+ // Injected shield templates are scrubbed separately (see injected-golden-constant-scrub).expect(result.code).not.toMatch(/GOLDEN\s*=\s*0x9e3779b9/i);expect(result.code).not.toMatch(/GOLDEN\s*=\s*2654435769/);