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

Session Management

  • 411 installs
  • 305 repo stars
  • Updated March 4, 2026
  • aj-geddes/useful-ai-prompts

session-management is an agent skill that implements secure session cookies, JWT rotation, fixation defenses, and logout invalidation for developers who need production-grade authenticated user flows.

About

session-management is an aj-geddes/useful-ai-prompts agent skill for building secure authentication state in SaaS and ecommerce backends. It covers JWT access tokens with 1-hour expiry and 7-day refresh tokens, server-side Redis session storage, secure httpOnly SameSite cookies, CSRF token protection, session fixation defenses, rotation, and logout cleanup across Flask, Express, and related frameworks. Seven reference guides address JWT generation, Node.js Express JWT setup, Redis session storage, CSRF protection, middleware chains, token refresh endpoints, and session cleanup jobs. Developers reach for session-management when adding login to a new API, hardening cookie flags, implementing refresh-token rotation, or defending against session fixation and CSRF on state-changing routes.

  • Secure cookie flags and SameSite guidance
  • Session fixation and rotation defenses
  • Server-side store vs signed JWT tradeoffs
  • Idle and absolute timeout policies
  • Centralized logout and token revocation

Session Management by the numbers

  • 411 all-time installs (skills.sh)
  • Ranked #551 of 2,203 Security skills by installs in the Skillselion catalog
  • Data as of Aug 5, 2026 (Skillselion catalog sync)
npx skills add https://github.com/aj-geddes/useful-ai-prompts --skill session-management

Add your badge

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

Listed on Skillselion
Installs411
repo stars305
Last updatedMarch 4, 2026
Repositoryaj-geddes/useful-ai-prompts

How do you implement secure JWT session management?

Implement secure session cookies, rotation, fixation defenses, server-side store or JWT strategies, and logout invalidation for authenticated SaaS and ecommerce user flows.

Who is it for?

Backend developers shipping authenticated SaaS or ecommerce APIs who need JWT, cookie, and CSRF hardening with Redis-backed sessions.

Skip if: Developers integrating a hosted auth provider like Auth0 or Clerk who do not manage session storage themselves.

When should I use this skill?

Adding user login, implementing refresh-token rotation, configuring secure session cookies, or adding CSRF protection to authenticated APIs.

What you get

Token manager classes, secure cookie configuration, refresh endpoints, CSRF middleware, and session cleanup policies.

  • token refresh flow
  • secure cookie middleware
  • CSRF protection layer

By the numbers

  • Bundles 7 reference guides for JWT, Express, Redis sessions, and CSRF
  • Quick-start TokenManager uses 1-hour access tokens and 7-day refresh tokens

Files

SKILL.mdMarkdownGitHub ↗

Session Management

Table of Contents

Overview

Implement comprehensive session management systems with secure token handling, session persistence, token refresh mechanisms, proper logout procedures, and CSRF protection across different backend frameworks.

When to Use

  • Implementing user authentication systems
  • Managing session state and user context
  • Handling JWT token refresh cycles
  • Implementing logout functionality
  • Protecting against CSRF attacks
  • Managing session expiration and cleanup

Quick Start

Minimal working example:

# Python/Flask Example
from flask import current_app
from datetime import datetime, timedelta
import jwt
import os

class TokenManager:
    def __init__(self, secret_key=None):
        self.secret_key = secret_key or os.getenv('JWT_SECRET')
        self.algorithm = 'HS256'
        self.access_token_expires_hours = 1
        self.refresh_token_expires_days = 7

    def generate_tokens(self, user_id, email, role='user'):
        """Generate both access and refresh tokens"""
        now = datetime.utcnow()

        # Access token
        access_payload = {
            'user_id': user_id,
            'email': email,
            'role': role,
            'type': 'access',
            'iat': now,
            'exp': now + timedelta(hours=self.access_token_expires_hours)
// ... (see reference guides for full implementation)

Reference Guides

Detailed implementations in the references/ directory:

GuideContents
JWT Token Generation and ValidationJWT Token Generation and Validation
Node.js/Express JWT ImplementationNode.js/Express JWT Implementation
Session Storage with RedisSession Storage with Redis
CSRF ProtectionCSRF Protection
Session Middleware ChainSession Middleware Chain
Token Refresh EndpointToken Refresh Endpoint
Session Cleanup and MaintenanceSession Cleanup and Maintenance

Best Practices

✅ DO

  • Use HTTPS for all session transmission
  • Implement secure cookies (httpOnly, sameSite, secure flags)
  • Use JWT with proper expiration times
  • Implement token refresh mechanism
  • Store refresh tokens securely
  • Validate tokens on every request
  • Use strong secret keys
  • Implement session timeout
  • Log authentication events
  • Clear session data on logout
  • Use CSRF tokens for state-changing requests

❌ DON'T

  • Store sensitive data in tokens
  • Use short secret keys
  • Transmit tokens in URLs
  • Ignore token expiration
  • Reuse token secrets across environments
  • Store tokens in localStorage (use httpOnly cookies)
  • Implement session without HTTPS
  • Forget to validate token signatures
  • Expose session IDs in logs
  • Use predictable session IDs

Related skills

How it compares

Use session-management when you own auth session storage and cookie policy; use an OAuth-integration skill when delegating identity to an external IdP.

FAQ

Does session-management recommend localStorage for JWTs?

session-management explicitly warns against storing tokens in localStorage. The skill recommends httpOnly, Secure, SameSite cookies for session transmission and Redis or server-side stores for refresh tokens with rotation and logout invalidation.

How many reference guides ship with session-management?

session-management bundles 7 reference guides covering JWT generation, Express JWT implementation, Redis session storage, CSRF protection, middleware chains, token refresh endpoints, and session cleanup maintenance.

Securityappsecsecrets

This week in AI coding

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

unsubscribe anytime.