# Session Fixation (CWE-384) Authenticating a user, or otherwise establishing a new user session, without invalidating any existing session identifier gives an attacker the opportunity to steal authenticated sessions. **Stack:** Go - Prevalence: Média 3 linguagens cobertas - Impact: Alto 3 regras de severidade alta - Prevention: Documentada 3 exemplos de correção **OWASP:** Identification and Authentication Failures (A07:2021-Identification and Authentication Failures) - #7 ## Description In a session fixation attack, the attacker sets a user's session ID to a known value before the user authenticates. After authentication, the attacker can use the known session ID to hijack the authenticated session. ## Prevention Estratégias de prevenção para Session Fixation baseadas em 1 regras de detecção do Shoulder. ### Key Practices - Use predictable values or cookies lack Secure/HttpOnly flags ### Go Use crypto/rand for session IDs with Secure, HttpOnly, and SameSite cookie flags ## Warning Signs - [HIGH] Session management has security weaknesses ## Consequences - Obter privilégios - Burlar mecanismo de proteção ## Mitigations - Regenere os IDs de sessão após autenticação bem-sucedida - Invalide sessões antigas ao criar novas - Use bibliotecas seguras de gerenciamento de sessão ## Detection - Total rules: 3 - Languages: javascript, typescript, go, python ## Rules by Language ### Go (1 rules) - **Insecure Session Management** [HIGH]: Session IDs use predictable values or cookies lack Secure/HttpOnly flags. - Remediation: Use crypto/rand for session IDs and set secure cookie flags. ```go b := make([]byte, 32) rand.Read(b) sessionID := base64.URLEncoding.EncodeToString(b) http.SetCookie(w, &http.Cookie{ Name: "session_id", Value: sessionID, HttpOnly: true, Secure: true, SameSite: http.SameSiteStrictMode, }) ``` Learn more: https://shoulder.dev/learn/go/cwe-384/insecure-session-management