Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
N
next.js
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Alex
next.js
Commits
5452439f
Unverified
Commit
5452439f
authored
May 04, 2026
by
Rishi
Committed by
GitHub
May 04, 2026
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix(next/image): Improve error message for private IP (SSRF) rejections (#91686)
Co-authored-by:
Steven
<
steven@ceriously.com
>
parent
07f76411
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
55 additions
and
2 deletions
+55
-2
version-16.mdx
docs/01-app/02-guides/upgrading/version-16.mdx
+2
-0
image.mdx
docs/01-app/03-api-reference/02-components/image.mdx
+2
-0
image-optimizer.ts
packages/next/src/server/image-optimizer.ts
+3
-2
fetch-external-image.test.ts
test/unit/image-optimizer/fetch-external-image.test.ts
+48
-0
No files found.
docs/01-app/02-guides/upgrading/version-16.mdx
View file @
5452439f
...
...
@@ -843,6 +843,8 @@ const nextConfig = {
module.exports = nextConfig
```
This
might
be
necessary
when
hosting
Next
.
js
in
a
VPC
with
split
-
horizon
DNS
and
you
receive
status
400
Bad
Request
.
Only
enable
once
you
understand
the
SSRF
risk
.
### Maximum Redirects (Breaking change)
The
default
for
`images.maximumRedirects`
has
changed
from
unlimited
to
3
redirects
maximum
.
...
...
docs/01-app/03-api-reference/02-components/image.mdx
View file @
5452439f
...
...
@@ -917,6 +917,8 @@ module.exports = {
}
```
This might be necessary when hosting Next.js in a VPC with split-horizon DNS and you receive status 400 Bad Request. Only enable once you understand the SSRF risk.
#### `dangerouslyAllowSVG`
`dangerouslyAllowSVG` allows you to serve SVG images.
...
...
packages/next/src/server/image-optimizer.ts
View file @
5452439f
...
...
@@ -882,8 +882,9 @@ export async function fetchExternalImage(
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'
)
}
...
...
test/unit/image-optimizer/fetch-external-image.test.ts
View file @
5452439f
...
...
@@ -5,6 +5,54 @@ import {
}
from
'next/dist/server/image-optimizer'
describe
(
'fetchExternalImage'
,
()
=>
{
describe
(
'private IP / SSRF guard'
,
()
=>
{
it
(
'should reject a literal private IP hostname with a generic error message'
,
async
()
=>
{
const
fetchMock
=
jest
.
fn
()
global
.
fetch
=
fetchMock
const
error
=
await
fetchExternalImage
(
'http://192.168.0.1/private.jpg'
,
false
,
50
_000_000
).
catch
((
e
)
=>
e
)
expect
(
error
).
toBeInstanceOf
(
ImageError
)
expect
((
error
as
ImageError
).
statusCode
).
toBe
(
400
)
expect
((
error
as
ImageError
).
message
).
toBe
(
'"url" parameter is not allowed'
)
expect
(
fetchMock
).
not
.
toHaveBeenCalled
()
})
it
(
'should allow a literal private IP when dangerouslyAllowLocalIP is true'
,
async
()
=>
{
global
.
fetch
=
jest
.
fn
().
mockResolvedValue
({
ok
:
true
,
status
:
200
,
body
:
new
ReadableStream
({
start
(
controller
)
{
controller
.
enqueue
(
new
Uint8Array
([
1
,
2
,
3
]))
controller
.
close
()
},
}),
headers
:
{
get
:
jest
.
fn
((
header
:
string
)
=>
{
if
(
header
===
'Content-Type'
)
return
'image/jpeg'
return
null
}),
},
})
const
result
=
await
fetchExternalImage
(
'http://192.168.0.1/private.jpg'
,
true
,
50
_000_000
)
expect
(
result
.
buffer
).
toBeInstanceOf
(
Buffer
)
expect
(
global
.
fetch
).
toHaveBeenCalled
()
})
})
describe
(
'response size limit'
,
()
=>
{
it
(
'should throw error when response has no body'
,
async
()
=>
{
global
.
fetch
=
jest
.
fn
().
mockResolvedValue
({
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment