feat(harden/mcp/cli): bankrupt refuse JS WASM hydrate-dump + skill v1.5.8

Wire lint into harden/protect/defend/auditor, CLI
`lint-js-wasm-hydrate-dump` / `--allow-js-wasm-hydrate-dump`, MCP
`bla_lint_js_wasm_hydrate_dump` + allow_js_wasm_hydrate_dump, and
document the round-5 residual (prefer in-WASM ARX+certify).
This commit is contained in:
qybaihe
2026-11-03 04:29:28 +08:00
parent 9bb3b74a31
commit 4ca075ef55
12 changed files with 233 additions and 5 deletions
+4 -3
View File
@@ -7,14 +7,14 @@ description: >
Agents). Prefer this skill as the guide; call existing MCP tools / CLI — do not invent
new MCP tools. Default verb: bla_harden. Refuse crack/RE of third-party software.
metadata:
version: "1.5.6"
version: "1.5.8"
---
# BLA: Blind LLM Agents
**This skill is the primary one-click harden GUIDE.** MCP (`bla` server) and the
`bla-agents` CLI are the **execution layer**. Prefer teaching/calling existing tools
(`bla_harden`, `bla_defend`, `bla_weave_plan`, `bla_lint_lanes`, `bla_lint_seal`, `bla_lint_wasm_params`, `bla_lint_panel_derive`, …) over inventing new
(`bla_harden`, `bla_defend`, `bla_weave_plan`, `bla_lint_lanes`, `bla_lint_seal`, `bla_lint_wasm_params`, `bla_lint_panel_derive`, `bla_lint_js_aes_unwrap`, `bla_lint_js_wasm_hydrate_dump`, …) over inventing new
MCP surfaces.
Use BLA whenever the user asks to harden a project against AI reverse-engineering
@@ -24,7 +24,7 @@ model misjudgment on proprietary logic, or **one-click / 一键加固** a build.
Defensive only: protect **their own** artifacts. Refuse crack, RE, bypass PoCs, or
attack playbooks against software they do not own.
**Principles (red-blue round-1+2+3+4):** do not ship a stable public WASM ABI without an explicit `wasm_preserve_exports` list; do not leave JS-side independent lane tables — prefer whole-key chained mixing (`bla_lint_lanes` / harden refuse). **Do not** place plaintext seal/catalog JSON (`revision`, salts, certificate ciphertext) beside hardened outputs. Public compare targets must be **one-way** (SHA-256/HMAC/etc.); reversible ARX/Feistel digests as public `revision` are a key-recovery footgun (round-2 break — **closed in round-3** when seal is digests-only). Enforce with `bla_lint_seal` / `bla lint-seal`; bankrupt harden **refuses** unless `allow_plaintext_seal` / `--allow-plaintext-seal`. Round-3 residual **gates**: `bla_lint_wasm_params` / `bla lint-wasm-params` — bankrupt refuses clear `R2SEAL`/`R3PARM`/`R3CIPH`-class carriers unless `allow_wasm_clear_params`; `bla_lint_panel_derive` — maximum/bankrupt **rewrites** `__vaultPanelDerive_*` to `_blaPd_*` unless `allow_stable_panel_derive`; bankrupt harden sets `selfSealRecommended` for multi-artifact trees (never auto for single-file) — prefer **`self_seal`**. Round-4 gates: `bla_lint_js_aes_unwrap` / `bla lint-js-aes-unwrap` — bankrupt **refuses** JS wrap-key + `create*iv` + fixed sealed hdr (e.g. `d17ea004`) unless `allow_js_aes_unwrap` (gate only — **not** white-box AES; prefer in-WASM unwrap). `bla_lint_panel_derive` flags `deriveLocal` (rewritten to `_blaPdLocal_*`) and **refuses** `deriveLocal` + plaintext `panelTokenSha256` offline-oracle packaging unless `allow_panel_offline_oracle` (rename is not a crypto fix — scrub digests / avoid derive UI). `self_seal` embeds **expected sibling SHA-256 hard-fail** when siblings exist at protect time (harden processes JS last); opaque-seed entanglement alone does **not** gate entitlement control flow.
**Principles (red-blue round-1+2+3+4):** do not ship a stable public WASM ABI without an explicit `wasm_preserve_exports` list; do not leave JS-side independent lane tables — prefer whole-key chained mixing (`bla_lint_lanes` / harden refuse). **Do not** place plaintext seal/catalog JSON (`revision`, salts, certificate ciphertext) beside hardened outputs. Public compare targets must be **one-way** (SHA-256/HMAC/etc.); reversible ARX/Feistel digests as public `revision` are a key-recovery footgun (round-2 break — **closed in round-3** when seal is digests-only). Enforce with `bla_lint_seal` / `bla lint-seal`; bankrupt harden **refuses** unless `allow_plaintext_seal` / `--allow-plaintext-seal`. Round-3 residual **gates**: `bla_lint_wasm_params` / `bla lint-wasm-params` — bankrupt refuses clear `R2SEAL`/`R3PARM`/`R3CIPH`-class carriers unless `allow_wasm_clear_params`; `bla_lint_panel_derive` — maximum/bankrupt **rewrites** `__vaultPanelDerive_*` to `_blaPd_*` unless `allow_stable_panel_derive`; bankrupt harden sets `selfSealRecommended` for multi-artifact trees (never auto for single-file) — prefer **`self_seal`**. Round-4 gates: `bla_lint_js_aes_unwrap` / `bla lint-js-aes-unwrap` — bankrupt **refuses** JS wrap-key + `create*iv` + fixed sealed hdr (e.g. `d17ea004`) unless `allow_js_aes_unwrap` (gate only — **not** white-box AES; prefer in-WASM unwrap). `bla_lint_panel_derive` flags `deriveLocal` (rewritten to `_blaPdLocal_*`) and **refuses** `deriveLocal` + plaintext `panelTokenSha256` offline-oracle packaging unless `allow_panel_offline_oracle` (rename is not a crypto fix — scrub digests / avoid derive UI). `self_seal` embeds **expected sibling SHA-256 hard-fail** when siblings exist at protect time (harden processes JS last); opaque-seed entanglement alone does **not** gate entitlement control flow. Round-5 gates: `bla_lint_js_wasm_hydrate_dump` / `bla lint-js-wasm-hydrate-dump` — bankrupt **refuses** JS that copies salt/rounds/cipher from `WebAssembly.Memory` after hydrate/instantiate unless `allow_js_wasm_hydrate_dump` (host memory dump needs **no** Node `create*iv`; export rename alone does not close this — prefer keep ARX+certify **inside** WASM so params never re-enter JS).
## Prerequisites (once)
@@ -108,6 +108,7 @@ npx -y bla-agents@latest doctor
npx -y bla-agents@latest harden .
npx -y bla-agents@latest harden . --weave-decoys --self-seal
npx -y bla-agents@latest lint-lanes path/to/gate.js
npx -y bla-agents@latest lint-js-wasm-hydrate-dump path/to/license.cjs
npx -y bla-agents@latest defend /absolute/path/to/target --manifest --json
npx -y bla-agents@latest verify /absolute/path/to/protected /absolute/path/to/target --json
```
+1
View File
@@ -31,6 +31,7 @@ For coding agents, the **[`blind-llm-agents` skill](../.agents/skills/blind-llm-
- `bla_lint_wasm_params`: Read-only WASM clear param/cipher carrier lint (`path`) — `R3PARM`/`R3CIPH`/`R2SEAL`-class; same engine as CLI `bla lint-wasm-params`.
- `bla_lint_panel_derive`: Read-only panel-derive ABI lint (`path`) — stable `__vaultPanelDerive_*` / `deriveLocal` / `panelTokenSha256` oracle; same engine as CLI `bla lint-panel-derive`.
- `bla_lint_js_aes_unwrap`: Read-only JS AES wrap-key unwrap lint (`path`) — wrap-key + create*iv + fixed hdr; same engine as CLI `bla lint-js-aes-unwrap`. Gate only — not white-box AES.
- `bla_lint_js_wasm_hydrate_dump`: Read-only JS←WASM hydrate param-dump lint (`path`) — memory.buffer + salt/rounds/cipher after hydrate; same engine as CLI `bla lint-js-wasm-hydrate-dump`. Prefer in-WASM ARX+certify.
- `bla_run_lookup`: Read-only harden-run correlation (`summary_path`, optional `run_id`). Summaries are **unsigned**; missing/mismatched id is an error.
- `bla_rea_drift`: Thin wrapper over `npm run verify:rea` / `scripts/verify-rea-constants.mjs`. Absent sibling REA → `status: unverified` (not red-team evidence).
- `bla_redteam_report`: Read (or `execute:true` re-run) `docs/redteam/empirical-rea-validation.json`. On-disk read → `status: available` (not a live REA verdict); `execute:true` → `pass`/`fail`; missing report / unready REA → `status: unverified`.
+42
View File
@@ -16,6 +16,7 @@ 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 { lintJsWasmHydrateDumpFile } from "./engine/js-wasm-hydrate-dump-lint.js";
import { runShowcaseBenchmark } from "./engine/benchmark.js";
import {
emitCompileTimeNativeHeader,
@@ -59,6 +60,7 @@ Commands:
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_* / 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-js-wasm-hydrate-dump <file> Heuristic ERROR if JS dumps WASM hydrate salt/rounds/cipher; 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
@@ -82,6 +84,7 @@ Options:
--wasm-preserve-exports <a,b> Comma-separated WASM export names to keep as public ABI (issue #40.3)
--allow-lane-independent Allow harden/defend of lane-independent JS gates (issue #40.1); OFF by default
--allow-plaintext-seal Allow bankrupt harden despite plaintext/reversible seal JSON (round-2); OFF by default
--allow-js-wasm-hydrate-dump Allow bankrupt despite JS←WASM hydrate param-dump (round-5); OFF by default
--lang <c|rust|go> Target language for emit-headers (default: c)
--client <id> Agent client ID for setup (repeatable: claude_code, cursor, codex, etc.)
--all-detected Configure all detected coding agents on this machine
@@ -112,6 +115,7 @@ interface ParsedCliArgs {
readonly allowStablePanelDeriveAbi: boolean;
readonly allowJsAesUnwrap: boolean;
readonly allowPanelOfflineOracle: boolean;
readonly allowJsWasmHydrateDump: boolean;
readonly lang: NativeHeaderLanguage;
readonly clients: SupportedAgentClientId[];
readonly allDetected: boolean;
@@ -143,6 +147,7 @@ export function parseCliArgs(argv: readonly string[]): ParsedCliArgs {
let allowWasmClearParamCarriers = false;
let allowStablePanelDeriveAbi = false;
let allowJsAesUnwrap = false;
let allowJsWasmHydrateDump = false;
let allowPanelOfflineOracle = false;
let lang: NativeHeaderLanguage = "c";
const clients: SupportedAgentClientId[] = [];
@@ -196,6 +201,8 @@ export function parseCliArgs(argv: readonly string[]): ParsedCliArgs {
allowJsAesUnwrap = true;
} else if (arg === "--allow-panel-offline-oracle") {
allowPanelOfflineOracle = true;
} else if (arg === "--allow-js-wasm-hydrate-dump") {
allowJsWasmHydrateDump = true;
} else if (arg.startsWith("--wasm-preserve-exports=")) {
wasmPreserveExports = arg
.slice("--wasm-preserve-exports=".length)
@@ -257,6 +264,7 @@ export function parseCliArgs(argv: readonly string[]): ParsedCliArgs {
allowStablePanelDeriveAbi,
allowJsAesUnwrap,
allowPanelOfflineOracle,
allowJsWasmHydrateDump,
lang,
clients,
allDetected,
@@ -406,6 +414,9 @@ export async function runCli(argv: readonly string[] = process.argv.slice(2)): P
allowPanelOfflineOracle:
parsed.allowPanelOfflineOracle ||
loaded.config.allowPanelOfflineOracle === true,
allowJsWasmHydrateDump:
parsed.allowJsWasmHydrateDump ||
loaded.config.allowJsWasmHydrateDump === true,
...(parsed.output !== undefined ? { outputDirectory: parsed.output } : {}),
});
if (parsed.json) {
@@ -464,6 +475,9 @@ export async function runCli(argv: readonly string[] = process.argv.slice(2)): P
allowPanelOfflineOracle:
parsed.allowPanelOfflineOracle ||
loaded.config.allowPanelOfflineOracle === true,
allowJsWasmHydrateDump:
parsed.allowJsWasmHydrateDump ||
loaded.config.allowJsWasmHydrateDump === true,
});
if (parsed.sarif) {
console.log(
@@ -603,6 +617,31 @@ export async function runCli(argv: readonly string[] = process.argv.slice(2)): P
: 0;
}
case "lint-js-wasm-hydrate-dump": {
const target = parsed.positionals[0];
if (!target) {
console.error("Error: Missing <file> path for `bla lint-js-wasm-hydrate-dump <file>`.");
return 1;
}
const report = lintJsWasmHydrateDumpFile(resolve(target));
if (parsed.json) {
console.log(JSON.stringify(report, null, 2));
} else {
console.log(`BLA js-wasm-hydrate-dump 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;
@@ -667,6 +706,9 @@ export async function runCli(argv: readonly string[] = process.argv.slice(2)): P
allowPanelOfflineOracle:
parsed.allowPanelOfflineOracle ||
loaded.config.allowPanelOfflineOracle === true,
allowJsWasmHydrateDump:
parsed.allowJsWasmHydrateDump ||
loaded.config.allowJsWasmHydrateDump === true,
});
if (parsed.json) console.log(JSON.stringify(res, null, 2));
else console.log(formatProtectionResult(res));
+2
View File
@@ -34,6 +34,8 @@ export interface BlaProjectConfig {
readonly allowJsAesUnwrap?: boolean;
/** When true, allow bankrupt despite panel offline-oracle packaging (red-blue round-4). Default false. */
readonly allowPanelOfflineOracle?: boolean;
/** When true, allow bankrupt despite JS←WASM hydrate param-dump (red-blue round-5). Default false. */
readonly allowJsWasmHydrateDump?: boolean;
}
/**
+5
View File
@@ -206,6 +206,11 @@ export interface ProtectionOptions {
* plaintext panelTokenSha256 offline-oracle packaging (red-blue round-4). Default false — refuse.
*/
readonly allowPanelOfflineOracle?: boolean;
/**
* When true, allow bankrupt harden/protect despite JS←WASM hydrate memory
* dumps of salt/rounds/cipher (red-blue round-5). Default false — refuse.
*/
readonly allowJsWasmHydrateDump?: 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.
+15
View File
@@ -18,6 +18,7 @@ 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 { lintJsWasmHydrateDumpSource } from "./js-wasm-hydrate-dump-lint.js";
import { inspectPythonPyc } from "../shields/formats/python.js";
import { inspectNativeBinary } from "../shields/formats/native.js";
import { detectBunStandaloneGraph } from "../shields/formats/bun-standalone.js";
@@ -519,6 +520,20 @@ export function auditTarget(targetPath: string): AuditReport {
reason: f.summary,
});
}
const hydrateDumpLint = lintJsWasmHydrateDumpSource(text, { path: absPath });
for (const f of hydrateDumpLint.findings) {
exposedItems.push({
id: `js_wasm_hydrate_${f.id}`,
name: f.id,
kind: "export",
location: basename(absPath),
riskLevel: f.severity === "error" ? "high" : "medium",
reaToolUsed: "bla lint-js-wasm-hydrate-dump / static source scan",
estimatedTokensToReconstruct: 1_600,
estimatedCostUsd: 0.06,
reason: f.summary,
});
}
res.vectors.forEach((v) => vulnerableVectors.add(v));
} else if (format === "html-bundle") {
const htmlText = rawBytes.toString("utf8");
+5
View File
@@ -41,6 +41,8 @@ export interface OneClickDefenseOptions {
readonly allowJsAesUnwrap?: boolean;
/** Allow bankrupt despite panel offline-oracle packaging (red-blue round-4). Default false. */
readonly allowPanelOfflineOracle?: boolean;
/** Allow bankrupt despite JS←WASM hydrate param-dump (red-blue round-5). Default false. */
readonly allowJsWasmHydrateDump?: boolean;
/** Sibling paths forwarded into self-seal when enabled (multi-artifact harden). */
readonly selfSealSiblingPaths?: readonly string[];
}
@@ -148,6 +150,9 @@ export function defendTarget(options: OneClickDefenseOptions): OneClickDefenseRe
...(options.allowPanelOfflineOracle === true
? { allowPanelOfflineOracle: true }
: {}),
...(options.allowJsWasmHydrateDump === true
? { allowJsWasmHydrateDump: true }
: {}),
...(options.selfSealSiblingPaths !== undefined &&
options.selfSealSiblingPaths.length > 0
? { selfSealSiblingPaths: options.selfSealSiblingPaths }
+29 -2
View File
@@ -28,6 +28,11 @@ import {
intensityEnforcesJsAesUnwrapRefusal,
jsAesUnwrapRefuseMessage,
} from "./js-aes-unwrap-lint.js";
import {
discoverAndLintJsWasmHydrateDump,
intensityEnforcesJsWasmHydrateDumpRefusal,
jsWasmHydrateDumpRefuseMessage,
} from "./js-wasm-hydrate-dump-lint.js";
import {
computeHardenRunId,
HARDEN_SUMMARY_FILE_NAME,
@@ -128,6 +133,8 @@ export interface HardenProjectOptions {
readonly allowStablePanelDeriveAbi?: boolean;
/** Allow bankrupt despite JS AES wrap-key unwrap footguns (red-blue round-4). Default false. */
readonly allowJsAesUnwrap?: boolean;
/** Lab-only: allow JS←WASM hydrate memory dump of salt/rounds/cipher (red/blue r5). */
readonly allowJsWasmHydrateDump?: 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`. */
@@ -379,6 +386,12 @@ export function hardenProject(
options.allowJsAesUnwrap !== true
? jsAesReports.filter((r) => r.shouldRefuseBankrupt)
: [];
const jsHydrateDumpReports = discoverAndLintJsWasmHydrateDump(absDir);
const blockingJsHydrateDump =
intensityEnforcesJsWasmHydrateDumpRefusal(intensity) &&
options.allowJsWasmHydrateDump !== true
? jsHydrateDumpReports.filter((r) => r.shouldRefuseBankrupt)
: [];
const outputRoot = resolve(
options.outputDirectory ??
(statSync(absDir).isDirectory()
@@ -445,7 +458,7 @@ export function hardenProject(
runId,
} as const;
if (blockingSeals.length > 0 || blockingWasmParms.length > 0 || blockingJsAes.length > 0) {
if (blockingSeals.length > 0 || blockingWasmParms.length > 0 || blockingJsAes.length > 0 || blockingJsHydrateDump.length > 0) {
const sealArtifacts = blockingSeals.map((r) => ({
inputPath: r.path,
relativePath: (relative(absDir, r.path) || basename(r.path)).split(sep).join("/"),
@@ -482,12 +495,25 @@ export function hardenProject(
outputExisted: false,
error: jsAesUnwrapRefuseMessage(r, r.path),
}));
const jsHydrateDumpArtifacts = blockingJsHydrateDump.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: jsWasmHydrateDumpRefuseMessage(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");
if (blockingJsHydrateDump.length > 0) blockParts.push("JS WASM hydrate param-dump");
const blockReason = `skipped: ${blockParts.join(" / ")} blocked bankrupt harden`;
const blockedExtras = [...sealArtifacts, ...wasmArtifacts, ...jsAesArtifacts];
const blockedExtras = [...sealArtifacts, ...wasmArtifacts, ...jsAesArtifacts, ...jsHydrateDumpArtifacts];
return {
...reportBase,
overallSuccess: false,
@@ -569,6 +595,7 @@ export function hardenProject(
? { allowStablePanelDeriveAbi: true }
: {}),
...(options.allowJsAesUnwrap === true ? { allowJsAesUnwrap: true } : {}),
...(options.allowJsWasmHydrateDump === true ? { allowJsWasmHydrateDump: true } : {}),
...(options.allowPanelOfflineOracle === true
? { allowPanelOfflineOracle: true }
: {}),
+23
View File
@@ -74,6 +74,11 @@ import {
jsAesUnwrapRefuseMessage,
lintJsAesUnwrapSource,
} from "./js-aes-unwrap-lint.js";
import {
intensityEnforcesJsWasmHydrateDumpRefusal,
jsWasmHydrateDumpRefuseMessage,
lintJsWasmHydrateDumpSource,
} from "./js-wasm-hydrate-dump-lint.js";
/**
* Crash-safe output write: write to a temp file in the same directory, then
@@ -327,6 +332,15 @@ function protectTargetInner(options: ProtectionOptions): ProtectionResult {
throw new Error(jsAesUnwrapRefuseMessage(aesReport, absInput));
}
}
if (
intensityEnforcesJsWasmHydrateDumpRefusal(intensity) &&
options.allowJsWasmHydrateDump !== true
) {
const hydrateDumpReport = lintJsWasmHydrateDumpSource(raw, { path: absInput });
if (hydrateDumpReport.shouldRefuseBankrupt) {
throw new Error(jsWasmHydrateDumpRefuseMessage(hydrateDumpReport, absInput));
}
}
{
const panelLint = lintPanelDeriveAbiSource(raw, { path: absInput });
if (
@@ -385,6 +399,15 @@ function protectTargetInner(options: ProtectionOptions): ProtectionResult {
throw new Error(jsAesUnwrapRefuseMessage(aesReport, absInput));
}
}
if (
intensityEnforcesJsWasmHydrateDumpRefusal(intensity) &&
options.allowJsWasmHydrateDump !== true
) {
const hydrateDumpReport = lintJsWasmHydrateDumpSource(rawHtml, { path: absInput });
if (hydrateDumpReport.shouldRefuseBankrupt) {
throw new Error(jsWasmHydrateDumpRefuseMessage(hydrateDumpReport, absInput));
}
}
{
const panelLint = lintPanelDeriveAbiSource(rawHtml, { path: absInput });
if (
+55
View File
@@ -29,6 +29,10 @@ import {
lintJsAesUnwrapFile,
type JsAesUnwrapReport,
} from "../engine/js-aes-unwrap-lint.js";
import {
lintJsWasmHydrateDumpFile,
type JsWasmHydrateDumpReport,
} from "../engine/js-wasm-hydrate-dump-lint.js";
import {
computeArtifactRunId,
readHardenRunSummary,
@@ -202,6 +206,11 @@ export const BLA_MCP_TOOLS: readonly McpToolDefinition[] = Object.freeze([
description:
"Allow bankrupt harden/protect despite deriveLocal + plaintext panelTokenSha256 offline-oracle packaging. Default false — refuse (red-blue round-4).",
},
allow_js_wasm_hydrate_dump: {
type: "boolean",
description:
"Allow bankrupt harden/protect despite JS←WASM hydrate memory dumps of salt/rounds/cipher. Default false — refuse (red-blue round-5). Prefer in-WASM ARX+certify; gate only.",
},
seed: {
type: "string",
description: "Optional deterministic seed; when omitted, BLA uses/persists a per-project random seed in .blarc",
@@ -322,6 +331,11 @@ export const BLA_MCP_TOOLS: readonly McpToolDefinition[] = Object.freeze([
description:
"Allow bankrupt harden/protect despite deriveLocal + plaintext panelTokenSha256 offline-oracle packaging. Default false — refuse (red-blue round-4).",
},
allow_js_wasm_hydrate_dump: {
type: "boolean",
description:
"Allow bankrupt harden/protect despite JS←WASM hydrate memory dumps of salt/rounds/cipher. Default false — refuse (red-blue round-5). Prefer in-WASM ARX+certify; gate only.",
},
seed: {
type: "string",
description: "Optional deterministic seed; when omitted, BLA uses/persists a per-project random seed in .blarc",
@@ -423,6 +437,11 @@ export const BLA_MCP_TOOLS: readonly McpToolDefinition[] = Object.freeze([
description:
"Allow bankrupt harden/protect despite deriveLocal + plaintext panelTokenSha256 offline-oracle packaging. Default false — refuse (red-blue round-4).",
},
allow_js_wasm_hydrate_dump: {
type: "boolean",
description:
"Allow bankrupt harden/protect despite JS←WASM hydrate memory dumps of salt/rounds/cipher. Default false — refuse (red-blue round-5). Prefer in-WASM ARX+certify; gate only.",
},
seed: {
type: "string",
description: "Optional deterministic seed; when omitted, BLA mints an ephemeral random seed (prefer project .blarc via CLI)",
@@ -686,6 +705,22 @@ export const BLA_MCP_TOOLS: readonly McpToolDefinition[] = Object.freeze([
additionalProperties: false,
},
},
{
name: "bla_lint_js_wasm_hydrate_dump",
description:
"Read-only JS←WASM hydrate param-dump lint (same engine as CLI `bla lint-js-wasm-hydrate-dump`). Flags memory.buffer reads + salt/rounds/cipher layout decode after hydrate/instantiate. Bankrupt harden refuses unless allow_js_wasm_hydrate_dump. Prefer keep ARX+certify inside WASM. 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_run_lookup",
description:
@@ -949,6 +984,9 @@ function runDefend(handlers: McpEngineHandlers, args: Record<string, unknown>):
...(args.allow_panel_offline_oracle === true
? { allowPanelOfflineOracle: true }
: {}),
...(args.allow_js_wasm_hydrate_dump === true
? { allowJsWasmHydrateDump: true }
: {}),
...(typeof args.seed === "string" ? { seed: args.seed } : {}),
});
}
@@ -984,6 +1022,9 @@ function runProtect(handlers: McpEngineHandlers, args: Record<string, unknown>):
...(args.allow_panel_offline_oracle === true
? { allowPanelOfflineOracle: true }
: {}),
...(args.allow_js_wasm_hydrate_dump === true
? { allowJsWasmHydrateDump: true }
: {}),
});
}
@@ -1042,6 +1083,14 @@ function runLintJsAesUnwrap(args: Record<string, unknown>): JsAesUnwrapReport {
return lintJsAesUnwrapFile(abs);
}
function runLintJsWasmHydrateDump(args: Record<string, unknown>): JsWasmHydrateDumpReport {
const abs = resolvePath(args.path as string);
if (!existsSync(abs)) {
throw new Error(`lint-js-wasm-hydrate-dump target not found: ${abs}`);
}
return lintJsWasmHydrateDumpFile(abs);
}
export function validateMcpToolCall(
params: unknown,
):
@@ -1505,6 +1554,9 @@ export async function handleMcpRequest(
...(args.allow_panel_offline_oracle === true
? { allowPanelOfflineOracle: true }
: {}),
...(args.allow_js_wasm_hydrate_dump === true
? { allowJsWasmHydrateDump: true }
: {}),
...(typeof args.seed === "string" ? { seed: args.seed } : {}),
});
// Dry-run / confirmation_required leave no write receipt; real writes do.
@@ -1632,6 +1684,9 @@ export async function handleMcpRequest(
} else if (name === "bla_lint_js_aes_unwrap") {
payload = runLintJsAesUnwrap(args);
refused = (payload as JsAesUnwrapReport).shouldRefuseBankrupt;
} else if (name === "bla_lint_js_wasm_hydrate_dump") {
payload = runLintJsWasmHydrateDump(args);
refused = (payload as JsWasmHydrateDumpReport).shouldRefuseBankrupt;
} else if (name === "bla_run_lookup") {
payload = readHardenRunSummary(
args.summary_path as string,
@@ -28,6 +28,7 @@ const EXPECTED_MCP_ENGINE_CAPABILITIES: ReadonlyArray<{
"allow_stable_panel_derive",
"allow_js_aes_unwrap",
"allow_panel_offline_oracle",
"allow_js_wasm_hydrate_dump",
"seed",
"dry_run",
"max_artifacts",
@@ -56,6 +57,7 @@ const EXPECTED_MCP_ENGINE_CAPABILITIES: ReadonlyArray<{
"allow_stable_panel_derive",
"allow_js_aes_unwrap",
"allow_panel_offline_oracle",
"allow_js_wasm_hydrate_dump",
"seed",
"in_place",
"confirm_overwrite",
@@ -76,6 +78,7 @@ const EXPECTED_MCP_ENGINE_CAPABILITIES: ReadonlyArray<{
"allow_stable_panel_derive",
"allow_js_aes_unwrap",
"allow_panel_offline_oracle",
"allow_js_wasm_hydrate_dump",
"seed",
"llm_directives",
"in_place",
@@ -115,6 +118,10 @@ const EXPECTED_MCP_ENGINE_CAPABILITIES: ReadonlyArray<{
tool: "bla_lint_js_aes_unwrap",
params: ["path"],
},
{
tool: "bla_lint_js_wasm_hydrate_dump",
params: ["path"],
},
{
tool: "bla_run_lookup",
params: ["summary_path", "run_id"],
@@ -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 {
buildTestJsWasmHydrateDumpFootgun,
JS_WASM_HYDRATE_DUMP_SCHEMA,
} from "../src/engine/js-wasm-hydrate-dump-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_wasm_hydrate_dump", () => {
it("registers once", () => {
expect(BLA_MCP_TOOLS.filter((t) => t.name === "bla_lint_js_wasm_hydrate_dump")).toHaveLength(1);
});
it("flags R5 footgun with isError", async () => {
const dir = mkdtempSync(join(tmpdir(), "bla-mcp-hydrate-"));
tempDirs.push(dir);
const file = join(dir, "license.cjs");
writeFileSync(file, buildTestJsWasmHydrateDumpFootgun({}), "utf8");
const res = await call("bla_lint_js_wasm_hydrate_dump", { path: file });
expect(res?.error).toBeUndefined();
const result = res!.result as {
isError?: boolean;
structuredContent: { schema: string; shouldRefuseBankrupt: boolean };
};
expect(result.structuredContent.schema).toBe(JS_WASM_HYDRATE_DUMP_SCHEMA);
expect(result.structuredContent.shouldRefuseBankrupt).toBe(true);
expect(result.isError).toBe(true);
});
});