Repository navigation
Conversation
…aders
SendErrorJSON and ErrorLogger.Log cut the caller's path to its last
three elements without checking the length, so a caller file with a
shorter path, as in the root of a single-element module built with
-trimpath, panicked before the error response was written. The remote
address was cut at the first colon, which logged an IPv6 client as
"[2001"; it is now split with net.SplitHostPort, and a bare address
left by RealIP is logged whole.
Profiler routed only a fixed list of profile names, and pprof.Index
resolves names only under /debug/pprof/, so /pprof/allocs, /pprof/mutex
and any profile the application registers returned the index page.
Every /pprof/{name} is now served with pprof.Handler(name).
The bcrypt and Argon2 BasicAuth variants compared the user name with !=
and returned before verifying the password, so a wrong user name was
rejected in about a microsecond and a valid one took a full hash, which
told valid names apart. They now verify the password whatever user name
is supplied and compare the name with subtle.ConstantTimeCompare.
CrossOriginProtection.Check ran the stdlib handler to find out whether
a request passes, which called a custom deny handler on every rejected
Check. It now returns the stdlib Check result.
Throttle with a negative limit panicked when the channel was created,
although the handler treats a limit of 0 or less as no limit.
CORS added Vary: Origin only to responses for an allowed origin, so a
shared cache could store the response for a disallowed origin or one
without Origin, which carries no CORS headers, and hand it to an
allowed origin. Every response now carries it.
NoCache sent Expires with a UTC suffix, and HTTP dates must end in GMT;
its doc comment now lists the headers it actually sets and removes.
Profiler() without addresses served /pprof/cmdline and /vars to every
source, because OnlyFrom with an empty list lets everything through,
while Metrics() without addresses rejects every request. Profiler now
does the same; Profiler("0.0.0.0/0", "::/0") serves every source on
purpose.
The logger read X-Request-ID from the request only, so an ID that Trace
generated never reached the log line, whichever side of the logger
Trace was on. It now falls back from the request header to the Trace
context value and then the response header, replacing line breaks with
spaces.
AnonymizeIP left native IPv6 and hexadecimal IPv4-mapped addresses
unchanged. It now masks native IPv6 to /48 and IPv4-mapped addresses to
/24, removing ports, brackets and zones from the output.
The logger's response writer always offered Flush and Hijack and had no
Unwrap, so under Timeout a handler got an http.Flusher whose Flush did
nothing, and http.ResponseController could not reach the server's
writer. It now offers each interface only when the writer beneath does,
as Gzip does, unwraps, and reports a failed flush through FlushError.
Headers split each entry on every colon and dropped an entry whose
value contained one, such as a URL. It now splits on the first colon.
The README named wrong headers, status codes and log fields, and some of its examples did not compile. It also left out public helpers and options, and that RealIP and OnlyFrom trust proxy headers from any peer, so a proxy has to overwrite all of them. The agent instructions move to AGENTS.md, with the CSRF note and the test commands corrected. CI moves to golangci-lint v2.15.0 with golangci-lint-action v9.
Coverage Report for CI Build 46064956569Coverage increased (+0.2%) to 97.053%Details
Uncovered ChangesNo uncovered changes found. Coverage RegressionsNo coverage regressions found. Coverage Stats
💛 - Coveralls |
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.
Previously, error logging could panic, the hashed BasicAuth variants exposed valid user names through response timing,
Profiler()served the process command line to every source, and several README sections described headers, fields and methods the package does not have. After this change, these defects are fixed, the behaviours below change, and the README documents the corrected behaviour and the configuration it left out.Fixes:
BasicAuthWithBcryptHash,BasicAuthWithBcryptHashAndPromptandBasicAuthWithArgon2Hashreturned before verifying the password when the user name was wrong, so the response time told valid user names apart. They now verify the password whatever user name is supplied, and compare the user name withsubtle.ConstantTimeCompare.SendErrorJSONandErrorLogger.Logno longer panic when the caller's file path has fewer than three elements, as for a file in the root of a single-element module built with-trimpath, and log an IPv6 client address whole instead of[2001.Profilerserves every profile under/pprof/{name}, includingallocs,mutexand profiles the application registers; previously any profile without its own route returned the pprof index page.CrossOriginProtection.Checkbuilt with Go 1.25 or newer no longer calls the custom deny handler. It returns the result of the stdlibCheck, so its error text is now the stdlib's, such as "cross-origin request detected from Sec-Fetch-Site header".Throttlewith a negative limit no longer panics; any limit of 0 or less disables it, as the handler already assumed.CORSaddsVary: Originto every response, including responses for a disallowed origin and requests withoutOrigin. Previously only an allowed origin got it, so a shared cache could hand a response stored without CORS headers to an allowed origin.NoCachesendsExpireswith theGMTsuffix that HTTP dates require, and its doc comment lists the headers it actually sets and removes.Behaviour changes:
Profiler()called without addresses rejects every request with 403, asMetrics()does. Previously it served/pprof/cmdlineand/vars, which carry the command line, to every source. A caller that wants it open lists every source explicitly:Profiler("0.0.0.0/0", "::/0").Trace. It takes the first non-empty ID from the request header, theTracecontext value and the response header, in that order, and replaces line breaks in it with spaces.logger.AnonymizeIPmasks native IPv6 addresses to their /48 network and IPv4-mapped addresses to /24 in every spelling, including hexadecimal forms such as::ffff:808:404; its output drops ports, brackets and zones. Previously native IPv6 and hexadecimal IPv4-mapped addresses were returned unchanged. Plain IPv4 output is the same as before.http.Flusherandhttp.Hijackeronly when the writer beneath supports them, as withGzip. UnderTimeoutthese assertions now fail instead of returning aFlushthat does nothing, andhttp.ResponseControllerreaches the writer beneath throughUnwrapand receives flush errors.Headerssplits each entry on its first colon, so a value containing colons, such asX-Upstream:http://10.0.0.1:8080, is set instead of silently dropped.Documentation:
X-Real-IP,CF-Connecting-IPandX-Forwarded-For, since a client-supplied header the proxy leaves in place can spoof the source address, including forOnlyFrom.CLAUDE.mdis renamed toAGENTS.md.latestwith golangci-lint-action v7 to golangci-lint v2.15.0 with golangci-lint-action v9.Regression tests:
TestShortCallerPath,TestErrorDetailsMsgRemoteAddr,TestProfiler_AllocsAndMutex,TestProfiler_AnyNamedProfile,TestBasicAuthHashedWrongUserStillHashes,TestCSRF_CheckDoesNotCallDenyHandler,TestThrottleNegativeLimit,TestCORS_VaryOriginOnEveryResponse,TestNoCache,TestProfiler_NoAddressesDeniesAll,TestProfiler_NoAddressesInvalidRemote,TestTraceIDLogged,TestLogger_TraceIDOnOneLine,TestAnonymizeIP,TestLogger_WriterCapabilities,TestLogger_WriterPassesCallsThrough,TestLogger_ResponseController,TestLogger_ResponseControllerFlushErrorandTestHeadersValueWithColon. Each fails without its fix.Validation: race tests on Go 1.27 and on Go 1.24.0, which builds the pre-1.25 CSRF implementation; golangci-lint v2.15.0 with no issues; statement coverage unchanged from master at 97.6%; the README code blocks compile against this branch.
Please publish a release after merging. The
Profiler()default is a breaking change: callers must now pass the source addresses they allow. remark42 does not callProfiler.