Skip to content

Commit f00fcc9

Browse files
ztannerstyfle
andauthored
[backport]: fix(next/image): fix image-optimizer.ts headers (#82114) (#82175)
Backports: - #82114 Co-authored-by: Steven <[email protected]>
1 parent 55a7568 commit f00fcc9

File tree

3 files changed

+18
-1
lines changed

3 files changed

+18
-1
lines changed

packages/next/src/server/image-optimizer.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -634,7 +634,6 @@ export async function fetchInternalImage(
634634
const mocked = createRequestResponseMocks({
635635
url: href,
636636
method: _req.method || 'GET',
637-
headers: _req.headers,
638637
socket: _req.socket,
639638
})
640639

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
const pixel =
2+
'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNkYPj/HwADBwIAMCbHYQAAAABJRU5ErkJggg=='
3+
4+
export default function handler(req, res) {
5+
if (req.headers['cookie']) {
6+
res.setHeader('content-type', 'image/png')
7+
res.end(Buffer.from(pixel, 'base64'))
8+
} else {
9+
res.status(401).end('cookie was not found')
10+
}
11+
}

test/integration/image-optimizer/test/util.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,13 @@ export function runTests(ctx: RunTestsCtx) {
308308
expect(ctx.nextOutput).toContain(animatedWarnText)
309309
})
310310

311+
it('should not forward cookie header', async () => {
312+
const query = { w: ctx.w, q: 30, url: '/api/conditional-cookie' }
313+
const opts = { headers: { accept: 'image/webp', cookie: '1' } }
314+
const res = await fetchViaHTTP(ctx.appPort, '/_next/image', query, opts)
315+
expect(res.status).toBe(400)
316+
})
317+
311318
if (ctx.nextConfigImages?.dangerouslyAllowSVG) {
312319
it('should maintain vector svg', async () => {
313320
const query = { w: ctx.w, q: 90, url: '/test.svg' }

0 commit comments

Comments
 (0)