The vulnerability, identified as GHSA-hcff-qv74-7hr4, is a Cross-Site Request Forgery (CSRF) in the login endpoint of Gokapi. The root cause was the use of request.Form.Get() in several handlers, including the primary login function showLogin. This function call in Go's net/http package parses form data from both the URL query parameters (GET requests) and the request body (POST requests). This allowed an attacker to craft a malicious URL containing credentials in the query string. When a victim clicks this URL, their browser sends a GET request to the login endpoint, effectively logging them into an account controlled by the attacker.
The fix involved two main changes. First, all instances of r.Form.Get() that handled sensitive data were replaced with r.PostForm.Get(). This ensures that the application only processes data from the body of a POST request, which is the standard and secure way to handle login and other state-changing actions. Second, as a defense-in-depth measure, the session cookie was updated to include the SameSite=Lax attribute via the writeSessionCookie function. This instructs the browser not to send the cookie with cross-site GET requests, providing an additional layer of protection against CSRF attacks.