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.

feat(engine): thread selfSeal through protect, defend, and harden (#40.5)

qybaihe28210b332c95
diff --git a/src/core/types.ts b/src/core/types.ts
index 7de2152..cb2ba9f 100644
--- a/src/core/types.ts
+++ b/src/core/types.ts
@@ -164,6 +164,11 @@ export interface ProtectionOptions {
* When false, Python stays warm-init-only. Default false.
*/
readonly weaveDecoys?: boolean;
+ /**
+ * Opt-in self-seal / sibling-module integrity binding for JS/Node targets (issue #40.5).
+ * When true, harden/protect inject a self-integrity preamble and entangle the opaque seed.
+ */
+ readonly selfSeal?: boolean;
}
export interface ProtectionMetrics {
@@ -189,6 +194,8 @@ export interface ProtectionResult {
readonly intensity: ProtectionIntensity;
/** Present when protect was called with weaveDecoys:true (Python customer-def weave active). */
readonly weaveDecoys?: boolean;
+ /** Present when protect was called with selfSeal:true (JS self-integrity binding active). */
+ readonly selfSeal?: boolean;
readonly seed: string;
readonly originalSha256: string;
readonly protectedSha256: string;
diff --git a/src/engine/defender.ts b/src/engine/defender.ts
index 20289fe..c93acfc 100644
--- a/src/engine/defender.ts
+++ b/src/engine/defender.ts
@@ -25,6 +25,8 @@ export interface OneClickDefenseOptions {
readonly emitManifest?: boolean;
readonly llmDirectives?: boolean;
readonly weaveDecoys?: boolean;
+ /** Opt-in self-seal / sibling-module integrity binding for JS/Node (issue #40.5). */
+ readonly selfSeal?: boolean;
}
export interface OneClickDefenseStageSummary {
@@ -45,6 +47,8 @@ export interface OneClickDefenseReport {
readonly intensity: ProtectionIntensity;
/** True when caller opted into weave-decoy labeling/hooks. */
readonly weaveDecoys: boolean;
+ /** True when caller opted into self-seal integrity binding. */
+ readonly selfSeal: boolean;
readonly overallSuccess: boolean;
readonly stages: readonly OneClickDefenseStageSummary[];
readonly releaseExposure: ReleaseExposureReport | null;
@@ -108,6 +112,9 @@ export function defendTarget(options: OneClickDefenseOptions): OneClickDefenseRe
...(options.weaveDecoys !== undefined
? { weaveDecoys: options.weaveDecoys }
: {}),
+ ...(options.selfSeal !== undefined
+ ? { selfSeal: options.selfSeal }
+ : {}),
honeySourceMaps: true,
});
@@ -194,6 +201,7 @@ export function defendTarget(options: OneClickDefenseOptions): OneClickDefenseRe
outputPath: protection.outputPath,
intensity,
weaveDecoys: options.weaveDecoys === true,
+ selfSeal: options.selfSeal === true,
overallSuccess: verification.overallPassed,
stages,
releaseExposure,
diff --git a/src/engine/harden.ts b/src/engine/harden.ts
index ed3fc2e..6c6ac68 100644
--- a/src/engine/harden.ts
+++ b/src/engine/harden.ts
@@ -92,6 +92,8 @@ export interface HardenProjectOptions {
readonly emitManifest?: boolean;
readonly llmDirectives?: boolean;
readonly weaveDecoys?: boolean;
+ /** Opt-in self-seal / sibling-module integrity binding for JS/Node (issue #40.5). */
+ readonly selfSeal?: boolean;
/** Optional output root; defaults to `<dir>/.bla-hardened`. */
readonly outputDirectory?: string;
readonly maxArtifacts?: number;
@@ -109,6 +111,7 @@ export interface HardenProjectReport {
readonly artifacts: readonly HardenArtifactSummary[];
readonly oneSentenceUsage: string;
readonly weaveDecoys: boolean;
+ readonly selfSeal: boolean;
}
function isProtectableFormat(format: ArtifactFormat): boolean {
@@ -293,6 +296,9 @@ export function hardenProject(
...(options.weaveDecoys !== undefined
? { weaveDecoys: options.weaveDecoys }
: {}),
+ ...(options.selfSeal !== undefined
+ ? { selfSeal: options.selfSeal }
+ : {}),
emitManifest,
});
summaries.push({
@@ -333,6 +339,7 @@ export function hardenProject(
directory: absDir,
intensity,
weaveDecoys: options.weaveDecoys === true,
+ selfSeal: options.selfSeal === true,
artifacts: summaries,
},
null,
@@ -360,6 +367,7 @@ export function hardenProject(
oneSentenceUsage:
'Harden my software against REA — call bla_harden with { "directory": "." } (or `bla harden .`).',
weaveDecoys: options.weaveDecoys === true,
+ selfSeal: options.selfSeal === true,
};
}
diff --git a/src/engine/protector.ts b/src/engine/protector.ts
index a991719..1da5916 100644
--- a/src/engine/protector.ts
+++ b/src/engine/protector.ts
@@ -199,6 +199,7 @@ function protectTargetInner(options: ProtectionOptions): ProtectionResult {
intensity,
seed,
filename: basename(absInput),
+ ...(options.selfSeal === true ? { selfSeal: true as const } : {}),
});
let finalCode = transformed.code;
@@ -245,6 +246,7 @@ function protectTargetInner(options: ProtectionOptions): ProtectionResult {
intensity,
seed: `${seed}:html-script-${currentIndex}`,
sourceType: tagKind.isModule ? "module" : "script",
+ ...(options.selfSeal === true ? { selfSeal: true as const } : {}),
});
inlineScriptsTransformed++;
decoyFunctionsInjected += res.decoyFunctionsInjected;
@@ -269,6 +271,7 @@ function protectTargetInner(options: ProtectionOptions): ProtectionResult {
intensity,
seed: `${seed}:html-bootstrap`,
sourceType: "script",
+ ...(options.selfSeal === true ? { selfSeal: true as const } : {}),
});
decoyFunctionsInjected += bootstrapRes.decoyFunctionsInjected;
fakeCrossReferencesCreated += bootstrapRes.fakeCrossReferencesCreated;
@@ -314,6 +317,7 @@ function protectTargetInner(options: ProtectionOptions): ProtectionResult {
intensity,
seed: `${seed}:${vf.relativePath}`,
filename: vf.relativePath,
+ ...(options.selfSeal === true ? { selfSeal: true as const } : {}),
});
const honey = generateHoneySourceMap(
basename(vf.relativePath),
@@ -355,11 +359,17 @@ function protectTargetInner(options: ProtectionOptions): ProtectionResult {
// Inject a decoy hardware-enclave bridge module inside the ASAR archive
const decoyBridgeJs = transformJavaScriptWithBlaShield(
`export function verifyHardwareEnclaveLease(token) { return Boolean(token); }\n`,
- { intensity, seed: `${seed}:enclave-decoy` },
+ {
+ intensity,
+ seed: `${seed}:enclave-decoy`,
+ ...(options.selfSeal === true ? { selfSeal: true as const } : {}),
+ },
);
protectedFiles.push({
relativePath: "enclave/hardware-tee-bridge.js",
content: Buffer.from(decoyBridgeJs.code, "utf8"),
+
+ ...(options.selfSeal === true ? { selfSeal: true as const } : {}),
});
// Flood ASAR Pickle JSON header past REA DEFAULT_ASAR_MAX_HEADER_BYTES at
@@ -587,6 +597,7 @@ function protectTargetInner(options: ProtectionOptions): ProtectionResult {
intensity,
seed: `${seed}:${entry.name}`,
filename: entry.name,
+ ...(options.selfSeal === true ? { selfSeal: true as const } : {}),
});
const honey = generateHoneySourceMap(
entry.name,
@@ -673,6 +684,7 @@ function protectTargetInner(options: ProtectionOptions): ProtectionResult {
detectedFormat: format,
intensity,
...(options.weaveDecoys === true ? { weaveDecoys: true as const } : {}),
+ ...(options.selfSeal === true ? { selfSeal: true as const } : {}),
seed,
originalSha256: beforeAudit.sha256,
protectedSha256: afterAudit.sha256,