Problem Statement: Mid-Session Identity Change Is the Attack Surface
Frames session hijacking detection as a real-time comparison problem between a session's established baseline and each incoming request.
Problem statement
Design a session hijacking detection system that continuously validates whether the entity holding a session is still the entity that earned it. Authentication proves identity once, at login. A session credential then carries that proof forward for hours or days. Session hijacking is the class of attacks where that credential is stolen, copied, or replayed, and an attacker rides the session without ever defeating the login flow. The detection system must observe the attributes every request carries — source IP, user-agent, device fingerprint, geolocation, request cadence — compare them against the session's own baseline, score the divergence, and trigger a graduated response: allow, flag, step-up challenge, partial revocation, or full termination.
The brief pins four capabilities: a session store linked to device and agent data (FR1), a real-time comparison on each request (FR2), a re-auth challenge path when the mismatch is significant (FR3), and thresholds that tolerate mild legitimate change such as a mobile network handoff (FR4). The non-functional side demands that the per-request check add only a few milliseconds (NFR1), scale to high concurrency (NFR2), keep false positives on genuine IP or device change rare (NFR3), and emit observable anomaly records (NFR4).
Why this problem is distinctive
Most interview designs treat the request path as stateless: authorize, serve, log. Session hijacking detection inserts a stateful trust-continuity check into the hot path of every single request, without being allowed to slow that path down. Three properties make it distinctive:
- The baseline drifts legitimately. A user moves from home Wi-Fi to cellular, the IP changes by a whole /16, and the user-agent gains a minor version. None of this is malicious. The system must distinguish drift from theft, which is a precision problem, not just a lookup problem.
- The adversary is authenticated. A hijacked session passes every token check. Signature, expiry, audience — all valid. The only evidence is behavioral and contextual, which means detection is statistical and every threshold is a business trade-off between missed takeovers and insulted users.
- Latency is non-negotiable. The check sits in front of application logic for protected routes. A detection system that adds 200 ms to every request will be switched off by the product team within a quarter.
Threat categories in scope
We name threats as categories and design detectors for their observable signals; we do not document attack methods.
- THREAT_TOKEN_REPLAY — a valid session credential presented from an environment inconsistent with the one that established it. Signal: credential valid, context divergent.
- THREAT_COOKIE_THEFT — the session bearer extracted from a device and reused elsewhere. Signal: identical cookie, new device fingerprint appearing mid-session.
- THREAT_SESSION_FIXATION — an attacker-influenced session id later authenticated by the victim. Signal: pre-login and post-login context fingerprints disagree.
- THREAT_CONCURRENT_LOCATION — the same session used from two distant networks within a physically impossible window. Signal: impossible-travel velocity between consecutive requests.
- THREAT_CREDENTIAL_STUFFING_AFTERMATH — takeover that follows a leaked-password event. Signal: login from a new region followed by sensitive-action burst.
The four planes
- Collection plane — edge and application middleware emit normalized session-context events (IP, ASN, user-agent, fingerprint hashes, route class).
- Evaluation plane — a low-latency risk engine compares each request against the session baseline and device profile, producing allow / flag / challenge / revoke.
- Decision & enforcement plane — policy maps scores and signals to actions; revocation propagates to caches, edge, and the identity provider.
- Learning plane — async streams feed model training, threshold tuning, evidence retention, and SOC review.
A strong answer keeps the planes separate: the evaluation plane must degrade gracefully without breaking login, and the learning plane must never sit in the synchronous path.
Key Highlights
- •Authentication is a one-time proof; session hijacking detection is continuous proof, comparing each request to the session baseline.
- •A hijacked session passes all cryptographic checks — the only discriminating evidence is contextual: IP, agent, fingerprint, velocity, cadence.
- •The inline check must stay under a 5 ms p99 budget; everything heavier is pushed to the async plane.
- •Baseline drift is legitimate (Wi-Fi to cellular), so precision is a threshold-and-evidence problem, not a pattern-match problem.
- •Four planes: collection, evaluation, decision/enforcement, learning — synchronous safety only in the first two.
Section Rescue Kit
Buzzwords to use:
Safe statements:
- "Let me separate what authentication proves once from what this system must prove on every request."
- "Before choosing components, I will define which comparisons are synchronous in the request path and which are async."