Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion packages/next/src/server/image-optimizer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -634,7 +634,6 @@ export async function fetchInternalImage(
const mocked = createRequestResponseMocks({
url: href,
method: _req.method || 'GET',
headers: _req.headers,
socket: _req.socket,
})

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
const pixel =
'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNkYPj/HwADBwIAMCbHYQAAAABJRU5ErkJggg=='

export default function handler(req, res) {
if (req.headers['cookie']) {
res.setHeader('content-type', 'image/png')
res.end(Buffer.from(pixel, 'base64'))
} else {
res.status(401).end('cookie was not found')
}
}
7 changes: 7 additions & 0 deletions test/integration/image-optimizer/test/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,13 @@ export function runTests(ctx: RunTestsCtx) {
expect(ctx.nextOutput).toContain(animatedWarnText)
})

it('should not forward cookie header', async () => {
const query = { w: ctx.w, q: 30, url: '/api/conditional-cookie' }
const opts = { headers: { accept: 'image/webp', cookie: '1' } }
const res = await fetchViaHTTP(ctx.appPort, '/_next/image', query, opts)
expect(res.status).toBe(400)
Copy link

Copilot AI Jan 31, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test expects a 400 status code, but based on the test API endpoint in conditional-cookie.js, when the cookie header is missing (which is the expected behavior after the fix), the endpoint returns a 401 status with the message 'cookie was not found'. The test should verify that the image optimizer rejects the request before it reaches the API endpoint, or should expect a 401 status to match the API's behavior when cookies are absent.

Copilot uses AI. Check for mistakes.
})

if (ctx.nextConfigImages?.dangerouslyAllowSVG) {
it('should maintain vector svg', async () => {
const query = { w: ctx.w, q: 90, url: '/test.svg' }
Expand Down