jsonstrict

package
v0.13.0 Latest Latest
Warning

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

Go to latest
Published: Aug 7, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package jsonstrict adds the strictness encoding/json does not provide.

It lives in internal/ because both the root package and api/ need it and neither imports the other. Nothing here is part of the public API.

Index

Constants

This section is empty.

Variables

View Source
var ErrDuplicateKey = errors.New("request body contains a duplicate JSON key")

ErrDuplicateKey is returned when a request body names the same object member twice.

Functions

func RejectDuplicateKeys

func RejectDuplicateKeys(body []byte) error

RejectDuplicateKeys reports an error if any object in the document names the same member twice.

encoding/json silently takes the last occurrence: {"role":"user","role":"admin"} unmarshals to "admin" with no error. That is a smuggling primitive whenever anything else in the request path -- a proxy, a WAF, a gateway, an audit log -- parses the same body and resolves the conflict differently. Two components disagreeing about what a request said is the whole bug class.

encoding/json/v2 rejects duplicates, but only through its own API. Go 1.27 makes v2 the implementation behind encoding/json while deliberately keeping v1's semantics, so the permissive behaviour is not going away on its own and waiting for it would have been waiting for nothing. RejectDuplicateKeys is the exported entry point.

Types

This section is empty.

Jump to

Keyboard shortcuts

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