What Is a Man-in-the-Middle (MITM) Attack?
A man-in-the-middle attack occurs when an attacker secretly intercepts (and potentially alters) communication between two parties who believe they're communi...
Published November 16, 2026
A man-in-the-middle (MITM) attack is when an attacker secretly sits between two parties and reads or alters their traffic. HTTPS with valid certificates is the main defence.
The concept
Typical setups: rogue Wi-Fi hotspots, ARP or DNS spoofing and compromised routers redirect traffic through the attacker.
TLS encrypts traffic and certificates prove the server's identity, so an attacker cannot read or modify data without triggering a certificate warning.
Attacker in the path
Practical examples
Force HTTPS (HSTS)
Strict-Transport-Security: max-age=31536000; includeSubDomains; preloadPin or verify certificates in code
const agent = new https.Agent({ rejectUnauthorized: true }) // never set false in productionCheck the certificate
openssl s_client -connect example.com:443 -servername example.com </dev/null | openssl x509 -noout -issuer -subjectCommon mistakes
- Ignoring certificate warnings.
- Disabling TLS verification in code ('works on my machine').
- Using public Wi-Fi without a VPN or HTTPS.
Key takeaways
- Attacker relays and reads traffic.
- TLS + valid certs defeat it.
- Never disable verification.
FAQ
Does HTTPS fully prevent MITM?
Yes if certificates are validated and the endpoint is trusted.
What is SSL stripping?
Downgrading a user to HTTP; HSTS prevents it.