Repository navigation
Description
docs/features.md documents GZIP_MAX_FETCH_SIZE (default 10 MiB) as the cap on what gzip-file-as-resource will fetch. The module parses the variable with Number(...) at load time (tools/gzip-file-as-resource.ts:40-43), so a non-numeric value becomes NaN — and since every comparison against NaN is false, the cap silently stops applying and an over-cap fetch succeeds. There is no attacker path here (the value is the operator's own environment), so this is a documentation-versus-code question rather than a vulnerability report: the attached test pins the documented behaviour, and it fails on the current code. That failure is the question.
The question
The size cap documented for GZIP_MAX_FETCH_SIZE silently stops applying when the variable holds a non-numeric value: the module parses it with Number(...), the result is NaN, and every comparison against NaN is false, so an over-cap fetch succeeds. The attached test pins the documented behavior and fails on the current code. Is the intended behavior (a) fall back to the default on an unparseable value, (b) fail at startup, or (c) treat the variable as operator's-responsibility and document that invalid values disable the cap? The same Number(...) pattern parses GZIP_MAX_FETCH_TIME_MILLIS next to it. Happy to adjust the test to whichever behavior is intended.
Proposed test
As a new file beside src/everything/__tests__/gzip-limits.test.ts (the variable is read at module load, so the test needs its own file, in the same env-stubbing style). The first test is a control — a small fetch still succeeds under the same env. The second test is the one that fails:
/**
* The documented-cap question, as a test. docs/features.md documents
* GZIP_MAX_FETCH_SIZE (default 10 MiB) as the cap on what
* gzip-file-as-resource will fetch.
* The tool parses the variable with Number(...) at module load
* (tools/gzip-file-as-resource.ts:40-43), so a non-numeric value becomes
* NaN and every size comparison against it is false: the cap silently
* stops applying. This file sets the variable to a non-numeric value
* before importing the server (vitest gives each test file its own
* module graph) and asserts the DOCUMENTED behavior — an over-cap fetch
* is refused. On the pinned code the second test FAILS, which is the
* point: it is the question, in executable form. The fixture is on
* loopback, so it also sets GZIP_ALLOW_PRIVATE_IPS.
*/
import { createServer as createHttpServer, type Server } from "node:http";
import { once } from "node:events";
import {
afterAll,
afterEach,
beforeAll,
describe,
expect,
it,
vi,
} from "vitest";
import type { Session } from "./harness.js";
const TEN_MB = 10 * 1024 * 1024;
let harness: typeof import("./harness.js");
let http: Server;
let base: string;
beforeAll(async () => {
vi.stubEnv("GZIP_MAX_FETCH_SIZE", "not-a-number");
vi.stubEnv("GZIP_ALLOW_PRIVATE_IPS", "1");
harness = await import("./harness.js");
http = createHttpServer((req, res) => {
if (req.url === "/big") {
res.writeHead(200, { "content-length": String(TEN_MB + 1) });
res.end(Buffer.alloc(TEN_MB + 1, 0x61));
return;
}
res.end("small");
});
http.listen(0);
await once(http, "listening");
const address = http.address();
if (address === null || typeof address === "string")
throw new Error("no port");
base = `http://127.0.0.1:${address.port}`;
});
afterAll(async () => {
http.closeAllConnections();
await new Promise((resolve) => http.close(resolve));
});
const sessions: Session[] = [];
afterEach(async () => {
await Promise.all(sessions.splice(0).map((s) => s.close()));
});
async function open(): Promise<Session> {
const s = await harness.connect();
sessions.push(s);
return s;
}
describe("gzip-file-as-resource with a non-numeric GZIP_MAX_FETCH_SIZE", () => {
it("still fetches a small file (the tool itself works)", async () => {
const s = await open();
const result = await s.client.callTool({
name: "gzip-file-as-resource",
arguments: { name: "small.txt.gz", data: `${base}/small` },
});
expect(result.isError).toBeFalsy();
});
it("refuses a fetch larger than the documented 10 MiB cap", async () => {
const s = await open();
const result = await s.client.callTool({
name: "gzip-file-as-resource",
arguments: { name: "big.bin.gz", data: `${base}/big` },
});
// Documented expectation: the cap applies, so this is a tool error.
// Pinned behavior (2026-11-11): the fetch SUCCEEDS — the non-numeric
// value disabled the cap. This test is the question attached to the
// report, not a passing pin.
expect(result.isError).toBe(true);
});
});Verification
Ran against a byte-identical copy of v2/main @ 6cfff62 (Node 24, vitest 4.1.12): 1 passed (the small-fetch control) / 1 failed (the over-cap fetch succeeded instead of being refused). The failure is the question in executable form, not a broken run — it fails by succeeding. Full everything suite in the same tree: 481 passed, with this test the only failure. Happy to adjust the test to whichever behaviour is intended.
Prompt used
"In src/everything, the gzip fetch caps come from environment variables parsed once at module load. Write a test that starts the server (in the style of tests/gzip-limits.test.ts, which stubs env before importing the harness) with GZIP_MAX_FETCH_SIZE set to a non-numeric value, serves a body whose Content-Length is one byte over the documented 10 MiB default from a loopback fixture (with GZIP_ALLOW_PRIVATE_IPS=1), and asserts the fetch is refused — the behavior the docs describe. Add a control showing a small fetch still succeeds under the same env. The point of the test is the question it asks; on the current code the refusal assertion fails."
Activity
A7mdMe commentedon Nov 22, 2026
This is a great finding and question. The test suite clearly demonstrates the silent failure mode.
In production MCP deployments and containerized multi-agent environments, Option (a) with a startup/load diagnostic warning is almost universally preferred over (b) or (c) for the following reasons:
Architectural Evaluation of the Options
Why not (c) (Treat as operator-responsibility / silent disable)?
.envfiles where unexpanded template variables (e.g."${MAX_FETCH_SIZE}"), empty strings (""), or intuitive human-readable values like"10MB"or"30s"occur.NaNin JavaScript (payloadSize > NaNandpayloadSize < NaN) evaluate tofalse, the protection cap is silently and completely removed. A memory-safety cap should never fail-open due to a parsing mistake.Why not (b) (Hard crash at startup)?
Why (a) (Fail-closed fallback to documented default + stderr warning) is optimal:
process.stderr(neverstdout, to protect JSON-RPC stdio framing) alerts operators during deployment without breaking client initialization.Additional Consideration: Human-Readable Unit Suffixes
In addition to pure integers, operators frequently pass strings with units (
"10MB","500KB","30s"). StandardNumber()evaluates all of these toNaN.Here is a lightweight, zero-dependency helper pattern that parses unit multipliers, clamps safely to bounds, and guarantees fail-closed fallback to the documented default:
Applying this to
tools/gzip-file-as-resource.tsallows the test in the OP to pass immediately when expecting Option (a) behavior, while also safely handling intuitive operator values like"10 MiB"or"10MB".Disclosure: I maintain the open-source mcp-production-kit and the Production MCP Server Hardening Checklist, where we document and test fail-closed limit parsing and runtime edge cases across the MCP ecosystem.
cliffhall commentedon Nov 30, 2026
Triage: Priority Low (total 5)
GZIP_MAX_FETCH_SIZEsilently disables the documented cap; the value is the operator's own configurationbuglabel (relabelled from a question: the documented behaviour and the code disagree)Board: Servers V2 (#43), Status
Incoming, awaiting maintainer review (no milestone yet).cliffhall commentedon Nov 30, 2026
Fixed by #5703, merged into
v2/main; ships in v2.7.0.