Session fixation
Description
The Gogs application does NOT regenerate session IDs upon successful authentication. This allows an attacker to perform a session fixation attack where they can force a victim to use a known session ID, then hijack the session after the victim logs in.
Vulnerable Code Snippet:
// File: internal/route/user/auth.go
func SignInPost(c *context.Context, f form.SignIn) {
// ... authentication logic ...
// ADD THIS: Regenerate session ID on successful login
c.Session.RegenerateID(c.Req.Context())
// ... set user session ...
}PoC
- Attacker obtains the session ID by visiting login page → Session: i_like_gogs=c9af1981d493dc56
- Attacker forces the victim to use this session ID via:
- Social engineering (send link with cookie)
- XSS on subdomain
- MITM attack
- Physical access
- Victim logs in using attacker's session ID → Session remains: c9af1981d493dc56
- Attacker uses the same session ID to access the victim's account → Complete account takeover achieved!
Impact
- Account Takeover: Complete compromise of user accounts
- Data Breach: Access to private repositories and sensitive data
- Privilege Escalation: If the admin account is compromised, full system access
- Persistence: Attacker maintains access as long as the session is valid