Skip to content

fix: resolve RealIP for bare RemoteAddr without port (v4) - #3146

Open
orinnz wants to merge 1 commit into
labstack:v4from
orinnz:fix/v4-realip-bare-remote-addr
Open

orinnz wants to merge 1 commit into
labstack:v4from
orinnz:fix/v4-realip-bare-remote-addr

Conversation

@orinnz

@orinnz orinnz commented Oct 3, 2026

Copy link
Copy Markdown

Backport of #3054 to v4.

When no IPExtractor is set, Context.RealIP() falls back to net.SplitHostPort(RemoteAddr) and ignores the error. If RemoteAddr is a bare IP with no port (some listeners and proxies produce this), it returns an empty string.

This switches the fallback to extractIP, the helper ExtractIPDirect already uses, which handles both ip:port and a bare IP.

Added bare IPv4 and IPv6 RemoteAddr cases to TestContext_RealIP. They fail before the change and pass after. go test ./... passes.

Context.RealIP fell back to net.SplitHostPort and ignored its error, so a
RemoteAddr holding just an IP (no :port) came back as an empty string.
Use extractIP, the helper ExtractIPDirect already uses, which accepts
both forms.

Backport of labstack#3054.
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