Skip to content

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

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

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.
@vishr

vishr commented Oct 30, 2026

Copy link
Copy Markdown
Member

Resolved by #3197 and released in v4.16.3: https://github.com/labstack/echo/releases/tag/v4.16.3

The released RealIP fallback calls extractIP, and its regression tests cover bare IPv4 and IPv6 RemoteAddr values. Closing this superseded backport as completed by the security fix.

@vishr vishr closed this Oct 30, 2026
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.

2 participants