Skip to content

next/image: improve error message and support images.dangerouslyAllowLocalIP for private-IP rejections #1065

@github-actions

Description

@github-actions

Upstream change

Next.js commit 5452439f3db2a78967178ca4180b27fb48393a19 (PR #91686) updates the SSRF guard in fetchExternalImage to:

  1. Log a clearer error when an upstream image hostname resolves to a private IP, including a hint about images.dangerouslyAllowLocalIP.
  2. Document that dangerouslyAllowLocalIP may be needed when hosting in a VPC with split-horizon DNS, while warning about the SSRF risk.

Relevant change in packages/next/src/server/image-optimizer.ts:

   Log.error(
     'upstream image',
     href,
-    'resolved to private ip',
-    JSON.stringify(privateIps)
+    'hostname resolved to private IP',
+    JSON.stringify(privateIps),
+    'If this is expected and you understand SSRF risk, use images.dangerouslyAllowLocalIP = true to continue.'
   )
   throw new ImageError(400, '"url" parameter is not allowed')

A new unit test (test/unit/image-optimizer/fetch-external-image.test.ts) confirms:

  • Private IP hostnames are rejected with 400 and a generic "url" parameter is not allowed message.
  • dangerouslyAllowLocalIP: true allows the fetch to proceed.

Why this matters for vinext

vinext does not currently ship a full Next.js-compatible image optimizer (image handling on Cloudflare typically defers to Cloudflare Images / the platform). However, to the extent that vinext provides any next/image runtime or honors images.* config:

  • The SSRF guard for upstream image fetches should be in place for parity.
  • The images.dangerouslyAllowLocalIP config option (and its behavior) should be supported or explicitly documented as not applicable.
  • Error messages emitted on rejection should match Next.js for ecosystem compatibility.

This is a low-priority parity item — most Cloudflare deployments will rely on the platform's image pipeline rather than vinext's own optimizer.

Action items

  • Confirm vinext's current next/image story (built-in optimizer vs. delegate to platform).
  • If vinext fetches external images at runtime, port the private-IP guard and the images.dangerouslyAllowLocalIP opt-out.
  • Match the updated error/log message for ecosystem parity.
  • Document the behavior in vinext docs (especially for VPC / split-horizon DNS scenarios).

References

Metadata

Metadata

Assignees

No one assigned

    Labels

    nextjs-trackingTracking issue for a Next.js canary change relevant to vinext

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions