Allow a wildcard for images.domains in next.config.js / ability to disable Next/Image hostname check #18429
Replies: 13 comments 22 replies
-
I like the idea but I red in the PR the worries about Ddosing which of course is a real issue if you allow any domain. |
Beta Was this translation helpful? Give feedback.
-
This is from docs. I do like the reason behind this because it can easily be abused in many ways which would not benefit anyone, especially to the NextJS team. |
Beta Was this translation helpful? Give feedback.
-
Was the issue opened? Many providers have a dynamic subdomain, also social networks images requested by API |
Beta Was this translation helpful? Give feedback.
-
Agreed with @pronevich. Facebook for example has several subdomains all of which on the |
Beta Was this translation helpful? Give feedback.
-
Do we have any updates on this issue? I'm using cloudfront which changes subdomains pretty often, thus making Image unusable to me :( |
Beta Was this translation helpful? Give feedback.
-
This could work #27345 |
Beta Was this translation helpful? Give feedback.
-
Hi, I was also battling with this and managed to make a workaround to this issue by creating an image proxy. It is open-sourced & on npm, you can check the source here https://github.com/Blazity/next-image-proxy // pages/api/imageProxy.ts
import { withImageProxy } from '@blazity/next-image-proxy'
export default withImageProxy({ whitelistedPatterns: [/^https?:\/\/(.*).medium.com/] }) import NextImage from 'next/image'
export function SomeComponent() {
const actualImageUrl = 'https://cdn-images-1.medium.com/max/1024/1*xYoAR2XRmoCmC9SONuTb-Q.png'
return <NextImage src={`/api/imageProxy?imageUrl=${actualImageUrl}`} width={700} height={300} />
} |
Beta Was this translation helpful? Give feedback.
-
The problem comes that image is like a separate api request, with url parameters. With this approach, it would be security hole if we allow wildcard domains. The image component is fundamentally made wrong. It shouldn’t be an api request to a hidden |
Beta Was this translation helpful? Give feedback.
-
Any movement on this? With CDN's a plenty, I can't see why we shouldn't be able to use a wildcard for a subdomain, for example, instagram's cdn. |
Beta Was this translation helpful? Give feedback.
-
I see this has been open for 2 years already. I'm surprised that there aren't more replies on this. |
Beta Was this translation helpful? Give feedback.
-
This feature is available on the canary channel Update 1: this feature shipped in Next.js 12.2.0 Update 2: this feature is stable in Next.js 12.3.0 |
Beta Was this translation helpful? Give feedback.
-
Image is a terrible component. Use img tag instead. |
Beta Was this translation helpful? Give feedback.
-
The improvements in Here is the problem: e.g. Is there a way to load images of different domains, other than going for unoptimized |
Beta Was this translation helpful? Give feedback.
-
Feature request
A. The ability to use a wildcard or regular expression in the images.domains array within the next.config.js.
B. The ability to disable the hostname check when using Next/Image.
Is your feature request related to a problem? Please describe.
I'm trying to implement Next/Image in my current project with externally hosted images. My images are hosted on an external server which regularly changes hostnames to a random subdomain (e.g. s1-abc-def.domain.com). This makes it nearly impossible for me to use Next/Image with the current way hostnames are validated.
Describe the solution you'd like
A. It looks like the Next/Image component uses
Array.includes
to match the hostname of an image with the configured domains array in the next.config.js. It would be great if the ability to use a wildcard (e.g. *.domain.com) or regex could be added.B. A new parameter in the next.config.js which allows you to disable the domains check for images.
Describe alternatives you've considered
Additional context
N/A
Beta Was this translation helpful? Give feedback.
All reactions