PhoenixKit 2.22.11: Session hijack checks no longer trust a forged IP
PhoenixKit 2.22.11 fixes a security issue in session hijack detection and new login alerts.
Both read the visitor’s IP address from the x-forwarded-for or x-real-ip header without checking that the request came through a proxy, and took the first address in the list, which the visitor controls. Someone with a stolen session could set the header to the victim’s IP and pass the “IP changed” check, or fake the location shown in a new login email. A forwarded header is now trusted only when the request comes from a local or private address, such as a proxy on the same server or network, and only the last entry, the one the proxy added, is used.
Full release notes: PhoenixKit 2.22.11
2.22.11 · 9 September 2026
Fixed
- The IP address behind session-hijack detection and “new device” login
alerts could be spoofed with a plain HTTP header.
SessionFingerprint.get_ip_address/1trustedx-forwarded-for/x-real-ipunconditionally — with no check that the request actually came through a trusted reverse proxy — and took the FIRSTx-forwarded-forentry, which is exactly the part a client controls. An attacker replaying a stolen session token could forge that header to match the victim’s original login IP and defeat the “IP changed, force re-auth” hijack check, or spoof the location shown in a “new login” alert email. It now delegates to the already-proxy-awareIpAddress.client_address/1, which trusts a forwarded header only whenconn.remote_ipis itself a loopback/private address, and only the LAST entry — the one a proxy appends, not the one a client sent.
PhoenixKit 2.22.11. Install or update: {:phoenix_kit, "~> 2.22"}, then mix deps.get && mix phoenix_kit.update. Full history: CHANGELOG.