fix(security): migrate input-validator to zod ^4.6.7 (GHSA-mrhx-c7xc-m3w5)

zod < 4.6.6 can exhaust memory while validating oversized constrained
collections (high severity). @claude-flow/security declared zod ^3.22.0,
so every consumer of it (memory, hooks, codex, federation and the cli
bundle) carried a vulnerable zod. A fresh `npm i @claude-flow/memory@3.2.4`
reports 3 high findings via @claude-flow/security -> zod 3.25.76.

API changes handled:
- z.setErrorMap(fn(issue, ctx)) -> z.config({ customError }), with
  invalid_string/validation becoming invalid_format/format. Messages given
  to a check still take precedence; undefined falls back to zod's default.
- z.string().ip({version}) -> z.ipv4() / z.union([z.ipv4(), z.ipv6()]),
  keeping the messages.
- z.record(value) -> z.record(z.string(), value).
- SafeParseReturnType/ZodSchema -> ZodSafeParseResult/ZodType.

The workspace lockfile also drops zod 4.3.5 (vulnerable). Version 3.0.7,
and the cli and claude-flow pins move to 3.0.7. Publishing
@claude-flow/security only; the cli and claude-flow ride the release lane.

Tests: the existing 631 pass. input-validator-zod4.test.ts pins the
installed zod at >= 4.6.6, the IP schemas, message precedence, the global
map and the record schemas.

Co-Authored-By: claude-flow <ruv@ruv.net>
This commit is contained in:
ruv committed 2026-11-08 21:11:43 -05:00
1 parent 98ddf415b2
commit d77ecbe0bd
7 files changed
+118 -93

No files matched your search

