セッション管理は、ユーザーがリクエスト全体でログイン状態を保つことを処理します。セッション管理を安全に行うことは重要です。セッションの脆弱性(ハイジャック、固定化)により、攻撃者がユーザーになりすまし可能になるからです。安全なセッションには、適切なトークン処理、クッキーのセキュリティ、およびライフサイクル管理が必要です。
セッションの仕組み
After login, the server keeps a SESSION identifying the user across requests:
→ a SESSION ID (or token) is stored client-side (usually a cookie) and sent each request
→ the server uses it to know who the user is (without re-authenticating each time)
→ the session ID/token is effectively a key to the user's account → must be PROTECTED.
セッションの保護
✓ SECURE COOKIE flags for session cookies:
→ HttpOnly → JavaScript can't read it (protects against theft via XSS)
→ Secure → sent only over HTTPS (not plaintext)
→ SameSite → not sent on cross-site requests (mitigates CSRF)
✓ Strong, RANDOM, unpredictable session IDs (can't be guessed)
✓ Store session data server-side (or sign/encrypt tokens); transmit over HTTPS only
