skills/session-fixation-anti-pattern/SKILL.md
Security anti-pattern for session fixation vulnerabilities (CWE-384). Use when generating or reviewing code that handles user sessions, login flows, or authentication state changes. Detects failure to regenerate session IDs after authentication.
npx skillsauth add igbuend/grimbard session-fixation-anti-patternInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Severity: High
Attackers fix a user's session ID before login. The attacker obtains a valid session ID, tricks the victim into using it, and when authentication fails to regenerate the session ID, hijacks the victim's authenticated session.
The anti-pattern is reusing the same session ID before and after authentication.
# VULNERABLE: Session ID not regenerated after login.
from flask import Flask, session, redirect, url_for, request
app = Flask(__name__)
app.secret_key = 'your_secret_key' # Insecure in production
@app.route('/')
def index():
if 'username' in session:
return f'Hello {session["username"]}! <a href="/logout">Logout</a>'
return 'Welcome, please <a href="/login">Login</a>'
@app.route('/login', methods=['GET', 'POST'])
def login():
if request.method == 'POST':
username = request.form['username']
password = request.form['password']
if check_credentials(username, password):
# FLAW: Session ID not regenerated.
# Existing session (potentially attacker-fixed) now authenticated.
session['username'] = username
return redirect(url_for('index'))
return 'Invalid credentials'
return '''
<form method="post">
<p><input type=text name=username></p>
<p><input type=password name=password></p>
<p><input type=submit value=Login></p>
</form>
'''
# Attack:
# 1. Attacker gets session_id=ABCD
# 2. Tricks victim into using session_id=ABCD (XSS, referrer, etc.)
# 3. Victim logs in, server reuses session_id=ABCD
# 4. Attacker hijacks authenticated session with session_id=ABCD
# SECURE: Regenerate session ID after login and privilege changes.
from flask import Flask, session, redirect, url_for, request
app = Flask(__name__)
app.secret_key = 'your_secret_key' # Use strong, securely managed key
@app.route('/')
def index_secure():
if 'username' in session:
return f'Hello {session["username"]}! <a href="/logout">Logout</a>'
return 'Welcome, please <a href="/login_secure">Login Securely</a>'
@app.route('/login_secure', methods=['GET', 'POST'])
def login_secure():
if request.method == 'POST':
username = request.form['username']
password = request.form['password']
if check_credentials(username, password):
# Regenerate session ID after authentication.
# Creates new session, invalidating pre-login session ID.
session.regenerate()
session['username'] = username
return redirect(url_for('index_secure'))
return 'Invalid credentials'
return '''
<form method="post">
<p><input type=text name=username></p>
<p><input type=password name=password></p>
<p><input type=submit value=Login></p>
</form>
'''
@app.route('/logout')
def logout():
session.clear() # Invalidate session data.
session.regenerate() # Regenerate to prevent reuse.
return redirect(url_for('index_secure'))
HttpOnly: Prevents client-side script accessSecure: HTTPS-only transmissionSameSite: CSRF protectiondevelopment
Security anti-pattern for Cross-Site Scripting vulnerabilities (CWE-79). Use when generating or reviewing code that renders HTML, handles user input in web pages, uses innerHTML/document.write, or builds dynamic web content. Covers Reflected, Stored, and DOM-based XSS. AI code has 86% XSS failure rate.
development
Security anti-pattern for XPath injection vulnerabilities (CWE-643). Use when generating or reviewing code that queries XML documents, constructs XPath expressions, or handles user input in XML operations. Detects unescaped quotes and special characters in XPath queries.
development
Security anti-pattern for weak password hashing (CWE-327, CWE-759). Use when generating or reviewing code that stores or verifies user passwords. Detects use of MD5, SHA1, SHA256 without salt, or missing password hashing entirely. Recommends bcrypt, Argon2, or scrypt.
development
Security anti-pattern for weak encryption (CWE-326, CWE-327). Use when generating or reviewing code that encrypts data, handles encryption keys, or uses cryptographic modes. Detects DES, ECB mode, static IVs, and custom crypto implementations.