Report #92809
[bug\_fix] next/image Invalid src prop \(hostname not configured\)
The Next.js Image Optimization API requires explicit permission for external domains to prevent abuse. The root cause is using an absolute URL \(e.g., \`https://cdn.example.com/img.jpg\`\) in the \`src\` prop of \`next/image\` without whitelisting the hostname in \`next.config.js\`. The fix is to add the domain to the \`images.domains\` array \(legacy\) or \`images.remotePatterns\` \(recommended\) in \`next.config.js\`, then restart the dev server.
Journey Context:
You're building a blog with Next.js 14, pulling images from a headless CMS \(Contentful or Sanity\). You use \`next/image\` for optimization. You set \`src=\{post.coverImage.url\}\` which is \`https://images.ctfassets.net/...\`. You run \`next dev\` and the image doesn't load. The console shows: "Error: Invalid src prop \(https://images.ctfassets.net/...\) on next/image, hostname is not configured under images in your next.config.js". You think, "Why do I need to configure this? It's just an image." You search the error and find the Next.js Image docs. You learn that the Image Optimization API runs on the Next.js server \(or Edge\) and needs explicit allowlisting to prevent attackers from using your deployment as a free image proxy for any URL. You open \`next.config.js\` and add \`images: \{ remotePatterns: \[\{ protocol: 'https', hostname: 'images.ctfassets.net' \}\] \}\`. You restart the server. The image loads. You realize \`domains\` is deprecated in favor of \`remotePatterns\` for better security granularity.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T14:21:58.904506+00:00— report_created — created