urlsanitize

package
v1.260804.0 Latest Latest
Warning

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

Go to latest
Published: Aug 4, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const RedactedPlaceholder = "[REDACTED]"

RedactedPlaceholder replaces a URL that cannot be reduced to a safe form.

Variables

View Source
var DefaultSensitiveQueryKeys = map[string]struct{}{
	"x-amz-signature":      {},
	"x-amz-credential":     {},
	"x-amz-algorithm":      {},
	"x-amz-signedheaders":  {},
	"x-amz-security-token": {},
	"signature":            {},
	"key-pair-id":          {},
	"policy":               {},
	"sig":                  {},
	"token":                {},
	"access_token":         {},
	"id_token":             {},
	"refresh_token":        {},
}

DefaultSensitiveQueryKeys identifies params that should be redacted in logs.

View Source
var DefaultSignedQueryKeys = map[string]struct{}{
	"x-amz-signature":     {},
	"x-amz-credential":    {},
	"x-amz-algorithm":     {},
	"x-amz-signedheaders": {},
	"signature":           {},
	"key-pair-id":         {},
	"policy":              {},
	"sig":                 {},
}

DefaultSignedQueryKeys identifies query params that indicate signed URLs.

Functions

func ClassifyTransportFailure added in v1.260731.0

func ClassifyTransportFailure(err error) string

ClassifyTransportFailure returns a short, credential-free description of a transport failure so sanitized errors keep their diagnostic value.

func CopyKeySet

func CopyKeySet(source map[string]struct{}) map[string]struct{}

CopyKeySet returns a shallow copy of a key set map.

func HasSignedQuery

func HasSignedQuery(values url.Values, signedKeys map[string]struct{}) bool

HasSignedQuery returns true when query contains a non-empty signing key value.

func MergeKeySets

func MergeKeySets(sets ...map[string]struct{}) map[string]struct{}

MergeKeySets returns a merged copy of all provided key sets.

func RedactURLForError added in v1.260731.0

func RedactURLForError(rawURL string) string

RedactURLForError reduces a URL to scheme, host, and path. Userinfo, query values, and the fragment are dropped because presigned uploads carry their capability there. The path is kept because it identifies the operation.

func RedactURLHostForError added in v1.260731.0

func RedactURLHostForError(rawURL string) string

RedactURLHostForError reduces a URL to scheme and host only. Use it when the path is itself a credential, as with Slack incoming webhooks.

func SanitizeURLForLog

func SanitizeURLForLog(rawURL string, signedKeys, sensitiveKeys map[string]struct{}) string

SanitizeURLForLog redacts sensitive URL fields while preserving shape.

Types

type TransportError added in v1.260731.0

type TransportError struct {
	Message string
	Err     error
}

TransportError describes a failed request without repeating the request URL's credentials. Unwrap keeps errors.Is and errors.As usable on the cause.

func NewTransportError added in v1.260731.0

func NewTransportError(operation, safeURL string, err error) *TransportError

NewTransportError builds a sanitized transport error for an operation against safeURL, which must already have been reduced by one of the redact helpers.

func (*TransportError) Error added in v1.260731.0

func (e *TransportError) Error() string

Error returns the sanitized message. The wrapped cause is deliberately not interpolated: net/http renders the full request URL in its error text.

func (*TransportError) Unwrap added in v1.260731.0

func (e *TransportError) Unwrap() error

Unwrap exposes the underlying transport error for inspection.

Jump to

Keyboard shortcuts

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