capturedisclosure

package
v0.23.2 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2026 License: MIT Imports: 18 Imported by: 0

Documentation

Overview

Package capturedisclosure is the single disclosure owner for both HTTP capture directions: pure functions from raw captured facts to stored values, with no I/O. Input it cannot represent safely is omitted with a reason, never stored raw.

Index

Constants

View Source
const Masked = "[masked]"

Masked replaces a credential value in every mode.

Variables

This section is empty.

Functions

func Bytes

func Bytes(data []byte) []byte

Bytes keeps an absent body as zero bytes: body columns are NOT NULL and the byte codec rejects a nil slice.

func CredentialName

func CredentialName(name string, extra Names) bool

CredentialName decides header and body field names in both capture directions. It errs toward masking: a false positive hides one value, a false negative stores a vendor key for every developer to read.

Authorization, Set-Cookie, X-Api-Key, client_secret -> record.SensitiveName
auth, X-Auth-Token, x_auth, authToken               -> the word auth
key, X-RapidAPI-Key, Ocp-Apim-Subscription-Key      -> a separated final word key
subscriptionKey, accesskey                          -> a listed key compound
Idempotency-Key, monkey, author, oauth_state        -> visible

func CredentialQueryName

func CredentialQueryName(name string, extra Names) bool

CredentialQueryName adds the framework's own bearer parameters (a ticket or a signed-URL signature) and the words sig and signature, so presigned URLs such as X-Amz-Signature cannot be replayed from a viewer. Signature headers stay visible: an HMAC over one body grants nothing.

func Fields

func Fields(raw string, truncated bool, p Policy, mask func(string) bool) (fields []httpcapture.Field, cut bool, valid bool)

Fields parses URL-encoded pairs in first-appearance order, grouping repeated names and masking values whose names mask matches. A truncated input drops its possibly partial last pair. It reports false for any malformed escape instead of keeping raw text, and cut when the field bound stopped it.

func Headers

func Headers(fields []httpcapture.Field, mask, query func(string) bool) []httpcapture.Field

Headers masks the values of names mask matches, masks the query and fragment values of URL-valued headers whose names query matches, and makes text storable. Webhook response headers pass rules that match nothing: they are what the application sent, kept whole for debugging.

func Inspectable

func Inspectable(contentType, contentEncoding string) (Media, Reason)

Inspectable decides, from Content-Type and Content-Encoding alone, whether redacted mode can store a body. Outbound capture calls it before buffering and redaction calls it again, so the two never disagree.

func NonNil

func NonNil[T any](items []T) []T

NonNil stores an absent list as an empty JSON array.

func Omitted

func Omitted(size int) string

Omitted describes a value too long to store.

func Text

func Text(text string) string

Text makes transport text storable: PostgreSQL text and jsonb reject invalid UTF-8 and NUL, and one bad value would fail its whole batch.

func TextLimit

func TextLimit(text string, limit int) string

TextLimit also cuts replacement growth back to a column's byte limit on a rune boundary.

Types

type Format

type Format uint8

Format is what redacted mode can parse.

const (
	Opaque Format = iota
	JSON
	Form
	Multipart
)

type Media

type Media struct {
	Format Format
	// contains filtered or unexported fields
}

Media is a body's parsed redaction format.

type Names

type Names map[string]struct{}

Names are extra credential names from deployment settings, matched exactly and case-insensitively.

func NewNames

func NewNames(names []string) Names

NewNames builds the extra-name set. Settings validation bounds the input.

type Policy

type Policy struct {
	ValueBytes int
	BodyBytes  int
	Names      Names
}

Policy is the immutable redaction input: value and output bounds and the extra credential names deployment settings add.

type Reason

type Reason uint8

Reason is the internal omission vocabulary; each public capture package maps it onto its own generated enum.

const (
	NoReason Reason = iota
	ContentEncoded
	UnsupportedMediaType
	Malformed
	RedactionLimit
)

func Redact

func Redact(data []byte, media Media, p Policy) ([]byte, Reason)

Redact rewrites one complete body of an inspectable media type. Callers decide completeness from an observed end of stream first; a successful parse never proves completeness.

Jump to

Keyboard shortcuts

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