Man-in-the-Middle Attacks
Learn how an interceptor can sit between you and a website, what HTTPS stops and which warnings you should never skip.
Key takeaways
- A man-in-the-middle needs two things: a position on the path, and a way to defeat or sidestep encryption and identity checks.
- HTTPS with a valid certificate protects the content of your connection from people on the network between you and the site.
- Certificate warnings on a site that normally works are a reason to stop, change networks and investigate.
- Phishing sites that relay logins in real time can defeat one-time codes, while passkeys and security keys resist them.
- Updating your router, using trusted networks and never installing unknown certificates close most remaining gaps.
A man-in-the-middle attack happens when someone places themselves between two parties who think they are talking directly, so they can read, block or change what passes. You may also see it called an adversary-in-the-middle or on-path attack.
On today's web, HTTPS defeats most simple versions: an interceptor sees scrambled data and cannot impersonate a site without a certificate your device trusts. The successful attacks mostly go around that protection, by getting you to ignore a warning, install something, or visit a look-alike site that relays everything to the real one.
The idea in one picture
Normally your browser and a server agree on encryption keys and the server proves who it is. An interceptor wants to make two separate conversations look like one: you to the attacker, and the attacker to the server, passing messages along.
Getting into the middle
The first requirement is a position on the route. Common ways, described at a level useful for defense, include:
- Shared local networks. On a LAN, devices find each other using the Address Resolution Protocol (ARP) for IPv4, which trusts replies it receives. A hostile device on the same network can mislead others about where the router is. Managed switches offer protections against this.
- Rogue or "evil twin" Wi-Fi. An access point copies the name of a café or airport network and waits for devices to join.
- A compromised router. Whoever controls it sees all traffic that passes and can change which DNS servers your devices use.
- DNS tampering. If you get the wrong address for a name, you connect to the wrong machine.
- Routing problems on the internet itself. Mistaken or malicious BGP announcements can divert traffic between networks.
- Software on your device. Malware or an unwanted program can act as a local proxy, and a malicious browser extension can read pages after they are decrypted.
Position alone is not enough against well-encrypted traffic. It lets an interceptor see which addresses you contact and often which site names, and block or delay them, but not read or alter protected content.
What HTTPS and TLS actually protect
HTTPS runs web traffic inside TLS (Transport Layer Security). During the TLS handshake, the server presents a certificate that binds its domain name to a public key, signed by a certificate authority your device already trusts, and proves it holds the matching private key. Both sides then derive fresh session keys. The result gives you confidentiality, integrity and server identity. How certificates work goes into the trust chain.
The limits matter. The padlock or secure indicator confirms a protected connection to the name in the address bar. It doesn't confirm that the name belongs to the company you think, or that the company is honest. And anything on your own device that sees data before encryption or after decryption is outside TLS's reach.
Attacks that sidestep encryption
Downgrading to plain HTTP. If your first request to a site is unencrypted, an interceptor may keep you on HTTP while talking HTTPS to the server. HSTS (HTTP Strict Transport Security) lets a site tell browsers to use HTTPS only, and browser preload lists cover the first visit for participating domains. See HSTS explained. Browser HTTPS-only modes help for other sites.
Ignored warnings. A person who clicks through a certificate error hands the interceptor exactly what was missing.
Rogue root certificates. If someone installs their own certificate authority on your device, they can create certificates your browser accepts. Employers and schools sometimes do this openly to inspect traffic on managed devices. Some security software does too. A request from a website or unknown app to install a certificate or profile deserves a firm no.
Relay phishing. You are lured to a look-alike domain with its own valid certificate. The fake site forwards your password and one-time code to the real service and captures the resulting session cookie. Nothing about TLS is broken; you connected to the wrong name. Detecting fake login pages covers the tells.
Reading the warnings
Not every certificate error is an attack. A wrong device clock, an expired certificate, a captive portal (the sign-in page on hotel Wi-Fi) or a misconfigured site can all trigger one. The guide to certificate errors explains the common messages.
A practical rule: if a site that matters suddenly shows a certificate warning, don't proceed and don't type anything. Check the clock. If you are on public Wi-Fi, complete the network's sign-in page using an ordinary, non-sensitive page, or switch to mobile data. If the warning persists on a second network, it is probably the site's problem; if it disappears, distrust the first network.
SSH has its own version. A message saying a server's host key has changed may mean a rebuilt server or an interceptor. Confirm the new fingerprint through another channel before accepting it.
Defenses you can set up
- Keep devices, browsers and your router updated.
- Secure your home network with WPA2 or WPA3, a strong Wi-Fi passphrase and a changed router administrator password.
- Check the domain before signing in, and use bookmarks or your password manager, which won't autofill on the wrong domain.
- Use passkeys or security keys where offered. Their sign-in is tied to the real site's domain, so a relay on another domain gets nothing usable.
- Turn on HTTPS-only mode in your browser.
- Forget public networks you no longer use and disable automatic joining. Public Wi-Fi risks today puts the danger in proportion.
- Use a VPN when the local network is untrusted. It shields traffic from that network and moves the trust to the VPN provider. What a VPN does and doesn't do explains the limits.
- Audit installed certificates, profiles and extensions if you suspect tampering.
For people who run websites and networks
Serve everything over HTTPS, redirect HTTP, and add HSTS once you are sure all subdomains support it. Mark session cookies Secure and HttpOnly. Automate certificate renewal and monitor certificate transparency logs for certificates you didn't request. Don't ship apps that disable certificate checking, a shortcut that sometimes survives from testing into production.
On local networks, enable the switch features that restrict rogue DHCP servers and forged ARP replies, use WPA2 or WPA3 Enterprise where it fits, and keep management interfaces on a separate segment. For email between servers, standards such as MTA-STS let a domain require encrypted delivery.
Beyond the web browser
Browsers are strict about certificates and show warnings people can see. Other software varies.
Mobile and desktop apps usually rely on the system's trusted certificates, and some add certificate pinning, accepting only particular keys for their own servers. A badly written app might skip validation entirely, and you may have no way to tell. Keeping apps updated and deleting abandoned ones is the practical response.
Email between your device and your provider should use TLS. Check that account settings say SSL/TLS or STARTTLS and that your client doesn't fall back to an unencrypted connection. Encryption between mail servers protects each hop, but the providers themselves can still read messages unless the content is end-to-end encrypted.
Messaging apps with end-to-end encryption face their own version of the problem: how do you know the key belongs to your contact? Many offer a safety number or key fingerprint you can compare in person, and warn when it changes. A change usually means a new phone, but for a sensitive conversation it is worth confirming.
Payments and instructions by message invite a human form of interception. Someone who has taken over a mailbox can sit in a thread and alter bank details at the right moment. No network encryption helps, because the attacker is inside an account. Confirm any change of payment details by calling a number you already had.
Updates and downloads should arrive over HTTPS and be signed, so that a tampered file is rejected even if the connection was diverted. Don't override a failed signature check just to finish an installation.
If you think you were intercepted
Leave the network. From a trusted connection and device, change the passwords for anything you signed in to, sign out all sessions and review account activity. Remove unfamiliar certificates or configuration profiles, check browser proxy settings and extensions, and scan for malware. If your home router is suspect, reset it, update its firmware and set it up again. For a work system, report it to your security team with the time and network involved.