GO-2026-6978: CSRF protection bypass via _method override in github.com/mikehelmick/go-bananas
middleware.MutateMethod accepts a method override from the query string or request body and allows overriding the HTTP method to safe methods such as GET. When installed as router middleware ahead of middleware.HandleCSRF, a cross-site POST request with method=GET is routed to the POST handler while HandleCSRF observes a GET request and skips CSRF token validation.
Affected Software
Remediation
Recommended actions to resolve this vulnerability, in priority order.
- Upgrade
Upgrade
go/github.com/mikehelmick/go-bananasto a version that resolves this vulnerability.Fixed in 1.0.2
Event History
Frequently Asked Questions
Which deployments are exposed?
Deployments are exposed when middleware.MutateMethod is installed as router middleware before middleware.HandleCSRF. In that order, a method override can cause the CSRF middleware to see a safe method while the request is routed to a POST handler.
What does an attacker need to send?
An attacker needs to induce a cross-site POST request containing _method=GET in the query string or request body. This causes MutateMethod to override the method observed by HandleCSRF, which then skips CSRF token validation.
What can be done before a fix is applied?
Ensure middleware.MutateMethod is not placed ahead of middleware.HandleCSRF in the router middleware order. Review whether _method overrides from query strings or request bodies are accepted in routes protected by CSRF validation.
How can I check whether my application is affected?
Inspect router middleware registration order and identify whether MutateMethod runs before HandleCSRF. Test or review whether a POST request with _method=GET reaches a POST handler while the CSRF middleware treats it as a GET request.