Harden imported JSON Schema patterns - #6764
Conversation
🦋 Changeset detectedLatest commit: 4b61182 The changes in this PR will be included in the next version bump. This PR includes changesets to release 29 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Bundle Size AnalysisGenerated from PR build output; treat the content below as untrusted.
|
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
- Pattern safety checking: New
hasNestedUnboundedRepetitionfunction detects regex patterns with potentially unsafe nested unbounded repetition (e.g.(a+)+,(a*)*) in imported JSON Schema documents. The algorithm tracks mandatory-atom counts across groups and alternatives, flagging any inner group whose branches contain unbounded repetition without a separating mandatory atom. - Opt-out mechanism:
unsafeAllowComplexPatternsoption onFromJsonSchemaOptionsallows callers importing trusted documents to bypass the safety check. Defaults to safe (check enabled). - Documentation: Updated JSDoc for
fromJsonSchemaDocument,fromJsonSchemaMultiDocument, and the options interface. Added a note toSCHEMA.mdabout the native regex trust boundary. - Tests: Coverage for rejection of unsafe patterns in
pattern, opt-out validation, andpatternPropertiesrejection. The existing pattern round-trip test was retitled for clarity.
DeepSeek Pro (free via Pullfrog for OSS) (Kimi K2 not used — the program covers this model; add its provider key to run your pick) | 𝕏
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
hasNestedUnboundedRepetitionparser — detects classic catastrophic backtracking patterns ((a+)+,(x+x+)+y) and rejects them at import timeunsafeAllowComplexPatternsoption — explicit opt-out for trusted documents, documented as accepting the risk of unbounded validation- Checks in
collectStringChecksandcollectIndexSignatures— screens bothpatternandpatternPropertiesvalues - Documentation — JSDoc on
FromJsonSchemaOptions, doc comments onfromJsonSchemaDocumentandfromJsonSchemaMultiDocument, and a dedicated note inSCHEMA.mdall clearly communicate the native regex trust boundary and heuristic nature of the screen - Tests — covers rejection, overlapping mandatory atoms, disjoint delimiter acceptance, opt-out, and patternProperties rejection
DeepSeek Pro (free via Pullfrog for OSS) (Kimi K2 not used — the program covers this model; add its provider key to run your pick) | 𝕏
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes — three-commit hardening of JSON Schema pattern import safety:
- Pattern safety check — new
hasNestedUnboundedRepetitionfunction walks regex patterns to detect potentially unsafe nested unbounded repetition (e.g.(a+)+) before they reach the runtime's native regex engine. - Iteration boundary analysis — the checker distinguishes genuinely unsafe repetition (where repeated atoms overlap) from safe compound repetition with disjoint delimiters (e.g.
(\d+,)*). - Opt-out for trusted documents —
unsafeAllowComplexPatterns: truelets callers importing known-safe documents bypass the heuristic. - Documentation — public API JSDoc and
SCHEMA.mdboth call out the native regex trust boundary and the heuristic nature of the check.
Tests cover the main rejection cases (direct nested repetition, overlapping mandatory atoms, overlapping iteration boundaries, ambiguous class delimiters), safe disjoint-delimiter acceptance, the opt-out path, and patternProperties rejection. The heuristic's documented limitations (Unicode property escapes, lookahead/lookbehind character-set contribution, lazy-modifier under-counting) are all false-positive-only vectors — they can reject safe patterns but cannot miss unsafe ones.
DeepSeek Pro (free via Pullfrog for OSS) (Kimi K2 not used — the program covers this model; add its provider key to run your pick) | 𝕏
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
patternsoption onFromJsonSchemaOptions— adds a three-mode switch controlling how JSON Schemapattern,patternProperties, and patterns nested inpropertyNamesare imported."ignore"(default) — patterns are skipped and the source string is recorded in anignoredJsonSchemaPatternannotation, so missing validation remains observable."apply"mode — restores the previous behavior, compiling and enforcing patterns with the native regex engine."error"mode — rejects documents containing patterns with a path-anchored error.- Test helpers updated to default to
patterns: "apply", preserving existing test semantics while adding new tests for all three modes. - Docs updated in
SCHEMA.mdand JSDoc to document the native regex trust boundary.
DeepSeek Pro (free via Pullfrog for OSS) (Kimi K2 not used — the program covers this model; add its provider key to run your pick) | 𝕏

Summary
pattern,patternProperties, andpropertyNamespatterns by default, retaining skipped sources in annotationspatterns: "apply"andpatterns: "error"modes for trusted or fail-closed callersTesting
pnpm lint-fixpnpm --filter effect test --run test/schema/representation/fromJsonSchemaDocument.test.ts test/schema/representation/fromJsonSchemaMultiDocument.test.tspnpm checkCloses EFF-205