Prevent DNS Rebinding in Symfony: Secure Your App

🔐 What Is a DNS Rebinding Attack? DNS rebinding exploits browser DNS resolution, letting attackers point a trusted domain to internal IPs—bypassing same-origin policies to penetrate private networks. Common real-world threats include targeting IoT devices, admin dashboards, or local APIs that don't validate the Host header. ✅ Why Symfony Apps Should Care Symfony apps often serve APIs or admin pages trusted by *.myapp.com . An attacker could rebind evil.com to 192.168.0.10 (your internal API) and trick a browser into making authenticated requests. Without proper checks, your app treats these as legitimate. 😱 🛡️ Defense #1: Hostname Whitelisting via Middleware Use a Symfony HTTP middleware to validate incoming Host headers: // src/EventListener/HostValidationListener.php namespace App\EventListener; use Symfony\Component\HttpKernel\Event\RequestEvent; use Symfony\Component\HttpFoundation\Response; class HostValidationListener { private array $allowedHosts; ...