Session management صارفین کو درخواستوں میں لاگ ان رکھنے کو سنبھالتی ہے — اور اسے محفوظ طریقے سے کرنا اہم ہے، کیونکہ سیشن کی خامیاں (hijacking، fixation) حملہ آوروں کو صارفین کا روپ دھارنے دیتی ہیں۔ محفوظ سیشنز مناسب token handling، cookie security، اور lifecycle management شامل کرتے ہیں۔
سیشنز کیسے کام کرتے ہیں
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
