Echo has CSRF Protection Bypass via MethodOverride Rewriting POST to Safe Method
影響パッケージ
| 種類 | パッケージ | 影響を受ける版 | 直った版 |
|---|---|---|---|
| labstack | echo | — | — |
| go | github.com/labstack/echo/v5 |
5.0.0 以上 5.4.0 未満 |
5.4.0 |
| go | github.com/labstack/echo/v4 |
4.16.0 未満 |
4.16.0 |
原文の説明 取得元が公開している説明をそのまま載せています (多くは英語)。
Summary
The MethodOverride middleware accepts any non-empty string as the override target method — including safe methods (GET, HEAD, OPTIONS, TRACE) — when rewriting a POST request. When MethodOverride is registered before CSRF in the post-routing middleware chain (e.Use()), it rewrites the request method to a safe method before CSRF evaluates it. The CSRF middleware then skips token validation for the now-safe method, allowing state-changing POST handlers to execute without any CSRF check. Both the legacy token path and the modern Sec-Fetch-Site protection path are bypassed simultaneously.
Affected Component
middleware/method_override.go—MethodOverrideConfig.ToMiddleware()(lines 55–71): no whitelist on the override target methodmiddleware/csrf.go—CSRFConfig.ToMiddleware()(lines 188–189): safe-method bypass branch reads the already-rewritten methodmiddleware/csrf.go—checkSecFetchSiteRequest()(line 283):Sec-Fetch-Sitesafe check also reads the rewritten method
Description
MethodOverride accepts safe methods as override targets
MethodOverrideConfig.ToMiddleware() (method_override.go:55-71) restricts the source method (only POST requests are overrideable) but applies no whitelist to the target:
// method_override.go:61-67
req := c.Request()
if req.Method == http.MethodPost {
m := config.Getter(c)
if m != "" {
req.Method = m // ← any non-empty string accepted, including "GET"…
出典: CVE.org (CVE Program・cvelistV5) NVD GitHub Advisory