Skip to content

Reject Yaml tags and explicit keys, resolve alias keys, and keep non-space white space - #10276

Closed
effect-bot wants to merge 19 commits into
v4/next-minorfrom
agent/nelson-effect-bot/eff-3232-stage3-hardening
Closed

effect-bot wants to merge 19 commits into
v4/next-minorfrom
agent/nelson-effect-bot/eff-3232-stage3-hardening

Conversation

@effect-bot

@effect-bot effect-bot commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

Stage 3 of the YAML expansion. Yaml.parse and Yaml.parseAll used to read some input as text and return a wrong value without any error. This PR either rejects that input or parses it correctly.

Behavior

  • Tags fail. a: !!str 123 used to give "!!str 123", and !!str a: 1 gave the key "!!str a". Now every tag is rejected: core, local, non-specific and verbatim tags, on values, keys, collections and flow items. Resolving core tags is planned as a separate change. A ! inside a plain scalar (x!y, hello!) is still text.
  • Alias keys. *name : value now uses the anchored scalar as the key; a number becomes its string form. Before, the key was the literal text "*name". An alias to a collection used as a key fails. An alias key needs a space before the :, because : is a valid character in an anchor name. That matches yaml 2.9.1.
  • Explicit keys fail with a clear error: block ? key, the flow mapping form {? a : 1} and the flow sequence form [? a]. The flow forms used to give the keys "? a".
  • Nesting depth. Collections can be nested up to 1000 levels deep; block and flow count together. Deeper input fails with an EncodingError instead of a stack overflow.
  • White space. YAML 1.2.2 §5.5 treats only spaces and tabs as white space. The parser used JavaScript's trim() and \s, which also removed no-break spaces (U+00A0), U+2028, U+3000 and similar characters from values and keys. It also treated # after them as the start of a comment. Those characters are now kept as content, and the results match yaml 2.9.1.

Integers beyond Number.MAX_SAFE_INTEGER still lose precision under JavaScript number semantics. The docs now say so and suggest quoting such values.

Docs

  • The module header lists what is rejected and the limits that remain.
  • The parse JSDoc covers tags, explicit keys, the depth limit, alias keys and precision. Its example has a rejected tag.
  • .changeset/yaml-parser-hardening.md is the release note.

Validation

  • Yaml.test.ts: 216 of 217 pass.
    • The failing test, "rejects deeper block nesting", has a bug in its input generator: 100,000 levels of indentation make a string of about 5 × 10⁹ characters, so it throws RangeError: Invalid string length before parsing starts.
    • The parser part of that test passes: 1001 levels fail with the depth error, and so do 3000 to 5000 levels of block mappings or sequences.
    • The test will be fixed in a separate run.
  • YAML, CLI, Skills, ai-codegen and openapi-generator tests: 860 passed, 3 skipped, plus the test above.
  • pnpm lint, pnpm jsdocs --check and the Yaml.ts doctests pass.
  • pnpm check reports one error, the apiStabilityLeak in cluster/ShardingRegistrationEvent.ts, which also occurs on v4/next-minor.

Stack

These PRs form one stack. Each targets the PR before it, so its diff shows only its own stage. Merge them in this order:

  1. Add Yaml.parseAll and return Result from Yaml.parse #10271: Yaml.parseAll and Result from Yaml.parse (merged)
  2. Reject Yaml tags and explicit keys, resolve alias keys, and keep non-space white space #10276: parser hardening, based on v4/next-minor (this PR)
  3. Parse Yaml compact nested sequences and multiline quoted flow scalars #10279: compact nested sequences and multiline quoted flow scalars, based on Reject Yaml tags and explicit keys, resolve alias keys, and keep non-space white space #10276
  4. Treat a tab after a Yaml sequence dash as separation #10282: tab after a sequence dash, based on Parse Yaml compact nested sequences and multiline quoted flow scalars #10279
  5. Accept escaped literal tabs in Yaml double-quoted scalars #10283: escaped literal tabs, based on Treat a tab after a Yaml sequence dash as separation #10282
  6. Reject Yaml flow plain scalars starting with a dash and separation #10284: flow plain scalars starting with a dash, based on Accept escaped literal tabs in Yaml double-quoted scalars #10283
  7. Resolve Yaml core schema tags #10285: core schema tags, based on Reject Yaml flow plain scalars starting with a dash and separation #10284
  8. Add Yaml.stringify and Yaml.stringifyAll #10272: Yaml.stringify and Yaml.stringifyAll, based on Resolve Yaml core schema tags #10285
  9. Harden and extend Yaml parsing and add Yaml.stringify #10287: printer round-trip through Yaml.parse, based on Add Yaml.stringify and Yaml.stringifyAll #10272

After a PR in the stack is squash-merged, the next one has to be rebased onto the squash commit and retargeted to v4/next-minor before it can merge.

