A man-in-the-middle (MITM) attack is an attack in which an adversary positions themselves between two communicating parties to intercept and possibly alter the data passing between them. A proxy relays traffic between a client and a server by design, so the proxy operator's trustworthiness and whether the traffic is encrypted decide how much of that traffic can be read.

OWASP also calls this a manipulator-in-the-middle attack. The attacker splits one connection into two, one to the client and one to the server, and can then read, insert and modify data. Over plain HTTP, headers travel in cleartext, so a session cookie can be read from them.

MITM Risk in the Proxy Context

  • Plain HTTP: Anything between you and the site, including a proxy, can see the request and response content.
  • HTTPS through CONNECT: The client asks the proxy to open a tunnel, and the proxy blindly forwards data in both directions. The TLS session runs end to end between client and site.
  • TLS interception: Tools such as mitmproxy decrypt HTTPS by creating a certificate for each site, signed by their own certificate authority. Clients accept these only if they trust that authority.
  • Warnings: Browsers warn when a certificate is untrusted or invalid. OWASP notes users may ignore these warnings.

Reducing MITM Risk

  • Use HTTPS: Send scraping and login traffic over HTTPS, not plain HTTP.
  • Keep certificate checks on: Do not disable TLS verification in scraping code, and do not install root certificates you do not control.
  • HSTS: The Strict-Transport-Security header makes browsers upgrade a site to HTTPS and blocks click-through on certificate errors. It does not protect the first visit unless the site is preloaded.
  • Pinning: Apps that pin certificates reject interception certificates like mitmproxy's.

Common MITM Techniques

  • Rogue Wi-Fi: The attacker sets up a wireless access point in a public place, such as a cafe or airport. Anyone who connects can have all browser traffic read and modified.
  • ARP spoofing: The attacker tricks the victim into accepting the attacker's MAC address as the real router address.
  • DNS spoofing: The attacker redirects the victim to a fake website.
  • IP address spoofing: The attacker makes the victim believe they are talking to a legitimate server.