Skip to content

Harden imported JSON Schema patterns - #6764

Draft
tim-smart wants to merge 4 commits into
mainfrom
agent/codex-engineer/6eb99df8
Draft

Harden imported JSON Schema patterns#6764
tim-smart wants to merge 4 commits into
mainfrom
agent/codex-engineer/6eb99df8

Conversation

@tim-smart

@tim-smart tim-smart commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

Summary

  • ignore imported pattern, patternProperties, and propertyNames patterns by default, retaining skipped sources in annotations
  • add explicit patterns: "apply" and patterns: "error" modes for trusted or fail-closed callers
  • document the native regular expression trust boundary and update the changeset

Testing

  • pnpm lint-fix
  • pnpm --filter effect test --run test/schema/representation/fromJsonSchemaDocument.test.ts test/schema/representation/fromJsonSchemaMultiDocument.test.ts
  • pnpm check

Closes EFF-205

@changeset-bot

changeset-bot Bot commented Jul 29, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 4b61182

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 29 packages
Name Type
effect Patch
@effect/opentelemetry Patch
@effect/platform-browser Patch
@effect/platform-bun Patch
@effect/platform-deno Patch
@effect/platform-node-shared Patch
@effect/platform-node Patch
@effect/vitest Patch
@effect/ai-anthropic Patch
@effect/ai-openai-compat Patch
@effect/ai-openai Patch
@effect/ai-openrouter Patch
@effect/atom-react Patch
@effect/atom-solid Patch
@effect/atom-vue Patch
@effect/sql-clickhouse Patch
@effect/sql-d1 Patch
@effect/sql-libsql Patch
@effect/sql-mssql Patch
@effect/sql-mysql2 Patch
@effect/sql-pg Patch
@effect/sql-pglite Patch
@effect/sql-sqlite-bun Patch
@effect/sql-sqlite-do Patch
@effect/sql-sqlite-node Patch
@effect/sql-sqlite-react-native Patch
@effect/sql-sqlite-wasm Patch
@effect/docgen Patch
@effect/openapi-generator Patch

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

@effect-slopcop effect-slopcop Bot added 4.0 bug Something isn't working labels Jul 29, 2026
@github-actions

github-actions Bot commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

Bundle Size Analysis

Generated from PR build output; treat the content below as untrusted.

File Name Current Size Previous Size Difference
basic.ts 6.63 KB 6.63 KB 0.00 KB (0.00%)
batching.ts 9.42 KB 9.42 KB 0.00 KB (0.00%)
brand.ts 6.31 KB 6.31 KB 0.00 KB (0.00%)
cache.ts 10.12 KB 10.12 KB 0.00 KB (0.00%)
config.ts 19.90 KB 19.90 KB 0.00 KB (0.00%)
differ.ts 20.03 KB 20.03 KB 0.00 KB (0.00%)
http-client.ts 20.94 KB 20.94 KB 0.00 KB (0.00%)
logger.ts 10.28 KB 10.28 KB 0.00 KB (0.00%)
metric.ts 8.55 KB 8.55 KB 0.00 KB (0.00%)
optic.ts 7.33 KB 7.33 KB 0.00 KB (0.00%)
pubsub.ts 14.26 KB 14.26 KB 0.00 KB (0.00%)
queue.ts 11.09 KB 11.09 KB 0.00 KB (0.00%)
schedule.ts 10.27 KB 10.27 KB 0.00 KB (0.00%)
schema-class.ts 18.86 KB 18.86 KB 0.00 KB (0.00%)
schema-fromJsonSchemaDocument.ts 28.85 KB 28.78 KB +0.07 KB (+0.23%)
schema-representation-roundtrip.ts 25.09 KB 25.09 KB 0.00 KB (0.00%)
schema-string-transformation.ts 12.95 KB 12.95 KB 0.00 KB (0.00%)
schema-string.ts 10.65 KB 10.65 KB 0.00 KB (0.00%)
schema-template-literal.ts 14.85 KB 14.85 KB 0.00 KB (0.00%)
schema-toArbitraryLazy.ts 21.66 KB 21.66 KB 0.00 KB (0.00%)
schema-toCodeDocument.ts 24.10 KB 24.10 KB 0.00 KB (0.00%)
schema-toCodecJson.ts 19.00 KB 19.00 KB 0.00 KB (0.00%)
schema-toEquivalence.ts 18.73 KB 18.73 KB 0.00 KB (0.00%)
schema-toFormatter.ts 18.59 KB 18.59 KB 0.00 KB (0.00%)
schema-toJsonSchemaDocument.ts 22.23 KB 22.23 KB 0.00 KB (0.00%)
schema-toRepresentation.ts 19.27 KB 19.27 KB 0.00 KB (0.00%)
schema.ts 18.12 KB 18.12 KB 0.00 KB (0.00%)
stm.ts 12.05 KB 12.05 KB 0.00 KB (0.00%)
stream.ts 9.37 KB 9.37 KB 0.00 KB (0.00%)

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ No new issues found.

