httpdebug

package
v0.7.3 Latest Latest
Warning

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

Go to latest
Published: Jun 2, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package httpdebug logs HTTP request / response traffic for developer-facing debugging while redacting credentials.

Three redaction layers run independently:

  • sensitive headers (Authorization, Proxy-Authorization) collapse to a placeholder before any header dump is written;
  • URL userinfo (user@ or user:pass@) is stripped from any text run through RedactURLCredentials, covering Location headers and HTML redirect bodies;
  • JSON token fields (access_token, id_token, refresh_token, subject_token) — the shapes the STS / OAuth endpoints return — collapse to the placeholder.

The redactors run in that order in BodyPreview. Truncation comes last: if a long JWT or URL password extends past the preview boundary, truncating first would leave the regex's terminator outside the slice and silently leak the secret. Tests in this package pin the order.

Index

Constants

View Source
const Placeholder = "***REDACTED***"

Placeholder replaces any redacted value in dumps.

View Source
const PreviewBytes = 512

PreviewBytes is the upper bound on the size of a body preview written to the log. Anything beyond is truncated.

Variables

View Source
var SensitiveHeaders = map[string]struct{}{
	"Authorization":       {},
	"Proxy-Authorization": {},
}

SensitiveHeaders carries credentials we never want to log verbatim. Stored by canonical key so RedactHeaders can do a single map lookup per header.

Functions

func BodyPreview

func BodyPreview(body []byte) []byte

BodyPreview returns the first PreviewBytes of body after URL + JSON-token redaction. Redaction MUST happen before truncation: a long JWT or URL password can extend past PreviewBytes, leaving its terminator (closing quote or `@`) outside the preview slice and out of reach of the regexes — truncate-first silently leaks the secret.

When the body contains a packfile, the preview ends just after the PACK signature so the rest of the binary stream doesn't flood the log.

func RedactHeaders

func RedactHeaders(h http.Header) http.Header

RedactHeaders returns a copy of h with values for SensitiveHeaders replaced by Placeholder. The input is not mutated — callers still need the real headers on the live request/response.

func RedactJSONTokens

func RedactJSONTokens(body []byte) []byte

RedactJSONTokens replaces JWT values inside a JSON body with Placeholder. Bodies that aren't JSON (or don't carry token fields) pass through unchanged.

func RedactURLCredentials

func RedactURLCredentials(s []byte) []byte

RedactURLCredentials replaces the userinfo of any http/https URL in s with Placeholder. Safe to run over arbitrary text — header dumps, HTML bodies, log lines.

Types

type RoundTripper

type RoundTripper struct {
	Next http.RoundTripper
}

RoundTripper wraps another http.RoundTripper and logs each request/response when debuglog.Enabled returns true. Bodies and sensitive headers are redacted before logging.

When debugging is off, the wrapper is a thin pass-through: no allocations, no body buffering.

func (*RoundTripper) RoundTrip

func (d *RoundTripper) RoundTrip(req *http.Request) (*http.Response, error)

RoundTrip implements http.RoundTripper. Response bodies are read in full (so the preview can render correctly) and re-wrapped before returning — the caller sees an io.ReadCloser as before. This is a debug-only cost; non-debug mode skips the read entirely.

Jump to

Keyboard shortcuts

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