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.

fix(mcp): move stdio JSDoc to the right target and rename MAX_STDIO_LINE_BYTES to MAX_STDIO_LINE_CHARS (#48)

Dery Ferdika0366db1a24e8
diff --git a/src/mcp/server.ts b/src/mcp/server.ts
index 462674d..18d3942 100644
--- a/src/mcp/server.ts
+++ b/src/mcp/server.ts
@@ -956,10 +956,11 @@ export async function handleMcpRequest(
}
/**
- * Starts the BLA MCP server over stdio (supporting newline-delimited JSON-RPC 2.0).
+ * Largest single stdio line accepted before the client is treated as
+ * misbehaving. Measured in UTF-16 code units (`String.length`, matching what
+ * JavaScript reports as a string's "characters"), not bytes.
*/
-/** Largest single stdio line accepted before the client is treated as misbehaving. */
-export const MAX_STDIO_LINE_BYTES = 1_048_576;
+export const MAX_STDIO_LINE_CHARS = 1_048_576;
export interface StdioLineProcessorHooks {
readonly onLine: (line: string) => void;
@@ -995,13 +996,13 @@ export function createStdioLineProcessor(hooks: StdioLineProcessorHooks): StdioL
const line = buffer.slice(0, newlineIdx).trim();
buffer = buffer.slice(newlineIdx + 1);
if (!line || line.startsWith("Content-Length:")) continue;
- if (line.length > MAX_STDIO_LINE_BYTES) {
+ if (line.length > MAX_STDIO_LINE_CHARS) {
hooks.onOversizedLine?.();
continue;
}
hooks.onLine(line);
}
- if (buffer.length > MAX_STDIO_LINE_BYTES) {
+ if (buffer.length > MAX_STDIO_LINE_CHARS) {
buffer = "";
discarding = true;
hooks.onOversizedLine?.();
@@ -1010,6 +1011,9 @@ export function createStdioLineProcessor(hooks: StdioLineProcessorHooks): StdioL
};
}
+/**
+ * Starts the BLA MCP server over stdio (supporting newline-delimited JSON-RPC 2.0).
+ */
export function startMcpStdioServer(): void {
let processingQueue = Promise.resolve();
const processor = createStdioLineProcessor({
@@ -1040,7 +1044,7 @@ export function startMcpStdioServer(): void {
id: null,
error: {
code: -32700,
- message: `Parse error: line exceeds ${MAX_STDIO_LINE_BYTES} byte limit`,
+ message: `Parse error: line exceeds ${MAX_STDIO_LINE_CHARS} character limit`,
},
};
process.stdout.write(JSON.stringify(parseErr) + "\n");
diff --git a/tests/mcp-stdio-limit.test.ts b/tests/mcp-stdio-limit.test.ts
index 49e147a..50999e8 100644
--- a/tests/mcp-stdio-limit.test.ts
+++ b/tests/mcp-stdio-limit.test.ts
@@ -1,5 +1,5 @@
import { describe, expect, it } from "vitest";
-import { createStdioLineProcessor, MAX_STDIO_LINE_BYTES } from "../src/mcp/server.js";
+import { createStdioLineProcessor, MAX_STDIO_LINE_CHARS } from "../src/mcp/server.js";
function collect() {
const lines: string[] = [];
@@ -27,7 +27,7 @@ describe("MCP stdio line processor", () => {
it("rejects an unterminated partial line past the cap and recovers at the next newline", () => {
const { lines, processor, oversizedCount } = collect();
- processor.push("x".repeat(MAX_STDIO_LINE_BYTES + 1));
+ processor.push("x".repeat(MAX_STDIO_LINE_CHARS + 1));
expect(oversizedCount()).toBe(1);
expect(lines).toEqual([]);
// The rest of the oversized line drains silently, then a valid message flows through.
@@ -38,7 +38,7 @@ describe("MCP stdio line processor", () => {
it("rejects a complete single line past the cap instead of parsing it", () => {
const { lines, processor, oversizedCount } = collect();
- processor.push("z".repeat(MAX_STDIO_LINE_BYTES + 1) + "\n");
+ processor.push("z".repeat(MAX_STDIO_LINE_CHARS + 1) + "\n");
expect(oversizedCount()).toBe(1);
expect(lines).toEqual([]);
// Buffer must be empty again: the next small message is not poisoned.