Skip to content

fix(security): zod 4 in api-types, sdk and langchain; GHSA-mrhx exception withdrawn (#214) - #249

Merged
fabianocruz merged 3 commits into
mainfrom
feat/214-zod4
Nov 15, 2026
Merged

fabianocruz merged 3 commits into
mainfrom
feat/214-zod4

Conversation

@fabianocruz

@fabianocruz fabianocruz commented Nov 15, 2026 •

Copy link
Copy Markdown
Member

Closes #214.

Migrates the repo to zod 4 for GHSA-mrhx-c7xc-m3w5: zod up to 4.6.5, and every 3.x, can exhaust memory while validating an oversized array. The audit exception that expires on 16/11 (UTC) is removed in this PR, so the Security audit passes because of the fix, not because of an accepted risk.

What changes

  • @codespar/api-types 0.6.0: depends on zod ^4.6.6. The schemas keep their shapes and inferred types. It is a minor because the schemas are now zod 4: whoever composes them with zod 3, or passes them to zod 3 tooling, opts in when moving to 0.6.0 (^0.5.0 does not pick it up).
  • @codespar/sdk 0.16.30: depends on zod ^4.6.6. SessionConfigSchema keeps the same shape and the same SessionConfig type. The three single-argument z.record(value) calls became z.record(z.string(), value), the form zod 4 requires; what validates is the same.
  • @codespar/langchain 0.5.2: it already imports zod/v3, which zod 4 ships, and its peer stays >=3.25.0. Only the dev dependency goes to ^4.6.6. Its test now imports from zod/v3 too, the same entry as schema.ts, so instanceof z.ZodEffects compares the same class. The bound on model input from fix(langchain): bound a tool call's input before Zod validates it #245 stays.
  • Lockfile: a single zod, 4.6.7. The packages that depend on zod (ai, @ai-sdk/*, @modelcontextprotocol/sdk, zod-to-json-schema) already accept ^4.
  • scripts/audit-exceptions.json: exceptions: [].
  • SDK snapshot refreshed to the served document (868a0272e249): usdc_accounts[].seed and the Shop's awaiting.reason with identity_required / consent_required. That was why spec-freshness failed, independent of zod.
  • Publish drift guard: langchain goes to 0.5.2 (its packed content moved), and the api-types waiver (pinned to 0.5.0) is removed. api-types 0.6.0 also publishes two_header (feat(sdk): session.ledger() + session.issue() wrappers + two_header api-type #72, core#132).

Consumers (enterprise and web, on main)

  • enterprise: api-types 0.4.0 and sdk 0.16.16 (zod 3.25.76 at the root). It imports ServerRowSchema, AuthSchemaFieldSchema and ProjectIdSchema from api-types into openapi.ts, so moving to 0.6.0 requires its OpenAPI generator on zod 4. Pinned to 0.4.0, it changes nothing until it opts in. It does not use SessionConfigSchema.
  • web: api-types 0.5.0 and sdk 0.16.27. The caret does not pick up api-types 0.6.0. SessionConfigSchema appears only in the documentation (content/docs/api/sdk/client.mdx), not in code.
  • Bumping each consumer to the new versions is its own PR, after publishing.

Checks

  • node scripts/audit-gate.mjs: exit 0 with no exception (only moderates reported). audit-gate.test.mjs: 9/9.
  • Build and tests run in CI. Locally, heavy was holding back because of memory pressure.

Publishing (tag) is not part of this PR.

🤖 Generated with Claude Code

fabianocruz and others added 3 commits November 15, 2026 20:13
…xception is withdrawn (core#214)

zod up to 4.6.5, and every 3.x, can exhaust memory while validating an
oversized array (GHSA-mrhx-c7xc-m3w5). api-types and the SDK depend on
zod ^4.6.6; langchain keeps its classic zod/v3 import, which zod 4 ships,
and its own tests read the same entry. The lockfile resolves one zod, 4.6.7.
The audit exception for the advisory is removed, so the gate passes on the
fix and not on an accepted risk.

api-types 0.6.0 (a minor: its schemas are zod 4 now) and sdk 0.16.30.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…seed, Shop awaiting reasons)

Regenerated by npm run sdk:spec:refresh; sdk:spec:check exits 0 against
the served document.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
….6.0

The publish drift guard: langchain's packed content moved (dev dependency),
so its version moves; the api-types 0.5.0 waiver no longer matches a
package at 0.6.0, which also publishes two_header (#72, core#132).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@fabianocruz
fabianocruz merged commit 3373434 into main Nov 15, 2026
12 checks passed
fabianocruz added a commit that referenced this pull request Nov 19, 2026
…alls in the SDKs, the CLI and the MCP package (#244)

Shop data calls in the SDKs, the CLI and the MCP package.

A data call is a per-call data service found by a research of
`task_kind: "data_service"`. An API key drafts one from an offer and
reads it. It never runs one: running it is the person's authorization.
While the call waits for the person, the API answers `next_action`, a
link to the call's card on the dashboard behind the person's own
sign-in.

## Status (2026-11-17)

- Merged with main at 3373434 (zod 4, #249). No code here uses zod, so
the zod 4 move needed no source change.
- **Blocked by a technical dependency, not by G1:** codespar-enterprise
#2520 has to be deployed first. The client calls routes that only #2520
serves:
- `POST /v1/shop/agent/data-calls` (`agent_id`, `offer_id`,
`idempotency_key`; answers `data_call`, `next_action` and
`idempotent_replay`);
  - `GET /v1/shop/agent/data-calls/{id}` (`data_call`, `next_action`);
- `POST /v1/shop/agent/data-calls/{id}/execute` (always 403
`person_required`, with `error.details.next_action`);
- on `POST /v1/shop/agent/research`, `task_kind: "data_service"`, the
`data` source and `criteria.data_service { params, sku? }`.
- `spec-freshness` is red until then, and it says exactly that: the
served document lacks those three operations and the research change.
Nothing else differs. It is not a required check; `ci` is green.
- The OpenAPI snapshot is the document served on 2026-11-17 (390
operations, G1 included) plus those four entries, taken from #2520 at
3bcd53dcb (`buildOpenApiSpec`). `src/generated/` is regenerated from it
(393 operations).
- Versions are past what npm and main hold: `@codespar/sdk` 0.16.31,
`@codespar/cli` 0.22.8 (SDK floor ^0.16.31), `@codespar/mcp` 0.5.21,
`@codespar/types` 0.11.8. The Python changelog stays "Unreleased"
(`codespar` 0.16.2 on PyPI). **Nothing is published here.** Publishing
happens after merge and after #2520 is deployed, with `spec:check` green
against the served document.

## What changes
- **TypeScript:**
- `cs.dataCalls` and `session.dataCalls`: `create`, `get` (`{ data_call,
next_action }`) and `execute`. A key's `execute` throws
`DataCallNeedsPersonError` with `nextAction`.
  - `dataCallOutcome(view)` turns the four states into one word.
- `session.research.create` takes `taskKind` and `criteria.dataService`.
  - The types live in `@codespar/types`.
- **Python:** `cs.research` and `cs.data_calls` (async and sync), with
`data_call_outcome` and `next_action_of`.
- **CLI:**
- Derived commands `shop create-data-calls`, `shop get-data-calls` and
`shop data-calls-execute`.
- These commands exit with the outcome: 0 confirmed, 10 pending, 20
refused, 30 failure, 40 uncertain.
  - A key's execute prints the person's link and exits 10.
  - Every other command keeps exit 1.
- **MCP package:** `codespar_shop_data_call_draft`,
`codespar_shop_data_call_request_authorization` (answers the person's
link) and `codespar_shop_data_call_status`. No tool runs a call.
- **OpenAPI snapshot:** the three data-call operations and the research
body.

## Tests
- Remote CI on 0a31927: `ci` green (build, typecheck, lint, the unit
suites, audit gate), plus gitleaks, kit-templates and the example
validations.
- Earlier head: core 261, cli 359, mcp 52, types 178, python 173; ruff,
mypy, and turbo typecheck and lint.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CI security audit fails on every head: zod 3 HIGH (GHSA-mrhx-c7xc-m3w5) has no 3.x fix; body-parser HIGH

1 participant