Help us shape the future of Go! Take the 2026 Go Developer Survey

decoder

package
v0.4.5 Latest Latest
Warning

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

Go to latest
Published: Oct 21, 2026 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package decoder provides safe, bounded decoding helpers for the detection pipeline.

Package decoder provides decoder functionality for CheeseWAF.

Index

Constants

View Source
const (
	// DefaultDecodeDepth handles routinely observed nested encodings without
	// giving an attacker an unbounded decode loop.
	DefaultDecodeDepth = 10
	// MaxDecodeDepth is the hard ceiling accepted by DecodeWithDepth and the
	// depth used by DeepDecode. Raising the ceiling covers the nested-encoding
	// lengths observed in 2022-2026 WAF evasion without an unbounded loop.
	MaxDecodeDepth = 12
)

Variables

This section is empty.

Functions

func FlattenJSON

func FlattenJSON(raw []byte) (string, error)

FlattenJSON renders raw's decoded JSON as a space-joined stream of keys and scalar values, for detectors that match against structure rather than syntax.

Documents nested deeper than maxJSONDepth are rejected with errJSONTooDeep and returned verbatim rather than partially flattened: a truncated walk drops exactly the deeply nested fields a payload would hide itself in, so whatever survived above the cutoff would read to a detector as a clean request. The untouched bytes come back alongside the error so a caller that mishandles it still hands the whole payload on instead of a truncated prefix. Callers must treat the error as "flattening unavailable", never as "no fields found".

Malformed input is returned unchanged with a nil error, matching the historical behaviour callers rely on.

func TryBase64

func TryBase64(raw string) (string, bool)

func URL

func URL(raw string) (string, error)

Types

type Decoded

type Decoded struct {
	Raw    string
	Layers []string
	Text   string
}

func Decode

func Decode(raw string) Decoded

func DecodeAll

func DecodeAll(raw string) []Decoded

DecodeAll returns multiple decode variants for thorough scanning.

func DecodeWithDepth

func DecodeWithDepth(raw string, maxDepth int) Decoded

DecodeWithDepth applies at most maxDepth transforming decode layers. Values outside the supported range are normalized to the safe default/ceiling.

func DecodeWithDepthPreserveControls

func DecodeWithDepthPreserveControls(raw string, maxDepth int) Decoded

DecodeWithDepthPreserveControls applies the same bounded transformations as DecodeWithDepth but keeps control bytes introduced by a decoding layer. The semantic detectors use this view so a sanitizer cannot join two tokens across an encoded NUL (for example `new-%00object` -> `new-object`). Callers that need the historical sanitized text should continue using DecodeWithDepth.

func DeepDecode

func DeepDecode(raw string) Decoded

DeepDecode performs aggressive multi-layer decoding to reveal obfuscated payloads.

Jump to

Keyboard shortcuts

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