Skip to main content
VulnerabilityPublished

CVE-2026-118657: Echo · HTTPS Redirect and HSTS Bypass via Unconditional Trust of Forwarded Scheme Headers

Affects github.com/labstack/echo/v5Source GCVE Database

0
Authoritative record:CVE-2026-118657· Medium 5.9

Not known to be exploited · CVSS 5.9 Medium : upgrade to 5.4.0 when convenient.

Data as of 28 Oct 2026, 22:12 UTC

CVSS 3.1 base score
5.9Medium
How severe the flaw is on the 0–10 CVSS scale.
Patch
Available – fixed in 5.4.0, 4.16.0
CVSS:3.1/AV:N/AC:H/PR:N/UI:R/S:U/C:H/I:L/A:N

Exploitation evidence

  1. Disclosed: evidence found.

    CVE published 28 Oct 2026

  2. Detectable: no evidence on record.

    No public nuclei template indexed

  3. Weaponised: no evidence on record.

    No public exploit code indexed in Metasploit or Exploit-DB

  4. Exploited in the wild: no evidence on record.

    Not in CISA KEV and no source reports exploitation

  5. Observed by OffSeq Mirage: no evidence on record.

    No attack traffic recorded by OffSeq Mirage sensors

A missing step is not evidence of safety. Sources: cve.org (opens in a new tab), the Metasploit, Exploit-DB and nuclei-templates index as of 26 Oct 2026.

What to do

Upgrade github.com/labstack/echo/v5 to 5.4.0; github.com/labstack/echo/v4 to 4.16.0.

Affected software

ProductAffectedFixed in
Gogithub.com/labstack/echo/v5Affected
  • <5.4.0
Fixed in
  • 5.4.0
Gogithub.com/labstack/echo/v4Affected
  • <4.16.0
Fixed in
  • 4.16.0

Check your own hosts for these packages with threat-finder (opens in a new tab), our free open-source scanner.

Description

## 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/redirect_test.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/secure_test.go` (lines 42–53) and `context_test.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

References

Community reviews

Loading reviews…