CVE-2026-118658: Echo has Arbitrary Scheme Injection in WWWRedirect/NonWWWRedirect Middlewares via X-Forwarded-Proto
Summary
The c.Scheme() method in Echo (context.go:162-181) trusts the X-Forwarded-Proto, X-Forwarded-Protocol, and X-Url-Scheme request headers without validating that the value is http or https. The WWWRedirect() and NonWWWRedirect() middlewares use this unsanitized scheme to construct redirect URLs, allowing an attacker to inject arbitrary URI schemes into the Location response header.
Affected Components
- context.go:162-181 - Scheme() method returns attacker-controlled value verbatim - middleware/redirect.go:172-184 - redirectWWW/redirectNonWWW use unsanitized scheme
Proof of Concept
GET /path HTTP/1.1 Host: example.com X-Forwarded-Proto: javascript
Response: HTTP/1.1 301 Moved Permanently Location: javascript://www.example.com/path
Confirmed injectable schemes: javascript, data, vbscript, file, ftp, ssh, telnet, gopher.
Only WWWRedirect() and NonWWWRedirect() (and WithConfig variants) are affected. HTTPSRedirect, HTTPSWWWRedirect, HTTPSNonWWWRedirect are NOT affected (they hardcode https://).
Impact
- Open redirect to arbitrary scheme URLs when app is not behind a proxy that strips X-Forwarded-Proto - Cache poisoning when behind a CDN that caches redirect responses keyed by path - file:// scheme injection could trigger file access in some browser configurations
Suggested Fix
Whitelist scheme in c.Scheme() to only return http or https:
go func (c Context) Scheme() string { if c.IsTLS() { return "https" } if scheme := c.request.Header.Get(HeaderXForwardedProto); scheme != "" { scheme = strings.ToLower(strings.TrimSpace(scheme)) if scheme == "https" { return "https" } } return "http" }
Disclosure
Source code review, manually verified with actual HTTP server. Tested on Echo v5.0.4 (latest master).
Patches
Fixed in github.com/labstack/echo/v5 v5.1.1 and github.com/labstack/echo/v4 v4.15.2. Context.Scheme() now accepts only http, https, ws or wss from the X-Forwarded-Proto, X-Forwarded-Protocol and X-Url-Scheme headers, and falls back to http for any other value (#2953).
Workarounds
Upgrade to a patched version. If you cannot upgrade, have your edge proxy overwrite or remove the X-Forwarded-Proto, X-Forwarded-Protocol and X-Url-Scheme request headers.
Other sources
Arbitrary Scheme Injection in WWWRedirect/NonWWWRedirect Middlewares via X-Forwarded-Proto in github.com/labstack/echo
— OSV
Echo is a Go web framework. Prior to 4.15.2 and 5.1.1, Context.Scheme returns values from X-Forwarded-Proto, X-Forwarded-Protocol, or X-Url-Scheme without validating that they are supported web schemes. WWWRedirect and NonWWWRedirect use that value to construct a Location header, so an attacker controlling a forwarded scheme header can cause a redirect to use an arbitrary URI scheme. Exploitation requires an affected redirect middleware and user interaction with the response; the HTTPS-specific redirect variants hardcode HTTPS and are unaffected. This issue is fixed in 4.15.2 and 5.1.1.
— MITRE
Affected Software
Remediation
Recommended actions to resolve this vulnerability, in priority order.
- Upgrade
Upgrade
go/github.com/labstack/echo/v4to a version that resolves this vulnerability.Fixed in 4.15.2 - Upgrade
Upgrade
go/github.com/labstack/echo/v5to a version that resolves this vulnerability.Fixed in 5.1.1 - Upgrade
Upgrade
github.com/labstack/echoto a version that resolves this vulnerability.Fixed in 4.15.2 - Compensating control
If upgrading is not possible, have the edge proxy overwrite or remove the X-Forwarded-Proto, X-Forwarded-Protocol, and X-Url-Scheme request headers.
Event History
Frequently Asked Questions
Which deployments are exposed to this issue?
Deployments using Echo versions before 4.15.2 or 5.1.1 are exposed only if they enable the WWWRedirect or NonWWWRedirect middleware. HTTPS-specific redirect middleware variants are not affected.
What does an attacker need to exploit it?
An attacker must be able to supply a forwarded scheme header, such as X-Forwarded-Proto, X-Forwarded-Protocol, or X-Url-Scheme, to an affected redirect middleware. Exploitation also requires a user to interact with the resulting redirect response.
How can I determine whether my application is affected?
Check the Echo version and whether WWWRedirect or NonWWWRedirect middleware is configured. If either middleware is in use, test whether a request carrying one of the forwarded scheme headers can influence the URI scheme in the Location response header.
What should be done if upgrading is not immediately possible?
Prevent untrusted clients from controlling X-Forwarded-Proto, X-Forwarded-Protocol, and X-Url-Scheme before requests reach Echo. Upgrade to Echo 4.15.2 or 5.1.1 when possible.