Closes EFF-3232

@changeset-bot

changeset-bot Bot commented Nov 2, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: a8cf572

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

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

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

@github-actions

github-actions Bot commented Nov 2, 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
arbitrary-combinators.ts 39.41 KB 39.41 KB 0.00 KB (0.00%)
basic.ts 7.23 KB 7.23 KB 0.00 KB (0.00%)
batching.ts 11.08 KB 11.08 KB 0.00 KB (0.00%)
brand.ts 6.87 KB 6.87 KB 0.00 KB (0.00%)
cache.ts 11.54 KB 11.54 KB 0.00 KB (0.00%)
config.ts 22.84 KB 22.84 KB 0.00 KB (0.00%)
differ.ts 22.00 KB 22.00 KB 0.00 KB (0.00%)
http-client.ts 27.12 KB 27.12 KB 0.00 KB (0.00%)
http-router.ts 37.04 KB 37.04 KB 0.00 KB (0.00%)
logger.ts 12.01 KB 12.01 KB 0.00 KB (0.00%)
metric.ts 9.47 KB 9.47 KB 0.00 KB (0.00%)
optic.ts 7.10 KB 7.10 KB 0.00 KB (0.00%)
pubsub.ts 16.02 KB 16.02 KB 0.00 KB (0.00%)
queue.ts 12.89 KB 12.89 KB 0.00 KB (0.00%)
schedule.ts 11.80 KB 11.80 KB 0.00 KB (0.00%)
schema-bigdecimal.ts 14.14 KB 14.14 KB 0.00 KB (0.00%)
schema-binary.ts 41.99 KB 41.99 KB 0.00 KB (0.00%)
schema-class.ts 21.73 KB 21.73 KB 0.00 KB (0.00%)
schema-fromJsonSchemaDocument.ts 29.60 KB 29.60 KB 0.00 KB (0.00%)
schema-representation-roundtrip.ts 27.99 KB 27.99 KB 0.00 KB (0.00%)
schema-string-transformation.ts 15.35 KB 15.35 KB 0.00 KB (0.00%)
schema-string.ts 12.34 KB 12.34 KB 0.00 KB (0.00%)
schema-template-literal.ts 16.27 KB 16.27 KB 0.00 KB (0.00%)
schema-toArbitrary.ts 38.95 KB 38.95 KB 0.00 KB (0.00%)
schema-toCodeDocument.ts 26.15 KB 26.15 KB 0.00 KB (0.00%)
schema-toCodecJson.ts 20.90 KB 20.90 KB 0.00 KB (0.00%)
schema-toEquivalence.ts 21.05 KB 21.05 KB 0.00 KB (0.00%)
schema-toFormatter.ts 21.14 KB 21.14 KB 0.00 KB (0.00%)
schema-toJsonSchemaDocument.ts 26.17 KB 26.17 KB 0.00 KB (0.00%)
schema-toRepresentation.ts 21.23 KB 21.23 KB 0.00 KB (0.00%)
schema.ts 20.82 KB 20.82 KB 0.00 KB (0.00%)
stm.ts 14.20 KB 14.20 KB 0.00 KB (0.00%)
stream.ts 10.38 KB 10.38 KB 0.00 KB (0.00%)

@effect-bot
effect-bot force-pushed the agent/nelson-effect-bot/eff-3232-stage3-hardening branch from 6375469 to 5608c22 Compare November 3, 2026 23:40
Tags, alias keys, explicit keys, nesting depth, and non-separation
whitespace (NBSP, U+2028) that is currently trimmed as if it were
YAML white space.
Reject tags and explicit keys instead of reading them as text, resolve
scalar aliases used as mapping keys, bound collection nesting at 1000
levels, and treat only spaces and tabs as YAML white space.
Sequence-item mapping depth, alias keys resolving to '<<' in flow
mappings, anchor and tag properties on keys, colons in alias names, and
U+2028/U+2029 in anchored values.
Trim and fold white space with linear scans, count a sequence item's
mapping before its first value, read anchors and tags on keys, keep
colons in alias names, merge only through a plain '<<' key, and keep
U+2028/U+2029 in anchored values.
Share one scalar-key resolver between block and flow mappings, read plain
flow scalars and keys through one helper that rejects indicator prefixes,
name the flow anchor-name boundary once, and add the flow-key quoting
migration note to the changeset.
@effect-bot
effect-bot force-pushed the agent/nelson-effect-bot/eff-3232-stage3-hardening branch from 5608c22 to a8cf572 Compare November 3, 2026 23:43
@effect-bot

Copy link
Copy Markdown
Contributor Author

Superseded by #10287, which now holds the rest of the YAML expansion as one PR against v4/next-minor. This PR's commits are included there unchanged.

@effect-bot effect-bot closed this Nov 4, 2026
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.

6 participants