Documentation
¶
Overview ¶
Package limit provides a configurable safety limit plugin for go-yaml.
The limit plugin controls the maximum nesting depth and alias expansion ratio during YAML parsing. By default, go-yaml enforces conservative limits to prevent DoS attacks. This plugin lets you relax or tighten those limits for your use case.
Usage ¶
import (
"github.com/pb33f/go-yaml"
"github.com/pb33f/go-yaml/plugin/limit"
)
// Default limits
loader := yaml.NewLoader(data, yaml.WithPlugin(limit.New()))
// Disable alias checking (e.g. for 11,000 programmatic aliases)
loader := yaml.NewLoader(data, yaml.WithPlugin(limit.New(limit.AliasNone())))
// Custom depth limit
loader := yaml.NewLoader(data, yaml.WithPlugin(limit.New(limit.DepthValue(50))))
Third-Party Plugins ¶
You can implement [yaml.LimitPlugin] directly instead of using this package:
type StrictLimit struct{}
func (s *StrictLimit) CheckDepth(depth int, ctx *yaml.DepthContext) error { ... }
func (s *StrictLimit) CheckAlias(aliasCount, constructCount int) error { ... }
yaml.NewLoader(data, yaml.WithPlugin(&StrictLimit{}))
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type DepthContext ¶
type DepthContext = libyaml.DepthContext
DepthContext is an alias for the type used in depth check callbacks. See [yaml.DepthContext] for field documentation.
type Option ¶
type Option func(*Plugin)
Option configures a Plugin.
func AliasValue ¶
AliasValue sets a simple alias expansion count threshold.
func DepthFunc ¶
func DepthFunc(fn func(depth int, ctx *DepthContext) error) Option
DepthFunc sets a custom depth check function.
func DepthValue ¶
DepthValue sets a maximum nesting depth (both flow and block).
type Plugin ¶
type Plugin struct {
// contains filtered or unexported fields
}
Plugin implements configurable safety limits for YAML parsing.
func New ¶
New creates a limit plugin with the given options. With no options, it uses the same defaults as the bare go-yaml library.
func NewFromYAML ¶
NewFromYAML creates a limit plugin from a YAML config map. Keys: "depth" (int or null), "alias" (int or null). Null values disable the corresponding check. Omitted keys use defaults.
func (*Plugin) CheckAlias ¶
CheckAlias implements [yaml.LimitPlugin].
func (*Plugin) CheckDepth ¶
func (p *Plugin) CheckDepth(depth int, ctx *DepthContext) error
CheckDepth implements [yaml.LimitPlugin].