You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[Breaking] feat(next/image)!: add support for images.dangerouslyAllowLocalIP and images.maximumRedirects (#84676)
This PR adds a two new options and sets a strict default value for each.
- `images.dangerouslyAllowLocalIP`
- `images.maximumRedirects`
### dangerouslyAllowLocalIP
In rare cases when self-hosting Next.js on a private network, you may
want to allow optimizing images from local IP addresses on the same
network.
However, this is not recommended for most users so the default is
`false`.
> [!NOTE]
> BREAKING CHANGE: This change is breaking for those who self-hosting
Next.js on a private network and want to allow optimizing images from
local IP addresses on the same network. In those cases, you can still
enable the config.
### maximumRedirects
Since are also testing redirects for local IPs, we can also reduce the
maximum number of redirects to 3 by default.
Unlike normal websites which might redirect for features like auth, its
unusual to have more than 3 redirects for an image.
In some rare cases, developers may need to increase this value or set to
`0` to disable redirects.
> [!NOTE]
> BREAKING CHANGE: This change is breaking for those who need image
optimization to follow more than 3 redirects.
Copy file name to clipboardExpand all lines: docs/01-app/03-api-reference/02-components/image.mdx
+47-1Lines changed: 47 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -804,6 +804,52 @@ module.exports = {
804
804
}
805
805
```
806
806
807
+
#### `maximumRedirects`
808
+
809
+
The default image optimization loader will follow HTTP redirects when fetching remote images up to 3 times.
810
+
811
+
```js filename="next.config.js"
812
+
module.exports= {
813
+
images: {
814
+
maximumRedirects:3,
815
+
},
816
+
}
817
+
```
818
+
819
+
You can configure the number of redirects to follow when fetching remote images. Setting the value to `0` will disable following redirects.
820
+
821
+
```js filename="next.config.js"
822
+
module.exports= {
823
+
images: {
824
+
maximumRedirects:0,
825
+
},
826
+
}
827
+
```
828
+
829
+
#### `dangerouslyAllowLocalIP`
830
+
831
+
In rare cases when self-hosting Next.js on a private network, you may want to allow optimizing images from local IP addresses on the same network. This is not recommended for most users because it could allow malicious users to access content on your internal network.
832
+
833
+
By default, the value is false.
834
+
835
+
```js filename="next.config.js"
836
+
module.exports= {
837
+
images: {
838
+
dangerouslyAllowLocalIP:false,
839
+
},
840
+
}
841
+
```
842
+
843
+
If you need to optimize remote images hosted elsewhere in your local network, you can set the value to true.
844
+
845
+
```js filename="next.config.js"
846
+
module.exports= {
847
+
images: {
848
+
dangerouslyAllowLocalIP:true,
849
+
},
850
+
}
851
+
```
852
+
807
853
#### `dangerouslyAllowSVG`
808
854
809
855
`dangerouslyAllowSVG` allows you to serve SVG images.
@@ -1284,7 +1330,7 @@ export default function Home() {
0 commit comments