{"id":"CVE-2026-118658","aliases":["CVE-2026-118658","GHSA-23wf-92cp-8pcj","GO-2026-6878"],"related":[],"kind":"vulnerability","state":"published","title":"Echo: Arbitrary Scheme Injection in WWWRedirect/NonWWWRedirect Middlewares via X-Forwarded-Proto","summary":"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.","summarySource":"cvelist","descriptions":[{"lang":"en","text":"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.","source":"cvelist"},{"lang":"en","text":"## Summary\n\nThe `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.\n\n## Affected Components\n\n- `context.go:162-181` - `Scheme()` method returns attacker-controlled value verbatim\n- `middleware/redirect.go:172-184` - `redirectWWW`/`redirectNonWWW` use unsanitized scheme\n\n## Proof of Concept\n\n```\nGET /path HTTP/1.1\nHost: example.com\nX-Forwarded-Proto: javascript\n\nResponse:\nHTTP/1.1 301 Moved Permanently\nLocation: javascript://www.example.com/path\n```\n\nConfirmed injectable schemes: `javascript`, `data`, `vbscript`, `file`, `ftp`, `ssh`, `telnet`, `gopher`.\n\nOnly `WWWRedirect()` and `NonWWWRedirect()` (and `WithConfig` variants) are affected. `HTTPSRedirect`, `HTTPSWWWRedirect`, `HTTPSNonWWWRedirect` are NOT affected (they hardcode `https://`).\n\n## Impact\n\n- Open redirect to arbitrary scheme URLs when app is not behind a proxy that strips `X-Forwarded-Proto`\n- Cache poisoning when behind a CDN that caches redirect responses keyed by path\n- `file://` scheme injection could trigger file access in some browser configurations\n\n## Suggested Fix\n\nWhitelist scheme in `c.Scheme()` to only return `http` or `https`:\n\n```go\nfunc (c *Context) Scheme() string {\n    if c.IsTLS() {\n        return \"https\"\n    }\n    if scheme := c.request.Header.Get(HeaderXForwardedProto); scheme != \"\" {\n        scheme = strings.ToLower(strings.TrimSpace(scheme))\n        if scheme == \"https\" {\n            return \"https\"\n        }\n    }\n    return \"http\"\n}\n```\n\n## Disclosure\n\nSource code review, manually verified with actual HTTP server. Tested on Echo v5.0.4 (latest master).\n\n## Patches\n\nFixed 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).\n\n## Workarounds\n\nUpgrade 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.","format":"markdown","source":"ghsa"},{"lang":"en","text":"Arbitrary Scheme Injection in WWWRedirect/NonWWWRedirect Middlewares via X-Forwarded-Proto in github.com/labstack/echo","format":"markdown","source":"go"}],"published":"2026-10-28T20:17:11.083Z","modified":"2026-11-05T23:26:00.516Z","severity":{"scorer":"GitHub_M","scheme":"CVSS:3.1","vector":"CVSS:3.1/AV:N/AC:H/PR:N/UI:R/S:C/C:L/I:L/A:N","score":4.7,"rating":"MEDIUM"},"severities":[{"scorer":"GitHub_M","scheme":"CVSS:3.1","vector":"CVSS:3.1/AV:N/AC:H/PR:N/UI:R/S:C/C:L/I:L/A:N","score":4.7,"rating":"MEDIUM"},{"scorer":"GitHub","scheme":"CVSS:3.1","vector":"CVSS:3.1/AV:N/AC:H/PR:N/UI:R/S:C/C:L/I:L/A:N","score":4.7,"rating":"MEDIUM"}],"cwes":["CWE-601"],"affected":[{"ranges":[{"version":">= 5.0.0, < 5.1.1","status":"affected"},{"version":"< 4.15.2","status":"affected"}],"vendor":"labstack","product":"echo","source":"cvelist"},{"ranges":[{"type":"semver","introduced":"0","status":"affected","fixed":"5.1.1"}],"ecosystem":"Go","package":"github.com/labstack/echo/v5","purl":"pkg:golang/github.com/labstack/echo/v5","source":"ghsa"},{"ranges":[{"type":"semver","introduced":"0","status":"affected","fixed":"4.15.2"}],"ecosystem":"Go","package":"github.com/labstack/echo/v4","purl":"pkg:golang/github.com/labstack/echo/v4","source":"ghsa"},{"ranges":[{"type":"semver","introduced":"0","status":"affected","fixed":"4.15.2"}],"ecosystem":"Go","package":"github.com/labstack/echo/v4","purl":"pkg:golang/github.com/labstack/echo/v4","source":"go"},{"ranges":[{"type":"semver","introduced":"0","status":"affected","fixed":"5.1.1"}],"ecosystem":"Go","package":"github.com/labstack/echo/v5","purl":"pkg:golang/github.com/labstack/echo/v5","source":"go"}],"references":[{"url":"https://github.com/labstack/echo/security/advisories/GHSA-23wf-92cp-8pcj","tags":["advisory","exploit","web","x-refsource-confirm"],"sources":["cvelist","ghsa","go","nvd"]},{"url":"https://github.com/labstack/echo/commit/ca4f38a474302aabee93c66bdd0052359882e181","tags":["fix","web","x-refsource-misc"],"sources":["cvelist","ghsa","go","nvd"]},{"url":"https://github.com/labstack/echo/commit/d1d8ad3f99dd9b80542cd0c357d56a8916c515df","tags":["fix","web","x-refsource-misc"],"sources":["cvelist","ghsa","go","nvd"]},{"url":"https://github.com/labstack/echo/releases/tag/v4.15.2","tags":["web","x-refsource-misc"],"sources":["cvelist","ghsa","go","nvd"]},{"url":"https://github.com/labstack/echo/releases/tag/v5.1.1","tags":["web","x-refsource-misc"],"sources":["cvelist","ghsa","go","nvd"]},{"url":"https://github.com/labstack/echo/pull/2953","tags":["fix","web"],"sources":["ghsa","go"]},{"url":"https://github.com/labstack/echo","tags":["package"],"sources":["ghsa"]}],"credits":[],"assigner":"GitHub_M","ssvc":{"scorer":"CISA-ADP","exploitation":"poc","automatable":"no","technicalImpact":"partial","date":"2026-11-02T20:43:55.876Z"},"sources":[{"source":"cvelist","name":"CVE List","id":"CVE-2026-118658","url":"https://www.cve.org/CVERecord?id=CVE-2026-118658","licence":"CVE Terms of Use","modified":"2026-11-02T20:44:22.513Z"},{"source":"ghsa","name":"GitHub Advisory Database","id":"GHSA-23wf-92cp-8pcj","url":"https://github.com/advisories/GHSA-23wf-92cp-8pcj","licence":"CC-BY-4.0","modified":"2026-11-05T23:26:00.516Z"},{"source":"go","name":"Go Vulnerability Database","id":"GO-2026-6878","url":"https://pkg.go.dev/vuln/GO-2026-6878","licence":"CC-BY-4.0","modified":"2026-11-05T23:15:15.416Z"},{"source":"nvd","name":"NVD","id":"CVE-2026-118658","url":"https://nvd.nist.gov/vuln/detail/CVE-2026-118658","licence":"Public domain","modified":"2026-11-02T21:17:27.930Z"}],"updatedAt":"2026-11-25T22:59:47.688Z","epss":{"score":0.00269,"percentile":0.20335,"date":"2026-12-01T12:00:22.000Z"}}