limit

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 25, 2026 License: Apache-2.0 Imports: 2 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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 AliasFunc

func AliasFunc(fn func(aliasCount, constructCount int) error) Option

AliasFunc sets a custom alias check function.

func AliasNone

func AliasNone() Option

AliasNone disables alias checking entirely.

func AliasValue

func AliasValue(n int) Option

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 DepthNone

func DepthNone() Option

DepthNone disables depth checking entirely.

func DepthValue

func DepthValue(n int) Option

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

func New(opts ...Option) *Plugin

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

func NewFromYAML(cfg map[string]any) (*Plugin, error)

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

func (p *Plugin) CheckAlias(aliasCount, constructCount int) error

CheckAlias implements [yaml.LimitPlugin].

func (*Plugin) CheckDepth

func (p *Plugin) CheckDepth(depth int, ctx *DepthContext) error

CheckDepth implements [yaml.LimitPlugin].

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL