Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Image optimizer rejects requests for remote images with _next/image in the URL (v14.2.7) #69456

Closed
igordanchenko opened this issue Aug 29, 2024 · 1 comment · Fixed by #69586
Labels
bug Issue was opened via the bug report template. Image (next/image) Related to Next.js Image Optimization. locked

Comments

@igordanchenko
Copy link

igordanchenko commented Aug 29, 2024

Link to the code that reproduces this issue

https://stackblitz.com/edit/nextjs-14-2-7-image-bug?file=app%2Fpage.tsx

To Reproduce

  1. Download the sandbox - https://stackblitz.com/edit/nextjs-14-2-7-image-bug?file=app%2Fpage.tsx
  2. npm install && npm run dev
  3. Open http://localhost:3000
  4. Observe the broken image

Current vs. Expected behavior

Image optimizer in v14.2.7 rejects image requests for remote images that contain _next/image in the URL path.

Scenario:

  1. Next.js app uses images coming from external CMS (the images are hosted on 3rd-party domains)
  2. Some of the remote images just happen to be sourced from 3rd-party domains that also use Next.js and thus contain _next/image in their URL path
  3. Starting with v14.2.7 image optimizer rejects image requests for such remote images

As far as I can tell, this change comes from #68628

While I understand the need to avoid recursive image optimizer calls within the same app, the current implementation seems overly restrictive. Image optimizer should not reject requests for remote images specified in the remotePatterns as the app doesn't have control over what images are coming from an external CMS.

Provide environment information

Operating System:
  Platform: darwin
  Arch: x64
  Version: Darwin Kernel Version 23.5.0: Wed May  1 20:09:52 PDT 2024; root:xnu-10063.121.3~5/RELEASE_X86_64
  Available memory (MB): 32768
  Available CPU cores: 12
Binaries:
  Node: 20.16.0
  npm: 10.8.1
  Yarn: N/A
  pnpm: N/A
Relevant Packages:
  next: 14.2.7 // Latest available version is detected (14.2.7).
  eslint-config-next: N/A
  react: 18.3.1
  react-dom: 18.3.1
  typescript: 5.5.4
Next.js Config:
  output: N/A

Which area(s) are affected? (Select all that apply)

Image (next/image)

Which stage(s) are affected? (Select all that apply)

next dev (local), next start (local)

Additional context

No response

@igordanchenko igordanchenko added the bug Issue was opened via the bug report template. label Aug 29, 2024
@github-actions github-actions bot added the Image (next/image) Related to Next.js Image Optimization. label Aug 29, 2024
@huozhi huozhi closed this as completed Aug 29, 2024
@huozhi huozhi reopened this Aug 29, 2024
styfle added a commit that referenced this issue Sep 3, 2024
…a Image component (#69586)

### What?
Fixes #69456 which describes an issue with `next/image` component, where
an external image containing `_next/image` in the URL fails with the
error `"url" parameter cannot be recursive`.

### Why?
The `next/image` component should be able to render images from
configured hostnames without doing the recursive check.

### How?
Before checking for the existence of `_next/image` substring in the
image's path, we can simply check if the image is an external URL that
comes from a preconfigured host in the `next.config.js` file.

Example:
<img width="1207" alt="image"
src="https:/user-attachments/assets/8d5c99cf-f050-40a9-b5a4-ba961b83f037">

---------

Co-authored-by: Steven <[email protected]>
lubieowoce pushed a commit that referenced this issue Sep 4, 2024
…a Image component (#69586)

### What?
Fixes #69456 which describes an issue with `next/image` component, where
an external image containing `_next/image` in the URL fails with the
error `"url" parameter cannot be recursive`.

### Why?
The `next/image` component should be able to render images from
configured hostnames without doing the recursive check.

### How?
Before checking for the existence of `_next/image` substring in the
image's path, we can simply check if the image is an external URL that
comes from a preconfigured host in the `next.config.js` file.

Example:
<img width="1207" alt="image"
src="https:/user-attachments/assets/8d5c99cf-f050-40a9-b5a4-ba961b83f037">

---------

Co-authored-by: Steven <[email protected]>
Copy link
Contributor

This closed issue has been automatically locked because it had no new activity for 2 weeks. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 18, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Issue was opened via the bug report template. Image (next/image) Related to Next.js Image Optimization. locked
Projects
None yet
2 participants