| 1 | // Copyright 2026 The go-yaml Project Contributors |
| 2 | // SPDX-License-Identifier: Apache-2.0 |
| 3 | |
| 4 | package yaml |
| 5 | |
| 6 | // LimitPlugin configures safety limits for YAML parsing. |
| 7 | // |
| 8 | // When registered, CheckDepth is called on each nesting depth increase, |
| 9 | // and CheckAlias is called on each alias expansion to detect excessive |
| 10 | // aliasing. |
| 11 | // |
| 12 | // Example usage: |
| 13 | // |
| 14 | // import "go.yaml.in/yaml/v4/plugin/limit" |
| 15 | // loader := yaml.NewLoader(data, yaml.WithPlugin(limit.New(limit.AliasNone()))) |
| 16 | type LimitPlugin interface { |
| 17 | // CheckDepth is called when the parser increases nesting depth. |
| 18 | // depth is the current nesting level; ctx.Kind is "flow" or "block". |
| 19 | // Return an error to abort parsing. |
| 20 | CheckDepth(depth int, ctx *DepthContext) error |
| 21 | |
| 22 | // CheckAlias is called during alias expansion. |
| 23 | // Return an error to abort construction. |
| 24 | CheckAlias(aliasCount, constructCount int) error |
| 25 | } |