+12 -3
View File
@@ -26,7 +26,7 @@
"@claude-flow/mcp": "3.1.6",
"@claude-flow/neural": "3.0.3",
"@claude-flow/plugin-agent-federation": "1.0.7",
"@claude-flow/security": "3.0.6",
"@claude-flow/security": "3.0.7",
"@claude-flow/shared": "3.0.7",
"@electron/asar": "^4.3.1",
"@iarna/toml": "^2.2.5",
@@ -15331,11 +15331,11 @@
}
},
"v3/@claude-flow/security": {
"version": "3.0.6",
"version": "3.0.7",
"dependencies": {
"@noble/ed25519": "^2.1.0",
"bcryptjs": "^3.0.3",
"zod": "^3.22.0"
"zod": "^4.6.7"
},
"devDependencies": {
"vitest": "^4.1.0"
@@ -15591,6 +15591,15 @@
}
}
},
"v3/@claude-flow/security/node_modules/zod": {
"version": "4.6.7",
"resolved": "https://registry.npmjs.org/zod/-/zod-4.6.7.tgz",
"integrity": "sha512-g8W2D2kU6a8untc053fX1uVBKzM7yqAxW/3zwk83+6RyF2+SKOuV+c0wBDhUwzV1PaGapmZH+rmcUzPf+3CGwg==",
"license": "MIT",
"funding": {
"url": "https://github.com/sponsors/colinhacks"
}
},
"v3/@claude-flow/shared": {
"version": "3.0.7",
"dev": true,
+1 -1
View File
@@ -74,7 +74,7 @@
"@claude-flow/mcp": "3.1.6",
"@claude-flow/neural": "3.0.3",
"@claude-flow/plugin-agent-federation": "1.0.7",
"@claude-flow/security": "3.0.6",
"@claude-flow/security": "3.0.7",
"@claude-flow/shared": "3.0.7",
"@electron/asar": "^4.3.1",
"@iarna/toml": "^2.2.5",
+1 -1
View File
@@ -106,7 +106,7 @@
"@claude-flow/mcp": "3.1.6",
"@claude-flow/neural": "3.0.3",
"@claude-flow/plugin-agent-federation": "1.0.7",
"@claude-flow/security": "3.0.6",
"@claude-flow/security": "3.0.7",
"@claude-flow/shared": "3.0.7",
"@iarna/toml": "^2.2.5",
"@noble/ed25519": "2.3.0",
@@ -0,0 +1,64 @@
/**
* zod 4 migration (GHSA-mrhx-c7xc-m3w5: zod < 4.6.6 can exhaust memory
* validating oversized constrained collections).
*
* Pins the behaviour that changed API under zod 4: the global security error
* map (z.setErrorMap -> z.config), IP schemas (string().ip() -> z.ipv4/ipv6),
* record schemas (z.record now takes a key schema) and the bounded array
* limits the advisory is about.
*/
import { describe, it, expect } from 'vitest';
import {
IPSchema,
IPv4Schema,
UUIDSchema,
HttpsUrlSchema,
TaskInputSchema,
SpawnAgentSchema,
InputValidator,
z,
} from '../src/input-validator.js';
const message = (r: { success: boolean; error?: { issues: Array<{ message: string }> } }) =>
r.success ? undefined : r.error!.issues[0].message;
describe('input-validator on zod 4', () => {
it('runs on zod >= 4.6.6', async () => {
const { createRequire } = await import('node:module');
const req = createRequire(import.meta.url);
const version = req('zod/package.json').version as string;
const [major, minor, patch] = version.split('.').map(Number);
expect(major).toBe(4);
expect(minor > 6 || (minor === 6 && patch >= 6)).toBe(true);
});
it('IP schemas accept v4/v6 and keep their messages', () => {
expect(IPSchema.safeParse('10.0.0.1').success).toBe(true);
expect(IPSchema.safeParse('::1').success).toBe(true);
expect(message(IPSchema.safeParse('not-an-ip'))).toBe('Invalid IP address');
expect(IPv4Schema.safeParse('192.168.1.1').success).toBe(true);
expect(message(IPv4Schema.safeParse('::1'))).toBe('Invalid IPv4 address');
});
it('schema-level messages still win over the global map', () => {
expect(message(UUIDSchema.safeParse('nope'))).toBe('Invalid UUID format');
expect(message(HttpsUrlSchema.safeParse('http://example.com'))).toBe('URL must use HTTPS');
});
it('the global error map applies where a check has no message', () => {
expect(message(z.string().max(2).safeParse('abc'))).toBe('Input exceeds maximum allowed size');
expect(message(z.string().email().safeParse('x'))).toBe('Invalid email format');
});
it('record schemas accept string-keyed metadata', () => {
const task = {
taskId: '123e4567-e89b-42d3-a456-426614174000',
content: 'do the thing',
agentType: 'coder',
metadata: { a: 1, b: 'two' },
};
expect(TaskInputSchema.safeParse(task).success).toBe(true);
expect(SpawnAgentSchema.safeParse({ type: 'coder', config: { k: 'v' } }).success).toBe(true);
expect(InputValidator.safeParse(TaskInputSchema, { ...task, metadata: 'x' }).success).toBe(false);
});
});
+2 -2
View File
@@ -1,6 +1,6 @@
{
"name": "@claude-flow/security",
"version": "3.0.6",
"version": "3.0.7",
"type": "module",
"description": "Security module - CVE fixes, input validation, path security",
"main": "dist/index.js",
@@ -25,7 +25,7 @@
"dependencies": {
"@noble/ed25519": "^2.1.0",
"bcryptjs": "^3.0.3",
"zod": "^3.22.0"
"zod": "^4.6.7"
},
"optionalDependencies": {
"@napi-rs/keyring": "1.3.0"
+22 -28
View File
@@ -15,32 +15,28 @@
import { z } from 'zod';
/**
* Custom error map for security-focused messages
* Custom error map for security-focused messages. Messages passed to a check
* (e.g. `.min(1, '...')`) take precedence; returning undefined falls back to
* zod's default message.
*/
const securityErrorMap: z.ZodErrorMap = (issue, ctx) => {
const securityErrorMap: z.core.$ZodErrorMap = (issue) => {
switch (issue.code) {
case z.ZodIssueCode.too_big:
return { message: `Input exceeds maximum allowed size` };
case z.ZodIssueCode.too_small:
return { message: `Input below minimum required size` };
case z.ZodIssueCode.invalid_string:
if (issue.validation === 'email') {
return { message: 'Invalid email format' };
}
if (issue.validation === 'url') {
return { message: 'Invalid URL format' };
}
if (issue.validation === 'uuid') {
return { message: 'Invalid UUID format' };
}
return { message: 'Invalid string format' };
case 'too_big':
return 'Input exceeds maximum allowed size';
case 'too_small':
return 'Input below minimum required size';
case 'invalid_format':
if (issue.format === 'email') return 'Invalid email format';
if (issue.format === 'url') return 'Invalid URL format';
if (issue.format === 'uuid') return 'Invalid UUID format';
return 'Invalid string format';
default:
return { message: ctx.defaultError };
return undefined;
}
};
// Apply custom error map globally for this module
z.setErrorMap(securityErrorMap);
// Apply custom error map globally (zod 4: z.config replaces z.setErrorMap)
z.config({ customError: securityErrorMap });
/**
* Common validation patterns as reusable regex
@@ -160,14 +156,12 @@ export const PortSchema = z.number()
/**
* IP address schema (v4)
*/
export const IPv4Schema = z.string()
.ip({ version: 'v4', message: 'Invalid IPv4 address' });
export const IPv4Schema = z.ipv4({ message: 'Invalid IPv4 address' });
/**
* IP address schema (v4 or v6)
*/
export const IPSchema = z.string()
.ip({ message: 'Invalid IP address' });
export const IPSchema = z.union([z.ipv4(), z.ipv6()], { message: 'Invalid IP address' });
// ============================================================================
// Authentication Schemas
@@ -264,7 +258,7 @@ export const AgentTypeSchema = z.enum([
export const SpawnAgentSchema = z.object({
type: AgentTypeSchema,
id: IdentifierSchema.optional(),
config: z.record(z.unknown()).optional(),
config: z.record(z.string(), z.unknown()).optional(),
timeout: z.number().positive().optional(),
});
@@ -276,7 +270,7 @@ export const TaskInputSchema = z.object({
content: SafeStringSchema.max(10000, 'Task content too long'),
agentType: AgentTypeSchema,
priority: z.enum(['low', 'medium', 'high', 'critical']).optional(),
metadata: z.record(z.unknown()).optional(),
metadata: z.record(z.string(), z.unknown()).optional(),
});
// ============================================================================
@@ -392,14 +386,14 @@ export class InputValidator {
/**
* Validates input against a schema
*/
static validate<T>(schema: z.ZodSchema<T>, input: unknown): T {
static validate<T>(schema: z.ZodType<T>, input: unknown): T {
return schema.parse(input);
}
/**
* Safely validates input, returning result
*/
static safeParse<T>(schema: z.ZodSchema<T>, input: unknown): z.SafeParseReturnType<unknown, T> {
static safeParse<T>(schema: z.ZodType<T>, input: unknown): z.ZodSafeParseResult<T> {
return schema.safeParse(input);
}
+16 -58
View File
@@ -133,7 +133,7 @@ importers:
specifier: 1.0.7
version: link:../plugin-agent-federation
'@claude-flow/security':
specifier: 3.0.6
specifier: 3.0.7
version: link:../security
'@claude-flow/shared':
specifier: 3.0.7
@@ -619,8 +619,8 @@ importers:
specifier: ^3.0.3
version: 3.0.3
zod:
specifier: ^3.22.0
version: 3.25.76
specifier: ^4.6.7
version: 4.6.7
optionalDependencies:
'@napi-rs/keyring':
specifier: 1.3.0
@@ -1286,7 +1286,7 @@ packages:
'@modelcontextprotocol/sdk':
optional: true
dependencies:
'@modelcontextprotocol/sdk': 1.27.1(zod@4.3.5)
'@modelcontextprotocol/sdk': 1.27.1(zod@4.6.7)
google-auth-library: 10.5.0
p-retry: 4.6.2
protobufjs: 8.6.5
@@ -2148,7 +2148,7 @@ packages:
dependencies:
zod: 4.6.7
/@modelcontextprotocol/sdk@1.27.1(zod@4.3.5):
/@modelcontextprotocol/sdk@1.27.1(zod@4.6.7):
resolution: {integrity: sha512-sr6GbP+4edBwFndLbM60gf07z0FQ79gaExpnsjMGePXqFcSSb7t6iscpjk9DhFhwd+mTEQrzNafGP8/iGGFYaA==}
engines: {node: '>=18'}
peerDependencies:
@@ -2173,8 +2173,8 @@ packages:
json-schema-typed: 8.0.2
pkce-challenge: 5.0.1
raw-body: 3.0.2
zod: 4.3.5
zod-to-json-schema: 3.25.1(zod@4.3.5)
zod: 4.6.7
zod-to-json-schema: 3.25.1(zod@4.6.7)
transitivePeerDependencies:
- supports-color
@@ -2209,38 +2209,6 @@ packages:
transitivePeerDependencies:
- supports-color
/@modelcontextprotocol/sdk@1.32.1(zod@4.3.5):
resolution: {integrity: sha512-2DdE+SJDtzLEEWzY1ZjY7Q+VcPhcV1KisD3zI4u0XZyktsjHum1mwbMI+JaulUBi2OZk+KJAi2uPXzxichPkdw==}
engines: {node: '>=18'}
requiresBuild: true
peerDependencies:
'@cfworker/json-schema': ^4.1.1
zod: ^3.25 || ^4.0
peerDependenciesMeta:
'@cfworker/json-schema':
optional: true
dependencies:
'@hono/node-server': 1.19.9(hono@4.12.11)
ajv: 8.20.0
ajv-formats: 3.0.1(ajv@8.20.0)
content-type: 1.0.5
cors: 2.8.6
cross-spawn: 7.0.6
eventsource: 3.0.7
eventsource-parser: 3.1.1
express: 5.2.1
express-rate-limit: 8.6.2(express@5.2.1)
hono: 4.12.11
jose: 6.1.3
json-schema-typed: 8.0.2
pkce-challenge: 5.0.1
raw-body: 3.0.2
zod: 4.3.5
zod-to-json-schema: 3.25.1(zod@4.3.5)
transitivePeerDependencies:
- supports-color
dev: false
/@modelcontextprotocol/sdk@1.32.1(zod@4.6.7):
resolution: {integrity: sha512-2DdE+SJDtzLEEWzY1ZjY7Q+VcPhcV1KisD3zI4u0XZyktsjHum1mwbMI+JaulUBi2OZk+KJAi2uPXzxichPkdw==}
engines: {node: '>=18'}
@@ -6205,7 +6173,7 @@ packages:
typescript:
optional: true
dependencies:
'@modelcontextprotocol/sdk': 1.27.1(zod@4.3.5)
'@modelcontextprotocol/sdk': 1.27.1(zod@4.6.7)
'@noble/ed25519': 2.3.0
'@noble/hashes': 1.8.0
base64-js: 1.5.1
@@ -6217,7 +6185,7 @@ packages:
tweetnacl: 1.0.3
typescript: 5.9.3
uuid: 9.0.1
zod: 4.3.5
zod: 4.6.7
optionalDependencies:
agentic-flow: 1.10.2(@modelcontextprotocol/sdk@1.27.1)
better-sqlite3: 12.9.0
@@ -7670,7 +7638,7 @@ packages:
jose:
optional: true
dependencies:
'@modelcontextprotocol/sdk': 1.32.1(zod@4.3.5)
'@modelcontextprotocol/sdk': 1.32.1(zod@4.6.7)
'@standard-schema/spec': 1.1.0
execa: 9.6.1
file-type: 21.3.0
@@ -7679,10 +7647,10 @@ packages:
strict-event-emitter-types: 2.0.0
undici: 7.16.0
uri-templates: 0.2.0
xsschema: 0.4.0-beta.5(zod-to-json-schema@3.25.1)(zod@4.3.5)
xsschema: 0.4.0-beta.5(zod-to-json-schema@3.25.1)(zod@4.6.7)
yargs: 18.0.0
zod: 4.3.5
zod-to-json-schema: 3.25.1(zod@4.3.5)
zod: 4.6.7
zod-to-json-schema: 3.25.1(zod@4.6.7)
transitivePeerDependencies:
- '@cfworker/json-schema'
- '@valibot/to-json-schema'
@@ -11819,7 +11787,7 @@ packages:
utf-8-validate:
optional: true
/xsschema@0.4.0-beta.5(zod-to-json-schema@3.25.1)(zod@4.3.5):
/xsschema@0.4.0-beta.5(zod-to-json-schema@3.25.1)(zod@4.6.7):
resolution: {integrity: sha512-73pYwf1hMy++7SnOkghJdgdPaGi+Y5I0SaO6rIlxb1ouV6tEyDbEcXP82kyr32KQVTlUbFj6qewi9eUVEiXm+g==}
peerDependencies:
'@valibot/to-json-schema': ^1.0.0
@@ -11842,8 +11810,8 @@ packages:
zod-to-json-schema:
optional: true
dependencies:
zod: 4.3.5
zod-to-json-schema: 3.25.1(zod@4.3.5)
zod: 4.6.7
zod-to-json-schema: 3.25.1(zod@4.6.7)
dev: false
/xsschema@0.4.4(zod-to-json-schema@3.25.1)(zod@4.6.7):
@@ -11963,13 +11931,6 @@ packages:
dependencies:
zod: 3.25.76
/zod-to-json-schema@3.25.1(zod@4.3.5):
resolution: {integrity: sha512-pM/SU9d3YAggzi6MtR4h7ruuQlqKtad8e9S0fmxcMi+ueAK5Korys/aWcV9LIIHTVbj01NdzxcnXSN+O74ZIVA==}
peerDependencies:
zod: ^3.25 || ^4
dependencies:
zod: 4.3.5
/zod-to-json-schema@3.25.1(zod@4.6.7):
resolution: {integrity: sha512-pM/SU9d3YAggzi6MtR4h7ruuQlqKtad8e9S0fmxcMi+ueAK5Korys/aWcV9LIIHTVbj01NdzxcnXSN+O74ZIVA==}
peerDependencies:
@@ -11980,8 +11941,5 @@ packages:
/zod@3.25.76:
resolution: {integrity: sha512-gzUt/qt81nXsFGKIFcC3YnfEAx5NkunCfnDlvuBSSFS02bcXu4Lmea0AFIUwbLWxWPx3d9p8S5QoaujKcNQxcQ==}
/zod@4.3.5:
resolution: {integrity: sha512-k7Nwx6vuWx1IJ9Bjuf4Zt1PEllcwe7cls3VNzm4CQ1/hgtFUK2bRNG3rvnpPUhFjmqJKAKtjV576KnUkHocg/g==}
/zod@4.6.7:
resolution: {integrity: sha512-g8W2D2kU6a8untc053fX1uVBKzM7yqAxW/3zwk83+6RyF2+SKOuV+c0wBDhUwzV1PaGapmZH+rmcUzPf+3CGwg==}