Repository navigation
fix(api): mask url-valued headers and panic values in logs - #78
Merged
Merged
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Scope
One PR (1 of 1), module
apionly. Includes: masking of URL-valued header values in therequestlog record (default instance, instances, deprecatedLogRequest), and redaction of recovered panic values. Leaves out:http.ErrAbortHandlerhandling (separate PR), any change to howuriis masked. No further changes planned on top.Reason
redactHeadersmasked by header name only, soReferer: https://x/cb?token=T,Origin: https://u:p@host,X-Original-URL: /login?password=Pand similar were logged in clear, while the same key inuriwas masked (retro findings: epic-api-v1-instance Feature/upgrade go version #8, epic-security-fixes Feature/upgrade go version #5).logPaniclogged 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 unexportedredactHeaderValue/redactEveryQuery;redactHeadersapplies 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 withredactQuery(so each URL of aLinklist is covered); a value starting with/or containing://also has its user information masked (redactUserInfo, as foruri). Values with neither?nor@are returned as is (no allocation).instance_log.go:logPaniclogspaniconly for aruntime.Error,[REDACTED]otherwise, and always addspanic_type(%T). Same rule for thehandler aborteddebug record.LogRequest,logRequest,logPanic,WithLogger,WithErrorHook), README "Logging"/"Security notes",docs/migration-v1.md, ADR 0001 (amended note).Release notes
uri) inside header values such asReferer,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.panic recovered/handler abortedrecords carry a newpanic_typeattribute;panicholds the value only for aruntime.Errorand is[REDACTED]otherwise, since an arbitrary panic value may carry request data. Log queries that readpanicfor non-runtime panics should usepanic_type. No API or wire change.Review
Quick review lens; findings applied in bb9b920: a
Linklist 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) andTestInstanceLogsPanicValueOnlyForRuntimeErrors(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;TestLogRequestRedactsURLValuedHeaderscovers the deprecatedLogRequest.Local runs (after review patches):
gofmt -l .— no outputgo vet ./...— okgo test -race ./...— ok for every packagegovulncheck ./...— No vulnerabilities foundBenchmarkRedactHeaders(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).BenchmarkProcessRequestunchanged (its loggers discard, so redaction does not run).🤖 Generated with Claude Code