Skip to content

fix(bundle): allow bundle parsing under Zod v4 pick-with-refinements …#77

Merged
seansica merged 1 commit intonextfrom
bug/error-loading-latest-enterprise-attack-data
May 8, 2026
Merged

fix(bundle): allow bundle parsing under Zod v4 pick-with-refinements …#77
seansica merged 1 commit intonextfrom
bug/error-loading-latest-enterprise-attack-data

Conversation

@seansica
Copy link
Copy Markdown
Contributor

@seansica seansica commented May 8, 2026

Fixes #67.

Summary

parseStixBundle validates a bundle's top-level id and type by calling stixBundleSchema.pick({ id: true, type: true }). Zod v4 disallows .pick() on any schema that has refinements attached, and stixBundleSchema carries three (validateXMitreCollection, validateXMitreContentsReferences, validateNoDuplicates). As a result, every call into registerDataSource / loadDataModel threw:

Error: .pick() cannot be used on object schemas containing refinements

Fix

Split stixBundleSchema into two exports:

  • stixBundleBaseSchema — the plain z.object({...}).strict() shape, no refinements. Safe to compose with .pick(), .extend(), etc.
  • stixBundleSchemastixBundleBaseSchema.check(...) with the existing collection/contents/duplicate refinements. Used for full bundle validation, unchanged.

parseStixBundle now picks id and type from stixBundleBaseSchema, which sidesteps the Zod v4 restriction without weakening any validation: the top-level check was always meant to be a shallow gate (note the existing .loose() so objects passes through to per-object validation), and full bundle validation via stixBundleSchema is still available to callers that want it.

Test plan

  • npx vitest run test/objects/stix-bundle.test.ts — 23/23 pass
  • npx vitest run test/documentation/README.test.ts — 13/13 pass (exercises the registerDataSourceloadDataModel path from the bug report)
  • npx tsc --noEmit clean
  • Reproduce the original failing snippet from [BUG] Error loading latest enterprise-attack data #67 against a local build and confirm it loads techniques/tactics without throwing

…restriction

Zod v4 throws ".pick() cannot be used on object schemas containing
refinements", which broke parseStixBundles top-level id/type check
against stixBundleSchema. Split the bundle schema into a refinement-free
base (stixBundleBaseSchema) and the refined stixBundleSchema, and pick
from the base.
@seansica seansica merged commit 92d5d10 into next May 8, 2026
2 checks passed
@seansica seansica deleted the bug/error-loading-latest-enterprise-attack-data branch May 8, 2026 19:44
@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 8, 2026

🎉 This PR is included in version 4.11.3 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant