Wildcard Next.js Image Config Can Expose Your Server to SSRF Attacks
A common but risky misconfiguration in Next.js sets the remotePatterns hostname to a wildcard, allowing any HTTPS URL to be fetched server-side through the built-in image optimization endpoint. Because the fetch originates from the server itself, attackers can exploit this to probe internal services — such as admin panels or cloud metadata endpoints — that are otherwise unreachable from the public internet. This is a classic Server-Side Request Forgery (SSRF) vulnerability, and cloud metadata endpoints like 169.254.169.254 have been targeted this way in real-world attacks to steal instance credentials. The recommended fix is to replace the wildcard with an explicit allowlist of only the trusted image hostnames your application actually uses. For apps handling user-generated content from unpredictable domains, developers are advised to validate and store image sources rather than defaulting to an open wildcard.
This is an AI-generated summary. ShortSingh links to the original source for the complete article.
Discussion (0)
Log in to join the discussion and vote.
Log in