You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
SECURITY: middleware.ClientIP, a replacement for middleware.RealIP
@VojtechVitek submitted PR #967, which introduces middleware.ClientIP — a replacement for middleware.RealIP that closes the three open spoofing advisories:
middleware.RealIP is deprecated in this PR with pointers to the new API.
The deprecation only adds a // Deprecated: doc comment; the function keeps working for backward compatibility.
Why a new middleware (not "fix RealIP in place")
RealIP has two unfixable design choices: it mutates r.RemoteAddr, and it tries to be a one-size-fits-all default by walking a hard-coded list of headers any client can supply. Per adam-p's "The perils of the 'real' client IP" (which calls chi out by name on this), there is no safe default — the user must pick their trust source explicitly.
The new API
Four middlewares, two accessors. Pick exactly one middleware based on your
infrastructure, read the result with one of the two accessors:
// One of the four. There is no safe default — pick exactly one.funcClientIPFromHeader(trustedHeaderstring) func(http.Handler) http.HandlerfuncClientIPFromXFF(trustedIPPrefixes...string) func(http.Handler) http.HandlerfuncClientIPFromXFFTrustedProxies(numTrustedProxiesint) func(http.Handler) http.Handler</tr></table>
... (truncated)
Commits
3b17157 feat: middleware.ClientIP, a replacement for middleware.RealIP (#967)
818fdcf fix: set Request.Pattern from RoutePattern() (#1097)
Coverage variation is the difference between the coverage for the head and common ancestor commits of the pull request branch: <coverage of head commit> - <coverage of common ancestor commit>
Diff coverage is the percentage of lines that are covered by tests out of the coverable lines that the pull request added or modified: <covered lines added or modified>/<coverable lines added or modified> * 100%
NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer TIP This summary will be updated as you push new changes.
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
dependenciesPull requests that update a dependency filegoPull requests that update go code
0 participants
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.
Bumps github.com/go-chi/chi/v5 from 5.2.5 to 5.3.0.
Release notes
Sourced from github.com/go-chi/chi/v5's releases.
... (truncated)
Commits
3b17157feat: middleware.ClientIP, a replacement for middleware.RealIP (#967)818fdcffix: set Request.Pattern from RoutePattern() (#1097)f975af0Fix typo in Route doc comment (#1073)4ef87eamiddleware: fix httpFancyWriter.ReadFrom double-counting bytes with Tee (#1085)a54874fBump minimum Go to 1.23, always use request.Pattern (#1048)3328d4dApply the stringscutprefix modernizer (#1051)be60b2eSimplify chi.walk with slices.Concat (#1053)a36a925Remove last uses of io/ioutil (#1054)7d93ee3add go 1.26 to ci (#1052)903cff2Propagate inline middlewares across mounted subrouters (#1049)