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(harden/mcp/cli): bankrupt refuse JS AES unwrap + panel oracle

qybaihe84ce13a00f2c
diff --git a/src/cli.ts b/src/cli.ts
index c1f431d..b0d603a 100644
--- a/src/cli.ts
+++ b/src/cli.ts
@@ -15,6 +15,7 @@ import { lintLaneIndependence } from "./engine/lane-independence-lint.js";
import { lintSealCommitmentFile } from "./engine/seal-commitment-lint.js";
import { lintWasmParamCarrierFile } from "./engine/wasm-param-carrier-lint.js";
import { lintPanelDeriveAbiFile } from "./engine/panel-derive-abi-lint.js";
+import { lintJsAesUnwrapFile } from "./engine/js-aes-unwrap-lint.js";
import { runShowcaseBenchmark } from "./engine/benchmark.js";
import {
emitCompileTimeNativeHeader,
@@ -56,7 +57,8 @@ Commands:
audit <target> Pre-flight REA exposure & vulnerability scan
lint-lanes <file> Heuristic ERROR if gate code looks lane-independent (issue #40.1); exit 2
lint-wasm-params <file> Heuristic ERROR if WASM embeds clear R3PARM/R3CIPH/R2SEAL-class carriers; exit 2
- lint-panel-derive <file> Heuristic ERROR if stable __vaultPanelDerive_* ABI remains; exit 2
+ lint-panel-derive <file> Heuristic ERROR if stable __vaultPanelDerive_* / deriveLocal oracle remains; exit 2
+ lint-js-aes-unwrap <file> Heuristic ERROR if JS AES wrap-key + create*iv + fixed hdr unwrap; exit 2
lint-seal <file> Heuristic lint for plaintext/reversible seal sidecars (red-blue round-2); exit 2 on error
protect <target> Inject multi-layer Counter-REA adversarial shield
verify <target> [original] Verify Counter-REA defense invariants & token amplification
@@ -108,6 +110,8 @@ interface ParsedCliArgs {
readonly allowPlaintextSeal: boolean;
readonly allowWasmClearParamCarriers: boolean;
readonly allowStablePanelDeriveAbi: boolean;
+ readonly allowJsAesUnwrap: boolean;
+ readonly allowPanelOfflineOracle: boolean;
readonly lang: NativeHeaderLanguage;
readonly clients: SupportedAgentClientId[];
readonly allDetected: boolean;
@@ -138,6 +142,8 @@ export function parseCliArgs(argv: readonly string[]): ParsedCliArgs {
let allowPlaintextSeal = false;
let allowWasmClearParamCarriers = false;
let allowStablePanelDeriveAbi = false;
+ let allowJsAesUnwrap = false;
+ let allowPanelOfflineOracle = false;
let lang: NativeHeaderLanguage = "c";
const clients: SupportedAgentClientId[] = [];
let allDetected = false;
@@ -186,6 +192,10 @@ export function parseCliArgs(argv: readonly string[]): ParsedCliArgs {
allowWasmClearParamCarriers = true;
} else if (arg === "--allow-stable-panel-derive") {
allowStablePanelDeriveAbi = true;
+ } else if (arg === "--allow-js-aes-unwrap") {
+ allowJsAesUnwrap = true;
+ } else if (arg === "--allow-panel-offline-oracle") {
+ allowPanelOfflineOracle = true;
} else if (arg.startsWith("--wasm-preserve-exports=")) {
wasmPreserveExports = arg
.slice("--wasm-preserve-exports=".length)
@@ -245,6 +255,8 @@ export function parseCliArgs(argv: readonly string[]): ParsedCliArgs {
allowPlaintextSeal,
allowWasmClearParamCarriers,
allowStablePanelDeriveAbi,
+ allowJsAesUnwrap,
+ allowPanelOfflineOracle,
lang,
clients,
allDetected,
@@ -388,6 +400,12 @@ export async function runCli(argv: readonly string[] = process.argv.slice(2)): P
allowStablePanelDeriveAbi:
parsed.allowStablePanelDeriveAbi ||
loaded.config.allowStablePanelDeriveAbi === true,
+ allowJsAesUnwrap:
+ parsed.allowJsAesUnwrap ||
+ loaded.config.allowJsAesUnwrap === true,
+ allowPanelOfflineOracle:
+ parsed.allowPanelOfflineOracle ||
+ loaded.config.allowPanelOfflineOracle === true,
...(parsed.output !== undefined ? { outputDirectory: parsed.output } : {}),
});
if (parsed.json) {
@@ -440,6 +458,12 @@ export async function runCli(argv: readonly string[] = process.argv.slice(2)): P
allowStablePanelDeriveAbi:
parsed.allowStablePanelDeriveAbi ||
loaded.config.allowStablePanelDeriveAbi === true,
+ allowJsAesUnwrap:
+ parsed.allowJsAesUnwrap ||
+ loaded.config.allowJsAesUnwrap === true,
+ allowPanelOfflineOracle:
+ parsed.allowPanelOfflineOracle ||
+ loaded.config.allowPanelOfflineOracle === true,
});
if (parsed.sarif) {
console.log(
@@ -548,10 +572,37 @@ export async function runCli(argv: readonly string[] = process.argv.slice(2)): P
console.log(" (no findings)");
}
}
- return report.shouldRewriteOrRefuse || report.findings.some((f) => f.severity === "error")
+ return report.shouldRefuseBankrupt ||
+ report.shouldRewriteOrRefuse ||
+ report.findings.some((f) => f.severity === "error")
? 2
: 0;
}
+ case "lint-js-aes-unwrap": {
+ const target = parsed.positionals[0];
+ if (!target) {
+ console.error("Error: Missing <file> path for `bla lint-js-aes-unwrap <file>`.");
+ return 1;
+ }
+ const report = lintJsAesUnwrapFile(resolve(target));
+ if (parsed.json) {
+ console.log(JSON.stringify(report, null, 2));
+ } else {
+ console.log(`BLA js-aes-unwrap lint β€” ${report.path}`);
+ console.log(report.oneLineAdvice);
+ for (const f of report.findings) {
+ console.log(` [${f.severity}] ${f.id}: ${f.summary}`);
+ if (f.evidence) console.log(` evidence: ${f.evidence}`);
+ }
+ if (report.findings.length === 0) {
+ console.log(" (no findings)");
+ }
+ }
+ return report.shouldRefuseBankrupt || report.findings.some((f) => f.severity === "error")
+ ? 2
+ : 0;
+ }
+
case "audit": {
const loaded = loadBlaConfig(process.cwd(), parsed.configPath);
const target = parsed.positionals[0] ?? loaded.config.input;
@@ -610,6 +661,12 @@ export async function runCli(argv: readonly string[] = process.argv.slice(2)): P
allowStablePanelDeriveAbi:
parsed.allowStablePanelDeriveAbi ||
loaded.config.allowStablePanelDeriveAbi === true,
+ allowJsAesUnwrap:
+ parsed.allowJsAesUnwrap ||
+ loaded.config.allowJsAesUnwrap === true,
+ allowPanelOfflineOracle:
+ parsed.allowPanelOfflineOracle ||
+ loaded.config.allowPanelOfflineOracle === true,
});
if (parsed.json) console.log(JSON.stringify(res, null, 2));
else console.log(formatProtectionResult(res));
diff --git a/src/core/config.ts b/src/core/config.ts
index eabc1ab..3961c37 100644
--- a/src/core/config.ts
+++ b/src/core/config.ts
@@ -30,6 +30,10 @@ export interface BlaProjectConfig {
readonly allowWasmClearParamCarriers?: boolean;
/** When true, keep stable __vaultPanelDerive_* ABI (red-blue round-3). Default false. */
readonly allowStablePanelDeriveAbi?: boolean;
+ /** When true, allow bankrupt despite JS AES wrap-key unwrap footguns (red-blue round-4). Default false. */
+ readonly allowJsAesUnwrap?: boolean;
+ /** When true, allow bankrupt despite panel offline-oracle packaging (red-blue round-4). Default false. */
+ readonly allowPanelOfflineOracle?: boolean;
}
/**
diff --git a/src/core/types.ts b/src/core/types.ts
index 6aa6431..736ca8a 100644
--- a/src/core/types.ts
+++ b/src/core/types.ts
@@ -195,6 +195,17 @@ export interface ProtectionOptions {
* Default false β€” maximum/bankrupt rewrite to seed-stable `_blaPd_*` (red-blue round-3).
*/
readonly allowStablePanelDeriveAbi?: boolean;
+ /**
+ * When true, allow bankrupt harden/protect despite JS AES wrap-key +
+ * create*iv + fixed sealed-hdr unwrap footguns (red-blue round-4). Default false β€” refuse.
+ * This is a gate only β€” not white-box AES.
+ */
+ readonly allowJsAesUnwrap?: boolean;
+ /**
+ * When true, allow bankrupt harden/protect despite panel deriveLocal +
+ * plaintext panelTokenSha256 offline-oracle packaging (red-blue round-4). Default false β€” refuse.
+ */
+ readonly allowPanelOfflineOracle?: boolean;
/**
* Optional sibling paths for self-seal when `selfSeal` is true (multi-artifact harden).
* Relative paths are resolved from the protected module's directory at runtime.
diff --git a/src/engine/auditor.ts b/src/engine/auditor.ts
index e8cda43..90cb59f 100644
--- a/src/engine/auditor.ts
+++ b/src/engine/auditor.ts
@@ -17,6 +17,7 @@ import { unpackAsarBuffer } from "../shields/formats/asar.js";
import { inspectWasmBinary } from "../shields/formats/wasm.js";
import { lintWasmParamCarrierBuffer } from "./wasm-param-carrier-lint.js";
import { lintPanelDeriveAbiSource } from "./panel-derive-abi-lint.js";
+import { lintJsAesUnwrapSource } from "./js-aes-unwrap-lint.js";
import { inspectPythonPyc } from "../shields/formats/python.js";
import { inspectNativeBinary } from "../shields/formats/native.js";
import { detectBunStandaloneGraph } from "../shields/formats/bun-standalone.js";
@@ -504,6 +505,20 @@ export function auditTarget(targetPath: string): AuditReport {
reason: f.summary,
});
}
+ const aesLint = lintJsAesUnwrapSource(text, { path: absPath });
+ for (const f of aesLint.findings) {
+ exposedItems.push({
+ id: `js_aes_${f.id}`,
+ name: f.id,
+ kind: "export",
+ location: basename(absPath),
+ riskLevel: f.severity === "error" ? "high" : "medium",
+ reaToolUsed: "bla lint-js-aes-unwrap / static source scan",
+ estimatedTokensToReconstruct: 1_500,
+ estimatedCostUsd: 0.06,
+ reason: f.summary,
+ });
+ }
res.vectors.forEach((v) => vulnerableVectors.add(v));
} else if (format === "html-bundle") {
const htmlText = rawBytes.toString("utf8");
diff --git a/src/engine/defender.ts b/src/engine/defender.ts
index 79e4ef9..413445c 100644
--- a/src/engine/defender.ts
+++ b/src/engine/defender.ts
@@ -37,6 +37,10 @@ export interface OneClickDefenseOptions {
readonly allowWasmClearParamCarriers?: boolean;
/** Keep stable __vaultPanelDerive_* ABI (red-blue round-3). Default false β€” rewrite. */
readonly allowStablePanelDeriveAbi?: boolean;
+ /** Allow bankrupt despite JS AES wrap-key unwrap footguns (red-blue round-4). Default false. */
+ readonly allowJsAesUnwrap?: boolean;
+ /** Allow bankrupt despite panel offline-oracle packaging (red-blue round-4). Default false. */
+ readonly allowPanelOfflineOracle?: boolean;
/** Sibling paths forwarded into self-seal when enabled (multi-artifact harden). */
readonly selfSealSiblingPaths?: readonly string[];
}
@@ -140,6 +144,10 @@ export function defendTarget(options: OneClickDefenseOptions): OneClickDefenseRe
...(options.allowStablePanelDeriveAbi === true
? { allowStablePanelDeriveAbi: true }
: {}),
+ ...(options.allowJsAesUnwrap === true ? { allowJsAesUnwrap: true } : {}),
+ ...(options.allowPanelOfflineOracle === true
+ ? { allowPanelOfflineOracle: true }
+ : {}),
...(options.selfSealSiblingPaths !== undefined &&
options.selfSealSiblingPaths.length > 0
? { selfSealSiblingPaths: options.selfSealSiblingPaths }
diff --git a/src/engine/harden.ts b/src/engine/harden.ts
index 6531b67..c3fc249 100644
--- a/src/engine/harden.ts
+++ b/src/engine/harden.ts
@@ -23,6 +23,11 @@ import {
intensityEnforcesWasmParamRefusal,
wasmParamCarrierRefuseMessage,
} from "./wasm-param-carrier-lint.js";
+import {
+ discoverAndLintJsAesUnwrap,
+ intensityEnforcesJsAesUnwrapRefusal,
+ jsAesUnwrapRefuseMessage,
+} from "./js-aes-unwrap-lint.js";
import {
computeHardenRunId,
HARDEN_SUMMARY_FILE_NAME,
@@ -121,6 +126,10 @@ export interface HardenProjectOptions {
readonly allowWasmClearParamCarriers?: boolean;
/** Keep stable __vaultPanelDerive_* ABI (red-blue round-3). Default false β€” rewrite. */
readonly allowStablePanelDeriveAbi?: boolean;
+ /** Allow bankrupt despite JS AES wrap-key unwrap footguns (red-blue round-4). Default false. */
+ readonly allowJsAesUnwrap?: boolean;
+ /** Allow bankrupt despite panel offline-oracle packaging (red-blue round-4). Default false. */
+ readonly allowPanelOfflineOracle?: boolean;
/** Optional output root; defaults to `<dir>/.bla-hardened`. */
readonly outputDirectory?: string;
readonly maxArtifacts?: number;
@@ -364,6 +373,12 @@ export function hardenProject(
options.allowWasmClearParamCarriers !== true
? wasmParmReports.filter((r) => r.shouldRefuseBankrupt)
: [];
+ const jsAesReports = discoverAndLintJsAesUnwrap(absDir);
+ const blockingJsAes =
+ intensityEnforcesJsAesUnwrapRefusal(intensity) &&
+ options.allowJsAesUnwrap !== true
+ ? jsAesReports.filter((r) => r.shouldRefuseBankrupt)
+ : [];
const outputRoot = resolve(
options.outputDirectory ??
(statSync(absDir).isDirectory()
@@ -430,7 +445,7 @@ export function hardenProject(
runId,
} as const;
- if (blockingSeals.length > 0 || blockingWasmParms.length > 0) {
+ if (blockingSeals.length > 0 || blockingWasmParms.length > 0 || blockingJsAes.length > 0) {
const sealArtifacts = blockingSeals.map((r) => ({
inputPath: r.path,
relativePath: (relative(absDir, r.path) || basename(r.path)).split(sep).join("/"),
@@ -455,13 +470,24 @@ export function hardenProject(
outputExisted: false,
error: wasmParamCarrierRefuseMessage(r, r.path),
}));
- const blockReason =
- blockingSeals.length > 0 && blockingWasmParms.length > 0
- ? "skipped: plaintext/reversible seal sidecar or clear WASM param carrier blocked bankrupt harden"
- : blockingWasmParms.length > 0
- ? "skipped: clear WASM param/cipher carrier blocked bankrupt harden"
- : "skipped: plaintext/reversible seal sidecar blocked bankrupt harden";
- const blockedExtras = [...sealArtifacts, ...wasmArtifacts];
+ const jsAesArtifacts = blockingJsAes.map((r) => ({
+ inputPath: r.path,
+ relativePath: (relative(absDir, r.path) || basename(r.path)).split(sep).join("/"),
+ format: "javascript" as const,
+ outputPath: r.path,
+ success: false,
+ defenseScore: 0,
+ tokenAmplificationFactor: 0,
+ costAmplificationFactor: 0,
+ outputExisted: false,
+ error: jsAesUnwrapRefuseMessage(r, r.path),
+ }));
+ const blockParts: string[] = [];
+ if (blockingSeals.length > 0) blockParts.push("plaintext/reversible seal sidecar");
+ if (blockingWasmParms.length > 0) blockParts.push("clear WASM param carrier");
+ if (blockingJsAes.length > 0) blockParts.push("JS AES wrap-key unwrap");
+ const blockReason = `skipped: ${blockParts.join(" / ")} blocked bankrupt harden`;
+ const blockedExtras = [...sealArtifacts, ...wasmArtifacts, ...jsAesArtifacts];
return {
...reportBase,
overallSuccess: false,
@@ -542,6 +568,10 @@ export function hardenProject(
...(options.allowStablePanelDeriveAbi === true
? { allowStablePanelDeriveAbi: true }
: {}),
+ ...(options.allowJsAesUnwrap === true ? { allowJsAesUnwrap: true } : {}),
+ ...(options.allowPanelOfflineOracle === true
+ ? { allowPanelOfflineOracle: true }
+ : {}),
...((() => {
if (options.selfSeal !== true) return {};
const siblings = plannedOutputs
diff --git a/src/engine/protector.ts b/src/engine/protector.ts
index ee44c7c..cc96ad5 100644
--- a/src/engine/protector.ts
+++ b/src/engine/protector.ts
@@ -63,10 +63,17 @@ import {
wasmParamCarrierRefuseMessage,
} from "./wasm-param-carrier-lint.js";
import {
+ intensityEnforcesPanelOracleRefusal,
intensityRewritesPanelDerive,
lintPanelDeriveAbiSource,
+ panelDeriveRefuseMessage,
rewriteStablePanelDeriveSymbols,
} from "./panel-derive-abi-lint.js";
+import {
+ intensityEnforcesJsAesUnwrapRefusal,
+ jsAesUnwrapRefuseMessage,
+ lintJsAesUnwrapSource,
+} from "./js-aes-unwrap-lint.js";
/**
* Crash-safe output write: write to a temp file in the same directory, then
@@ -311,6 +318,25 @@ function protectTargetInner(options: ProtectionOptions): ProtectionResult {
throw new Error(laneIndependenceRefuseMessage(laneReport, absInput));
}
}
+ if (
+ intensityEnforcesJsAesUnwrapRefusal(intensity) &&
+ options.allowJsAesUnwrap !== true
+ ) {
+ const aesReport = lintJsAesUnwrapSource(raw, { path: absInput });
+ if (aesReport.shouldRefuseBankrupt) {
+ throw new Error(jsAesUnwrapRefuseMessage(aesReport, absInput));
+ }
+ }
+ {
+ const panelLint = lintPanelDeriveAbiSource(raw, { path: absInput });
+ if (
+ intensityEnforcesPanelOracleRefusal(intensity) &&
+ options.allowPanelOfflineOracle !== true &&
+ panelLint.shouldRefuseBankrupt
+ ) {
+ throw new Error(panelDeriveRefuseMessage(panelLint, absInput));
+ }
+ }
const panelSafe = applyPanelDeriveRewrite(raw, seed, intensity, options, absInput);
const selfSealOpt = selfSealTransformOption(options, absOutput);
const transformed = transformJavaScriptWithBlaShield(panelSafe, {
@@ -350,6 +376,25 @@ function protectTargetInner(options: ProtectionOptions): ProtectionResult {
counteredVectors.add("obligation-ledger-cloning");
} else if (format === "html-bundle") {
const rawHtml = readFileSync(absInput, "utf8");
+ if (
+ intensityEnforcesJsAesUnwrapRefusal(intensity) &&
+ options.allowJsAesUnwrap !== true
+ ) {
+ const aesReport = lintJsAesUnwrapSource(rawHtml, { path: absInput });
+ if (aesReport.shouldRefuseBankrupt) {
+ throw new Error(jsAesUnwrapRefuseMessage(aesReport, absInput));
+ }
+ }
+ {
+ const panelLint = lintPanelDeriveAbiSource(rawHtml, { path: absInput });
+ if (
+ intensityEnforcesPanelOracleRefusal(intensity) &&
+ options.allowPanelOfflineOracle !== true &&
+ panelLint.shouldRefuseBankrupt
+ ) {
+ throw new Error(panelDeriveRefuseMessage(panelLint, absInput));
+ }
+ }
let inlineScriptsTransformed = 0;
let scriptIndex = 0;
let transformedHtml = rawHtml.replace(
diff --git a/src/mcp/server.ts b/src/mcp/server.ts
index 2473993..d3a2413 100644
--- a/src/mcp/server.ts
+++ b/src/mcp/server.ts
@@ -25,6 +25,10 @@ import {
lintPanelDeriveAbiFile,
type PanelDeriveAbiReport,
} from "../engine/panel-derive-abi-lint.js";
+import {
+ lintJsAesUnwrapFile,
+ type JsAesUnwrapReport,
+} from "../engine/js-aes-unwrap-lint.js";
import {
computeArtifactRunId,
readHardenRunSummary,
@@ -186,7 +190,17 @@ export const BLA_MCP_TOOLS: readonly McpToolDefinition[] = Object.freeze([
allow_stable_panel_derive: {
type: "boolean",
description:
- "Keep stable __vaultPanelDerive_* ABI (skip rewrite). Default false β€” maximum/bankrupt rewrite to seed-stable _blaPd_* (red-blue round-3).",
+ "Keep stable __vaultPanelDerive_* / deriveLocal ABI (skip rewrite). Default false β€” maximum/bankrupt rewrite to seed-stable _blaPd_* / _blaPdLocal_* (red-blue round-3/4).",
+ },
+ allow_js_aes_unwrap: {
+ type: "boolean",
+ description:
+ "Allow bankrupt harden/protect despite JS AES wrap-key + create*iv + fixed sealed-hdr unwrap footguns. Default false β€” refuse (red-blue round-4). Gate only β€” not white-box AES.",
+ },
+ allow_panel_offline_oracle: {
+ type: "boolean",
+ description:
+ "Allow bankrupt harden/protect despite deriveLocal + plaintext panelTokenSha256 offline-oracle packaging. Default false β€” refuse (red-blue round-4).",
},
seed: {
type: "string",
@@ -296,7 +310,17 @@ export const BLA_MCP_TOOLS: readonly McpToolDefinition[] = Object.freeze([
allow_stable_panel_derive: {
type: "boolean",
description:
- "Keep stable __vaultPanelDerive_* ABI (skip rewrite). Default false β€” maximum/bankrupt rewrite to seed-stable _blaPd_* (red-blue round-3).",
+ "Keep stable __vaultPanelDerive_* / deriveLocal ABI (skip rewrite). Default false β€” maximum/bankrupt rewrite to seed-stable _blaPd_* / _blaPdLocal_* (red-blue round-3/4).",
+ },
+ allow_js_aes_unwrap: {
+ type: "boolean",
+ description:
+ "Allow bankrupt harden/protect despite JS AES wrap-key + create*iv + fixed sealed-hdr unwrap footguns. Default false β€” refuse (red-blue round-4). Gate only β€” not white-box AES.",
+ },
+ allow_panel_offline_oracle: {
+ type: "boolean",
+ description:
+ "Allow bankrupt harden/protect despite deriveLocal + plaintext panelTokenSha256 offline-oracle packaging. Default false β€” refuse (red-blue round-4).",
},
seed: {
type: "string",
@@ -387,7 +411,17 @@ export const BLA_MCP_TOOLS: readonly McpToolDefinition[] = Object.freeze([
allow_stable_panel_derive: {
type: "boolean",
description:
- "Keep stable __vaultPanelDerive_* ABI (skip rewrite). Default false β€” maximum/bankrupt rewrite to seed-stable _blaPd_* (red-blue round-3).",
+ "Keep stable __vaultPanelDerive_* / deriveLocal ABI (skip rewrite). Default false β€” maximum/bankrupt rewrite to seed-stable _blaPd_* / _blaPdLocal_* (red-blue round-3/4).",
+ },
+ allow_js_aes_unwrap: {
+ type: "boolean",
+ description:
+ "Allow bankrupt harden/protect despite JS AES wrap-key + create*iv + fixed sealed-hdr unwrap footguns. Default false β€” refuse (red-blue round-4). Gate only β€” not white-box AES.",
+ },
+ allow_panel_offline_oracle: {
+ type: "boolean",
+ description:
+ "Allow bankrupt harden/protect despite deriveLocal + plaintext panelTokenSha256 offline-oracle packaging. Default false β€” refuse (red-blue round-4).",
},
seed: {
type: "string",
@@ -623,7 +657,23 @@ export const BLA_MCP_TOOLS: readonly McpToolDefinition[] = Object.freeze([
{
name: "bla_lint_panel_derive",
description:
- "Read-only panel-derive ABI lint (same engine as CLI `bla lint-panel-derive`). Flags stable __vaultPanelDerive_* globals and classic FNV primes. Maximum/bankrupt protect rewrites the ABI unless allow_stable_panel_derive. Writes nothing.",
+ "Read-only panel-derive ABI lint (same engine as CLI `bla lint-panel-derive`). Flags stable __vaultPanelDerive_* / deriveLocal, classic FNV primes, and deriveLocal+panelTokenSha256 offline-oracle packaging. Maximum/bankrupt rewrites ABI unless allow_stable_panel_derive; bankrupt refuses oracle combo unless allow_panel_offline_oracle. Writes nothing.",
+ inputSchema: {
+ type: "object",
+ properties: {
+ path: {
+ type: "string",
+ description: "Path to a JS/TS/HTML file to lint",
+ },
+ },
+ required: ["path"],
+ additionalProperties: false,
+ },
+ },
+ {
+ name: "bla_lint_js_aes_unwrap",
+ description:
+ "Read-only JS AES wrap-key unwrap lint (same engine as CLI `bla lint-js-aes-unwrap`). Flags hex/base64 wrap-key material + createDecipheriv/createCipheriv + fixed sealed hdr (e.g. d17ea004). Bankrupt harden refuses unless allow_js_aes_unwrap. Gate only β€” not white-box AES. Writes nothing.",
inputSchema: {
type: "object",
properties: {
@@ -895,6 +945,10 @@ function runDefend(handlers: McpEngineHandlers, args: Record<string, unknown>):
...(args.allow_stable_panel_derive === true
? { allowStablePanelDeriveAbi: true }
: {}),
+ ...(args.allow_js_aes_unwrap === true ? { allowJsAesUnwrap: true } : {}),
+ ...(args.allow_panel_offline_oracle === true
+ ? { allowPanelOfflineOracle: true }
+ : {}),
...(typeof args.seed === "string" ? { seed: args.seed } : {}),
});
}
@@ -926,6 +980,10 @@ function runProtect(handlers: McpEngineHandlers, args: Record<string, unknown>):
...(args.allow_stable_panel_derive === true
? { allowStablePanelDeriveAbi: true }
: {}),
+ ...(args.allow_js_aes_unwrap === true ? { allowJsAesUnwrap: true } : {}),
+ ...(args.allow_panel_offline_oracle === true
+ ? { allowPanelOfflineOracle: true }
+ : {}),
});
}
@@ -976,6 +1034,14 @@ function runLintPanelDerive(args: Record<string, unknown>): PanelDeriveAbiReport
return lintPanelDeriveAbiFile(abs);
}
+function runLintJsAesUnwrap(args: Record<string, unknown>): JsAesUnwrapReport {
+ const abs = resolvePath(args.path as string);
+ if (!existsSync(abs)) {
+ throw new Error(`lint-js-aes-unwrap target not found: ${abs}`);
+ }
+ return lintJsAesUnwrapFile(abs);
+}
+
export function validateMcpToolCall(
params: unknown,
):
@@ -1429,12 +1495,16 @@ export async function handleMcpRequest(
? { allowLaneIndependentGates: true }
: {}),
...(args.allow_plaintext_seal === true ? { allowPlaintextSeal: true } : {}),
- ...(args.allow_wasm_clear_params === true
- ? { allowWasmClearParamCarriers: true }
- : {}),
- ...(args.allow_stable_panel_derive === true
- ? { allowStablePanelDeriveAbi: true }
- : {}),
+ ...(args.allow_wasm_clear_params === true
+ ? { allowWasmClearParamCarriers: true }
+ : {}),
+ ...(args.allow_stable_panel_derive === true
+ ? { allowStablePanelDeriveAbi: true }
+ : {}),
+ ...(args.allow_js_aes_unwrap === true ? { allowJsAesUnwrap: true } : {}),
+ ...(args.allow_panel_offline_oracle === true
+ ? { allowPanelOfflineOracle: true }
+ : {}),
...(typeof args.seed === "string" ? { seed: args.seed } : {}),
});
// Dry-run / confirmation_required leave no write receipt; real writes do.
@@ -1556,7 +1626,12 @@ export async function handleMcpRequest(
refused = (payload as WasmParamCarrierReport).shouldRefuseBankrupt;
} else if (name === "bla_lint_panel_derive") {
payload = runLintPanelDerive(args);
- refused = (payload as PanelDeriveAbiReport).shouldRewriteOrRefuse;
+ refused =
+ (payload as PanelDeriveAbiReport).shouldRefuseBankrupt ||
+ (payload as PanelDeriveAbiReport).shouldRewriteOrRefuse;
+ } else if (name === "bla_lint_js_aes_unwrap") {
+ payload = runLintJsAesUnwrap(args);
+ refused = (payload as JsAesUnwrapReport).shouldRefuseBankrupt;
} else if (name === "bla_run_lookup") {
payload = readHardenRunSummary(
args.summary_path as string,
diff --git a/tests/js-aes-unwrap-harden-gate.test.ts b/tests/js-aes-unwrap-harden-gate.test.ts
new file mode 100644
index 0000000..d959cfe
--- /dev/null
+++ b/tests/js-aes-unwrap-harden-gate.test.ts
@@ -0,0 +1,59 @@
+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 { protectTarget } from "../src/engine/protector.js";
+import { hardenProject } from "../src/engine/harden.js";
+import { buildTestJsAesUnwrapFootgun } from "../src/engine/js-aes-unwrap-lint.js";
+
+const dirs: string[] = [];
+afterEach(() => {
+ for (const d of dirs.splice(0)) rmSync(d, { recursive: true, force: true });
+});
+
+describe("red-blue round-4 JS AES unwrap gates", () => {
+ it("bankrupt protect refuses JS AES unwrap footgun unless allowed", () => {
+ const dir = mkdtempSync(join(tmpdir(), "bla-aes-gate-"));
+ dirs.push(dir);
+ const input = join(dir, "license.cjs");
+ const output = join(dir, "license.out.cjs");
+ writeFileSync(input, buildTestJsAesUnwrapFootgun({}), "utf8");
+ expect(() =>
+ protectTarget({
+ inputPath: input,
+ outputPath: output,
+ intensity: "bankrupt",
+ seed: "r4-aes-gate",
+ honeySourceMaps: false,
+ }),
+ ).toThrow(/allowJsAesUnwrap|AES sealed-blob unwrap/);
+ const ok = protectTarget({
+ inputPath: input,
+ outputPath: output,
+ intensity: "bankrupt",
+ seed: "r4-aes-gate",
+ honeySourceMaps: false,
+ allowJsAesUnwrap: true,
+ });
+ expect(ok.detectedFormat).toBe("javascript");
+ });
+
+ it("bankrupt harden refuses project trees with JS AES unwrap footguns", () => {
+ const dir = mkdtempSync(join(tmpdir(), "bla-aes-harden-"));
+ dirs.push(dir);
+ mkdirSync(join(dir, "dist"));
+ writeFileSync(join(dir, "dist", "license.cjs"), buildTestJsAesUnwrapFootgun({}), "utf8");
+ writeFileSync(
+ join(dir, "dist", "core.wasm"),
+ Buffer.from([0x00, 0x61, 0x73, 0x6d, 0x01, 0x00, 0x00, 0x00]),
+ );
+ const report = hardenProject({
+ directory: dir,
+ intensity: "bankrupt",
+ seed: "r4-harden-aes",
+ dryRun: true,
+ });
+ expect(report.overallSuccess).toBe(false);
+ expect(report.artifacts.some((a) => /AES|allowJsAesUnwrap/i.test(a.error ?? ""))).toBe(true);
+ });
+});
diff --git a/tests/mcp-engine-capability-parity.test.ts b/tests/mcp-engine-capability-parity.test.ts
index 088e8a7..3060dd1 100644
--- a/tests/mcp-engine-capability-parity.test.ts
+++ b/tests/mcp-engine-capability-parity.test.ts
@@ -26,6 +26,8 @@ const EXPECTED_MCP_ENGINE_CAPABILITIES: ReadonlyArray<{
"allow_plaintext_seal",
"allow_wasm_clear_params",
"allow_stable_panel_derive",
+ "allow_js_aes_unwrap",
+ "allow_panel_offline_oracle",
"seed",
"dry_run",
"max_artifacts",
@@ -52,6 +54,8 @@ const EXPECTED_MCP_ENGINE_CAPABILITIES: ReadonlyArray<{
"allow_plaintext_seal",
"allow_wasm_clear_params",
"allow_stable_panel_derive",
+ "allow_js_aes_unwrap",
+ "allow_panel_offline_oracle",
"seed",
"in_place",
"confirm_overwrite",
@@ -70,6 +74,8 @@ const EXPECTED_MCP_ENGINE_CAPABILITIES: ReadonlyArray<{
"allow_plaintext_seal",
"allow_wasm_clear_params",
"allow_stable_panel_derive",
+ "allow_js_aes_unwrap",
+ "allow_panel_offline_oracle",
"seed",
"llm_directives",
"in_place",
@@ -105,6 +111,10 @@ const EXPECTED_MCP_ENGINE_CAPABILITIES: ReadonlyArray<{
tool: "bla_lint_panel_derive",
params: ["path"],
},
+ {
+ tool: "bla_lint_js_aes_unwrap",
+ params: ["path"],
+ },
{
tool: "bla_run_lookup",
params: ["summary_path", "run_id"],
diff --git a/tests/mcp-lint-js-aes.test.ts b/tests/mcp-lint-js-aes.test.ts
new file mode 100644
index 0000000..5826e86
--- /dev/null
+++ b/tests/mcp-lint-js-aes.test.ts
@@ -0,0 +1,45 @@
+import { mkdtempSync, rmSync, writeFileSync } from "node:fs";
+import { tmpdir } from "node:os";
+import { join } from "node:path";
+import { afterEach, describe, expect, it } from "vitest";
+import { handleMcpRequest, BLA_MCP_TOOLS } from "../src/mcp/server.js";
+import {
+ buildTestJsAesUnwrapFootgun,
+ JS_AES_UNWRAP_SCHEMA,
+} from "../src/engine/js-aes-unwrap-lint.js";
+
+const tempDirs: string[] = [];
+afterEach(() => {
+ for (const d of tempDirs.splice(0)) rmSync(d, { recursive: true, force: true });
+});
+
+async function call(name: string, args: Record<string, unknown>) {
+ return handleMcpRequest({
+ jsonrpc: "2.0",
+ id: 1,
+ method: "tools/call",
+ params: { name, arguments: args },
+ });
+}
+
+describe("MCP bla_lint_js_aes_unwrap", () => {
+ it("registers once", () => {
+ expect(BLA_MCP_TOOLS.filter((t) => t.name === "bla_lint_js_aes_unwrap")).toHaveLength(1);
+ });
+
+ it("flags R4 footgun with isError", async () => {
+ const dir = mkdtempSync(join(tmpdir(), "bla-mcp-aes-"));
+ tempDirs.push(dir);
+ const file = join(dir, "license.cjs");
+ writeFileSync(file, buildTestJsAesUnwrapFootgun({}), "utf8");
+ const res = await call("bla_lint_js_aes_unwrap", { path: file });
+ expect(res?.error).toBeUndefined();
+ const result = res!.result as {
+ isError?: boolean;
+ structuredContent: { schema: string; shouldRefuseBankrupt: boolean };
+ };
+ expect(result.structuredContent.schema).toBe(JS_AES_UNWRAP_SCHEMA);
+ expect(result.structuredContent.shouldRefuseBankrupt).toBe(true);
+ expect(result.isError).toBe(true);
+ });
+});
diff --git a/tests/panel-oracle-harden-gate.test.ts b/tests/panel-oracle-harden-gate.test.ts
new file mode 100644
index 0000000..9fa927b
--- /dev/null
+++ b/tests/panel-oracle-harden-gate.test.ts
@@ -0,0 +1,57 @@
+import { mkdtempSync, rmSync, writeFileSync } from "node:fs";
+import { tmpdir } from "node:os";
+import { join } from "node:path";
+import { afterEach, describe, expect, it } from "vitest";
+import { protectTarget } from "../src/engine/protector.js";
+import { rewriteStablePanelDeriveSymbols } from "../src/engine/panel-derive-abi-lint.js";
+
+const dirs: string[] = [];
+afterEach(() => {
+ for (const d of dirs.splice(0)) rmSync(d, { recursive: true, force: true });
+});
+
+describe("red-blue round-4 panel oracle gate", () => {
+ it("bankrupt protect refuses deriveLocal + panelTokenSha256 unless allowed", () => {
+ const dir = mkdtempSync(join(tmpdir(), "bla-panel-oracle-"));
+ dirs.push(dir);
+ const input = join(dir, "panel.js");
+ const output = join(dir, "panel.out.js");
+ writeFileSync(
+ input,
+ [
+ "function deriveLocal(key) { return String(key).length.toString(16); }",
+ "function check(seal, key) {",
+ " return deriveLocal(key) === seal.panelTokenSha256;",
+ "}",
+ "module.exports = { deriveLocal, check };",
+ "",
+ ].join("\n"),
+ "utf8",
+ );
+ expect(() =>
+ protectTarget({
+ inputPath: input,
+ outputPath: output,
+ intensity: "bankrupt",
+ seed: "r4-oracle",
+ honeySourceMaps: false,
+ }),
+ ).toThrow(/allowPanelOfflineOracle|panel offline oracle/);
+ const ok = protectTarget({
+ inputPath: input,
+ outputPath: output,
+ intensity: "bankrupt",
+ seed: "r4-oracle",
+ honeySourceMaps: false,
+ allowPanelOfflineOracle: true,
+ });
+ expect(ok.detectedFormat).toBe("javascript");
+ const out = require("node:fs").readFileSync(ok.outputPath, "utf8");
+ expect(out).not.toMatch(/\bfunction\s+deriveLocal\b/);
+ const expected = rewriteStablePanelDeriveSymbols(
+ "function deriveLocal(key) { return key; }",
+ "r4-oracle",
+ ).renames.find((r) => r.from === "deriveLocal")!.to;
+ expect(out).toContain(expected);
+ });
+});