Now liveThe Skillselion MCP - thousands of ranked skills, loaded into your agent mid-task. No install.Get it →
engremran07 avatar

Sec Session Fixation

  • 1 installs
  • Updated May 22, 2026
  • engremran07/gsmvault

Prevent session fixation in Django - rotate the session on login, privilege escalation, and password change using cycle_key and update_session_auth_hash.

About

Session fixation prevention patterns for Django login and privilege-escalation flows. A developer uses it when implementing custom login, reviewing session handling, or auditing for session fixation vulnerabilities.

  • Django login() rotates session via cycle_key automatically
  • Manual cycle_key on MFA escalation; update_session_auth_hash on password change

Sec Session Fixation by the numbers

  • 1 all-time installs (skills.sh)
  • Ranked #1,834 of 2,203 Security skills by installs in the Skillselion catalog
  • Data as of Jul 8, 2026 (Skillselion catalog sync)
npx skills add https://github.com/engremran07/gsmvault --skill sec-session-fixation

Add your badge

Show developers this skill is listed on Skillselion. Paste this into your README.

Listed on Skillselion
Installs1
Last updatedMay 22, 2026
Repositoryengremran07/gsmvault

What it does

Prevent session fixation in Django - rotate the session on login, privilege escalation, and password change using cycle_key and update_session_auth_hash.

Files

SKILL.mdMarkdownGitHub ↗

Session Fixation Prevention

When to Use

  • Implementing custom login flows
  • Reviewing session handling security
  • Auditing for session fixation vulnerabilities

Rules

RuleImplementation
Rotate on loginrequest.session.cycle_key() — Django login() does this
Rotate on privilege escalationAny elevation (e.g., MFA verified)
Never accept external session IDsDjango session middleware rejects unknown IDs
Regenerate after password changeupdate_session_auth_hash()

Patterns

Django login() — Automatic Rotation

from django.contrib.auth import login as auth_login

def login_view(request: HttpRequest) -> HttpResponse:
    form = AuthenticationForm(request, data=request.POST)
    if form.is_valid():
        user = form.get_user()
        # auth_login() calls request.session.cycle_key() internally
        # This creates a new session ID, invalidating the old one
        auth_login(request, user)
        return redirect("dashboard")
    return render(request, "users/login.html", {"form": form})

Manual Session Rotation (Privilege Escalation)

def verify_mfa(request: HttpRequest) -> HttpResponse:
    code = request.POST.get("code", "")
    if verify_totp(request.user, code):
        # Rotate session after MFA verification (privilege escalation)
        request.session.cycle_key()
        request.session["mfa_verified"] = True
        return redirect("admin:index")
    return render(request, "users/mfa_verify.html", {"error": "Invalid code"})

Password Change — Session Preservation

from django.contrib.auth import update_session_auth_hash

def change_password_view(request: HttpRequest) -> HttpResponse:
    form = PasswordChangeForm(request.user, request.POST)
    if form.is_valid():
        user = form.save()
        # Regenerate session hash — keeps user logged in
        # Also invalidates all other sessions for this user
        update_session_auth_hash(request, user)
        return redirect("profile")

Red Flags

  • Custom login that calls authenticate() but not login() — no session rotation
  • Missing update_session_auth_hash() after password change
  • request.session.session_key used as authentication token
  • Accepting session IDs from URL parameters or POST data

Quality Gate

& .\.venv\Scripts\python.exe -m ruff check . --fix
& .\.venv\Scripts\python.exe -m ruff format .
& .\.venv\Scripts\python.exe manage.py check --settings=app.settings_dev

Related skills

Securityappsecaudit

This week in AI coding

Five minutes, every Monday - the tools, releases and tactics for developers.

unsubscribe anytime.