Nuxt & Universal SSR (50 Qs)•Part 3: Advanced Internals, Performance & Production (Senior / Staff)
How do you prevent Server-Side Request Forgery (SSRF) in Nuxt Nitro routes?
senior LevelFormsPerformanceSSR & Hydration
In Simple Words:
When a Nitro server route fetches external URLs based on user input (e.g. generating link previews, webhooks), attackers can pass internal private IP addresses (http://169.254.169.254 or http://localhost:5432) to steal cloud credentials or query local databases.
Defense Strategies:
- URL Whitelisting: Strict protocol check (
https:only) and allowlist of trusted external hostnames. - DNS Resolution & Private IP Blacklisting: Resolve the DNS first and block private subnet CIDRs (
10.0.0.0/8,172.16.0.0/12,192.168.0.0/16,127.0.0.1/8). - Disable Redirects: Prevent the HTTP client from following redirects to private internal subnets.