Prompt
How do I detect suspicious logins and session hijacking in SaaS?
Latest observation
To detect suspicious logins and session hijacking in a SaaS product, focus on behavioral anomalies, session integrity, and step-up verification. A good detection strategy combines signals from authentication, device/browser fingerprinting, IP intelligence, and session behavior.
1) Detect suspicious logins
Common signals
Flag or score logins when you see:
- Impossible travel
Same user logs in from distant geographies in too little time. - New device / new browser
First time seeing this device fingerprint or user agent. - New IP / ASN / country
Especially residential proxies, VPNs, hosting providers, or TOR. - Password spray / credential stuffing patterns
Many failed logins across many accounts from the same IP/subnet. - Unusual time of day
Login outside the user’s normal pattern. - Unusual authentication path
For example, password login when the user normally uses SSO or MFA. - Risky account changes around login
MFA disabled, recovery email changed, session settings altered.
Useful data to collect
- User ID, org ID
- Timestamp
- IP address, geo, ASN, proxy/VPN detection
- User agent
- Device fingerprint / browser fingerprint
- Auth method, MFA status
- Success/failure reason
- Session ID
- Login velocity and historical baseline
Detection examples
- Rule: login from a new country + no MFA = high risk
- Rule: 10 failed attempts for 50 accounts from one IP in 5 minutes = credential stuffing
- Rule: login from new device shortly after password reset = suspicious
- Rule: “impossible travel” with successful logins from two countries within 30 minutes = likely account compromise
2) Detect session hijacking
Session hijacking often shows up as a valid session being used in a way that doesn’t match the original user context.
Signals of hijacking
- IP or geo changes mid-session
- User agent changes mid-session
- Device fingerprint changes mid-session
- Multiple concurrent sessions with abnormal overlap
- Session used from a datacenter/VPN after being created on residential ISP
- Session tokens reused from a different context
- Behavior change
- rapid navigation to sensitive pages
- export/download spikes
- privilege changes
- API usage that doesn’t match UI pattern
- Long-lived sessions with no re-auth in sensitive actions
- CSRF or token anomalies if you track them
Session binding checks
Bind sessions to a soft context profile:
- IP range / ASN
- device fingerprint
- browser version family
- OS family
- locale/timezone
- cookie integrity / token rotation
Don’t hard-fail on normal mobile network changes, but score deviations.
3) Use risk scoring, not just hard rules
A single signal may be noisy. Combine signals into a risk score:
- New device: +20
- New country: +30
- Proxy/VPN: +25
- Failed logins before success: +15
- Impossible travel: +50
- Sensitive action after login: +20
Then define responses:
- Low risk: allow
- Medium risk: step-up MFA
- High risk: block or require re-auth
- Critical risk: revoke all active sessions and alert security
4) Protect sessions to reduce hijacking
Detection is important, but prevention matters too:
- Use short-lived access tokens
- Rotate refresh tokens and invalidate on reuse
- Use HttpOnly, Secure, SameSite cookies
- Re-authenticate for sensitive actions
- Support session revocation
- Tie refresh tokens to device/session family
- Use MFA and phishing-resistant MFA where possible
- Consider continuous auth for admin actions
- Detect token replay and concurrent use anomalies
5) Alerting and investigation workflow
When something looks suspicious:
- Show the login/session timeline
- Compare against user baseline
- Check nearby events:
- password reset
- MFA enrollment change
- API key creation
- role change
- Revoke sessions if needed
- Force password reset / MFA re-enrollment
- Notify the user and security team
6) Practical rules to start with
If you want a starter set:
- Successful login from new geo + new device + no MFA = step-up
- Any login from known proxy/VPN + high-value account = step-up or block
- More than N failed logins across many accounts from one IP/subnet = alert
- Session context changes significantly mid-session = score for hijack
- Sensitive action from an untrusted session = re-auth required
- Refresh token reuse detected = revoke entire token family
7) Logging considerations
Make sure your logs are:
- tamper-resistant
- time-synchronized
- privacy-conscious
- rich enough to reconstruct session timelines
Avoid storing raw secrets, full tokens, or excessive personal data.
If you want, I can also help you with:
- a Sigma/SQL detection rule set
- a risk scoring model
- a reference architecture for SaaS auth monitoring
- or a sample event schema for login/session telemetry