Reviewed changes

  • Pattern safety checking: New hasNestedUnboundedRepetition function 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: unsafeAllowComplexPatterns option on FromJsonSchemaOptions allows 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 to SCHEMA.md about the native regex trust boundary.
  • Tests: Coverage for rejection of unsafe patterns in pattern, opt-out validation, and patternProperties rejection. The existing pattern round-trip test was retitled for clarity.

Pullfrog  | View workflow run | Using DeepSeek Pro (free via Pullfrog for OSS) (Kimi K2 not used — the program covers this model; add its provider key to run your pick) | 𝕏

@tim-smart
tim-smart marked this pull request as draft July 29, 2026 23:56
@tim-smart
tim-smart marked this pull request as ready for review July 29, 2026 23:56
@tim-smart
tim-smart marked this pull request as draft July 29, 2026 23:57

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ No new issues found.

Reviewed changes

  • hasNestedUnboundedRepetition parser — detects classic catastrophic backtracking patterns ((a+)+, (x+x+)+y) and rejects them at import time
  • unsafeAllowComplexPatterns option — explicit opt-out for trusted documents, documented as accepting the risk of unbounded validation
  • Checks in collectStringChecks and collectIndexSignatures — screens both pattern and patternProperties values
  • Documentation — JSDoc on FromJsonSchemaOptions, doc comments on fromJsonSchemaDocument and fromJsonSchemaMultiDocument, and a dedicated note in SCHEMA.md all 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

Pullfrog  | View workflow run | Using DeepSeek Pro (free via Pullfrog for OSS) (Kimi K2 not used — the program covers this model; add its provider key to run your pick) | 𝕏

@tim-smart
tim-smart marked this pull request as ready for review July 30, 2026 00:15
@tim-smart
tim-smart marked this pull request as draft July 30, 2026 00:20

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ No new issues found.

Reviewed changes — three-commit hardening of JSON Schema pattern import safety:

  • Pattern safety check — new hasNestedUnboundedRepetition function 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 documentsunsafeAllowComplexPatterns: true lets callers importing known-safe documents bypass the heuristic.
  • Documentation — public API JSDoc and SCHEMA.md both 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.

Pullfrog  | View workflow run | Using DeepSeek Pro (free via Pullfrog for OSS) (Kimi K2 not used — the program covers this model; add its provider key to run your pick) | 𝕏

@tim-smart
tim-smart marked this pull request as ready for review July 30, 2026 00:50
@tim-smart
tim-smart marked this pull request as draft July 30, 2026 00:54

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ No new issues found.

Reviewed changes

  • patterns option on FromJsonSchemaOptions — adds a three-mode switch controlling how JSON Schema pattern, patternProperties, and patterns nested in propertyNames are imported.
  • "ignore" (default) — patterns are skipped and the source string is recorded in an ignoredJsonSchemaPattern annotation, 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.md and JSDoc to document the native regex trust boundary.

Pullfrog  | View workflow run | Using DeepSeek Pro (free via Pullfrog for OSS) (Kimi K2 not used — the program covers this model; add its provider key to run your pick) | 𝕏

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

Labels

4.0 bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant