Skip to content

fix(api): mask url-valued headers and panic values in logs - #78

Merged
josuegiron merged 2 commits into
masterfrom
fix/redact-url-valued-headers
Nov 21, 2026
Merged

josuegiron merged 2 commits into
masterfrom
fix/redact-url-valued-headers

Conversation

@josuegiron

@josuegiron josuegiron commented Nov 21, 2026 •

Copy link
Copy Markdown
Member

Scope

One PR (1 of 1), module api only. Includes: masking of URL-valued header values in the request log record (default instance, instances, deprecated LogRequest), and redaction of recovered panic values. Leaves out: http.ErrAbortHandler handling (separate PR), any change to how uri is masked. No further changes planned on top.

Reason

  • redactHeaders masked by header name only, so Referer: https://x/cb?token=T, Origin: https://u:p@host, X-Original-URL: /login?password=P and similar were logged in clear, while the same key in uri was masked (retro findings: epic-api-v1-instance Feature/upgrade go version #8, epic-security-fixes Feature/upgrade go version #5).
  • logPanic logged the raw recovered value, which may carry a secret (e.g. panic(err) of a failed parse of a sensitive header) (epic-security-fixes Fix error to inicializate api #6).

Changes

  • functions.go: new unexported redactHeaderValue / redactEveryQuery; redactHeaders applies them to every value not masked by name. Shape rule, not a header-name list (custom proxy headers are covered): every ? starts a query that runs to the next ?, masked by key with redactQuery (so each URL of a Link list is covered); a value starting with / or containing :// also has its user information masked (redactUserInfo, as for uri). Values with neither ? nor @ are returned as is (no allocation).
  • instance_log.go: logPanic logs panic only for a runtime.Error, [REDACTED] otherwise, and always adds panic_type (%T). Same rule for the handler aborted debug record.
  • Doc comments (LogRequest, logRequest, logPanic, WithLogger, WithErrorHook), README "Logging"/"Security notes", docs/migration-v1.md, ADR 0001 (amended note).
  • No new exported name, option, package variable, or dependency.

Release notes

  • Security (logging): request log records now mask sensitive query values (by the same sensitive keys as uri) inside header values such as Referer, Origin, Link, X-Original-URL, X-Forwarded-Uri, and the user information of URL-valued headers. Previously only headers with a sensitive name were masked.
  • Security (logging): the panic recovered / handler aborted records carry a new panic_type attribute; panic holds the value only for a runtime.Error and is [REDACTED] otherwise, since an arbitrary panic value may carry request data. Log queries that read panic for non-runtime panics should use panic_type. No API or wire change.

Review

Quick review lens; findings applied in bb9b920: a Link list leaked a sensitive key of a later URL (now each ? starts a query), ADR 0001 and several doc comments were out of date, test secrets were not distinctive and absence was not checked, a doc-comment wrap. One finding rejected: Principle V would call a documented log-content change MAJOR for a v1 module; the owner directed this as a PATCH (log content is not the exported API or wire format) — recorded as an owner question.

Verification

Test-first: TestHeaderMaskingAgreesWithTheDefaultInstance (default instance and an instance log the same masked headers: Referer, Origin, origin-form, network-path, Link, Link list, comma in a query value, URL in a query value, query-only, multi-value, non-URL values, sensitive name; every secret is absent from all records) and TestInstanceLogsPanicValueOnlyForRuntimeErrors (string, error with secret, nil map write, index out of range) failed before the change and pass after; TestInstanceLogsRecoveredPanic, the recover test and the default-instance golden record were updated; TestLogRequestRedactsURLValuedHeaders covers the deprecated LogRequest.

Local runs (after review patches):

  • gofmt -l . — no output
  • go vet ./... — ok
  • go test -race ./... — ok for every package
  • govulncheck ./... — No vulnerabilities found
  • BenchmarkRedactHeaders (Authorization, Accept, User-Agent, Referer with query): baseline ~2.1 µs, 512 B, 10 allocs → ~3.1 µs, 680 B, 16 allocs (the Referer query masking; values without ?/@ add no allocation). BenchmarkProcessRequest unchanged (its loggers discard, so redaction does not run).

🤖 Generated with Claude Code

josuegiron and others added 2 commits November 21, 2026 19:38
Header values not masked by name are now masked as uri when they carry
a URL (start with "/" or contain "://"), and any other value with a "?"
has its query part masked, so a Referer, Origin, X-Original-URL or Link
no longer logs a token or user information in clear.

A recovered panic logs its value only for a runtime.Error; any other
value is logged as [REDACTED], and every panic record gets panic_type.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@josuegiron
josuegiron merged commit b76254a into master Nov 21, 2026
2 checks passed
@josuegiron
josuegiron deleted the fix/redact-url-valued-headers branch November 21, 2026 19:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant