How WhatsApp Web Gets Your Chats (and why it’s secure — mostly)

When you open WhatsApp Web and scan the QR, it looks like “all my chats just appear.” But WhatsApp does not stream your entire history from a server archive. Instead it uses a short, deliberate sequence of steps designed for three goals:

  • Security: keep messages end-to-end encrypted (E2E) so only devices can read them.

  • Usability: give the web client immediate context (recent messages) after linking.

  • Availability: let multiple devices receive messages independently (so your web client works even if the phone is offline later).

This article explains what happens, why each step exists, and how it is implemented, with references to WhatsApp’s public documentation and engineering posts.


TL;DR (short flow)

  1. Scan QR → establish an E2E session (handshake).

  2. Phone sends an encrypted chat bundle (recent history) to the browser.

  3. Browser stores that history locally (IndexedDB) and reads from it.

  4. New messages are delivered to each device via per-device encrypted copies (client-fanout).

  5. The server only keeps undelivered ciphertext temporarily (deleted after a retention window). [^ref1][^ref2]


Purpose:

  • Prove the new Web client is authorized by the account owner.

  • Create a secure (E2E) channel between phone ↔ browser so sensitive data can be transferred safely.

High-level chronology (what is sent, in order):

  1. Browser generates an ephemeral key pair (private + public) and displays the public value inside the QR code.

    • Why ephemeral? So every link attempt is unique and cannot be replayed later.
  2. You scan the QR with your phone. The phone obtains the browser’s ephemeral public key.

  3. Phone generates its ephemeral DH (Diffie–Hellman) public value and uses a DH computation (with the browser’s ephemeral public) to derive a shared secret. The browser does the same using its ephemeral private and the phone’s ephemeral public. The math makes both sides compute the same secret.

    • Why DH? To let two parties agree a secret key without anyone in the middle learning it. [Diffie–Hellman = a way to derive a mutual secret from each side’s private value and the other side’s public value.]
  4. Identity verification: the phone signs (cryptographically) a message that includes its ephemeral public value and the browser’s ephemeral public value, using the phone’s long-term identity private key. The browser verifies this signature with the phone’s identity public key (which it fetches from the directory/servers).

    • Why sign X_phone || X_web? This binds the ephemeral DH exchange to the phone’s identity — it proves the DH value came from the legitimate phone and is meant for this specific browser instance. Without this signature an attacker could replay or inject values.
  5. Secure channel established. The derived shared secret is used to encrypt subsequent messages for the session.

References & context: WhatsApp’s multi-device design and linking flow are described in their engineering posts. The multi-device change makes each companion device (web, desktop, extra phones) a first-class endpoint. [^ref1]


2) Why the phone sends a separately encrypted chat bundle (and how)

Purpose:

  • Give the newly linked Web client immediate usable context (recent messages) instead of a blank UI.

  • Do this without exposing long-term keys or making older history permanently available to the server.

Mechanism (how):

  1. Phone takes a batch of recent messages and packages them into a bundle (bulk data).

  2. The phone encrypts that bundle with a fresh, one-time symmetric key (fast and suitable for large data).

  3. Over the E2E channel established by DH, the phone sends:

    • The encrypted bundle (the “locked box”), and

    • The one-time symmetric key that unlocks that box.

  4. The browser decrypts the bundle, imports messages into its local store, and the temporary key is deleted.

Why not just send messages directly over the session without the extra symmetric key?

  • The extra symmetric key creates separation of concerns and better security hygiene: the initial heavy transfer is an atomic operation protected by a dedicated ephemeral key that is discarded after bootstrapping. Even if session keys are compromised later, the initial bundle remains protected if its one-time key is securely deleted. This is standard practice for bootstrapping large encrypted transfers.

WhatsApp’s multi-device implementation explicitly transfers recent chat history to companion devices when linking; the engineering blog and analyses describe this “bootstrap bundle” approach. [^ref1]


3) Where the web client stores chats (local storage) — practical reality

What actually stores the data: WhatsApp Web keeps its message copy in the browser (IndexedDB). That local database is what the web UI reads when you scroll back through messages. If you clear browser storage or sign out, that local copy is gone. Community analysis and forensic explorations confirm WhatsApp Web’s use of browser storage for message data. [^ref3][^ref4]

Important consequence: If the initial bundle did not include very old messages, the web client cannot show them unless the phone is online and re-sends them; there is no central, plaintext archive to fetch older history from.


4) After linking: how new messages arrive (client-fanout)

Purpose: Avoid making the phone a single point of failure and let every device receive new messages independently while preserving E2E guarantees.

Mechanism (how):

  • When someone sends you a message, the sender’s app encrypts separate ciphertexts for each of your registered devices (phone, web, desktop, etc.) — i.e., per-device encryption (“client-fanout”). The server relays the appropriate ciphertext to each device. Each device decrypts with its own key and stores the message locally. The server never sees plaintext.

  • The server keeps undelivered encrypted copies temporarily while attempting delivery; policy/FAQ states that undelivered messages are retained (in encrypted form) for a limited period (deleted after a retention window, e.g., up to 30 days in their policy) and then removed if undelivered. [^ref2][^ref1]

Why this design:

  • Resilience: web/desktop can receive messages even if phone is offline (once they are linked).

  • Privacy: no central plaintext store; each ciphertext is targeted to a device.


5) Fingerprints / safety numbers and impersonation detection

What is a fingerprint (safety number)?

  • A short, human-readable hash (or QR) computed from the pair of identity public keys used in a chat. It’s a compact representation users can compare to detect whether both sides agree on each other’s identity keys. (Think: hash(my_pub || their_pub)). [^ref5]

How it helps detect impersonation:

  • If a server (or attacker) swaps someone’s public key in the directory, the fingerprint derived by peers changes. If two users manually compare safety numbers and they differ, it indicates a mismatch (possible MITM or legitimate key change). Manual verification is the gold standard for confirming there was no tampering.

What WhatsApp does to make this easier / safer:

  • WhatsApp exposes the safety number in the chat’s Encryption screen (60 digits + QR) so users can compare or scan to verify. It also optionally notifies users when a contact’s security code changes (you can enable “Show security notifications” on devices). [^ref6][^ref5]

6) Can WhatsApp server silently impersonate you? What prevents that?

The raw risk:
If clients blindly trust the server’s key directory, the server could replace a user’s public identity key with a fake key and act as a man-in-the-middle. That would let the server (or an attacker with server control) impersonate the user — UNLESS the change is detected.

WhatsApp’s mitigations:

  1. Safety numbers: contacts get a visible warning when a contact’s key changes and can re-verify by scanning/comparing codes. That makes impersonation detectable if users perform verification. [^ref5]

  2. Key transparency (Auditable Key Directory — AKD): WhatsApp has published an implementation of an Auditable Key Directory and has rolled out a key-transparency system so clients can automatically verify that the directory returned correct public keys and also obtain cryptographic proofs (append-only, auditable structure). This reduces the ability of a malicious server to hide a key swap without detection by auditors or clients that check proofs. [^ref7][^ref8]

Important practical point (as of current design):

  • When a user reinstalls or switches phones and thus legitimately generates a new identity key, that user (the one who changed keys) typically does not receive a “your key changed” alert — their app simply has a new local key (they caused it). Instead, their contacts see “(Contact)’s security code has changed.” This means detection of server-side key replacement largely depends on contacts noticing the change and re-verifying, unless the client actively performs and surfaces AKD verification results for the user. WhatsApp’s AKD work aims to provide automatic verification under the hood, but user-facing verification (manual comparison of safety numbers) still exists and is the simple human check. [^ref6][^ref8]

7) Practical consequences & recommendations

  • If you care about strong non-repudiation of identity (journalists, activists, sensitive comms): verify safety numbers with important contacts after linking or when you see a “security code changed” notice. Manual verification remains the only user action that definitively rules out a tampering attack. [^ref5]

  • If you sign out of Web or clear browser storage, the local IndexedDB copy is gone. Re-linking will require a new initial bundle transfer from your phone (if the phone still has history or backup). [^ref3]

  • The server’s retention policy for undelivered ciphertext is limited — WhatsApp documents that undelivered messages are stored (encrypted) only for a bounded window. That means the server does act as a temporary relay but not a long-term plaintext archive. [^ref2]


Appendix — definitions (short)

  • E2E (end-to-end encryption): Only endpoints (your devices), not the server, can decrypt message plaintext.

  • Diffie–Hellman (DH): A math way for two parties to derive a shared secret from each side’s private value and the other side’s public value without exposing the private values.

  • Ephemeral key: A short-lived key used for a single session or handshake.

  • Identity key pair: Long-term public/private key pair that identifies a device. Private key never leaves the device; public key is shared.

  • Signature: Cryptographic proof produced with a private key that anyone with the corresponding public key can verify — used to prove ownership of the private key.

  • Fingerprint / safety number: A short human-readable hash of the pair of identity public keys used for manual verification.

  • IndexedDB: Browser local database used by WhatsApp Web to persist message copies locally.


References

References

[^ref1]: How WhatsApp Enables Multi-Device Capability — WhatsApp Engineering Blog, July 14, 2021.
(https://engineering.fb.com/2021/07/14/security/whatsapp-multi-device/)

[^ref2]: WhatsApp Privacy Policy (Europe), message retention details (undelivered messages kept encrypted for a limited time).
(https://www.whatsapp.com/legal/privacy-policy-eea)

[^ref3]: Community analysis on Reddit about WhatsApp Web storing messages in browser storage.
(https://www.reddit.com/r/whatsapp/comments/10srktx/why_does_whatsapp_web_know_to_load_my_messages/)

[^ref4]: Forensic examination of WhatsApp browser behavior (e.g. IndexedDB usage).
(https://mazzo.li/posts/whatsapp-backup.html)

[^ref5]: WhatsApp Help Center — Security code / Encryption section (explains safety numbers and how to verify them).
(https://faq.whatsapp.com/1524220618005378)

[^ref6]: WhatsApp Help Center — Show security code notifications explanation.
(https://faq.whatsapp.com/1524220619047167)

[^ref7]: Deploying Key Transparency at WhatsApp — WhatsApp Engineering Blog, April 13, 2023.
(https://engineering.fb.com/2023/04/13/security/whatsapp-key-transparency/)

[^ref8]: WhatsApp and Cloudflare Enhance Security by Auditing Key Transparency — WABetaInfo (summarizing cloud audit of AKD).
(https://wabetainfo.com/whatsapp-and-cloudflare-enhance-security-by-auditing-key-transparency-for-end-to-end-encrypted-messages/)

[^ref9]: AKD (Auditable Key Directory) open-source implementation and audit: GitHub repository with examples and audit details.
(https://github.com/facebook/akd)

[^ref10]: Cloudflare helps verify the security of end-to-end encrypted messages by auditing key transparency for WhatsApp.
(https://blog.cloudflare.com/key-transparency/)

0
Subscribe to my newsletter

Read articles from Krishna Kumar Mahto directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Krishna Kumar Mahto
Krishna Kumar Mahto

Software Engineer - Backend