# 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: मध्यम 3 भाषाएँ कवर की गईं - Impact: उच्च 3 उच्च गंभीरता वाले नियम - Prevention: प्रलेखित 3 फिक्स उदाहरण **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 1 Shoulder डिटेक्शन नियमों पर आधारित Session Fixation के लिए रोकथाम रणनीतियाँ। ### 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 - विशेषाधिकार प्राप्त करना - सुरक्षा तंत्र को बायपास करना ## Mitigations - सफल प्रमाणीकरण के बाद सत्र ID को पुनः उत्पन्न करें - नए सत्र बनाते समय पुराने सत्रों को अमान्य करें - सुरक्षित सत्र प्रबंधन लाइब्रेरीज़ का उपयोग करें ## 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