Skip to content

Commit bcc7c65

Browse files
ztannerstyfle
andauthored
[backport v14]: fix(next/image): fix image-optimizer.ts headers (#82114) (#82178)
Backports: - #82114 Co-authored-by: Steven <[email protected]>
1 parent 243072b commit bcc7c65

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
@@ -594,7 +594,6 @@ export async function fetchInternalImage(
594594
const mocked = createRequestResponseMocks({
595595
url: href,
596596
method: _req.method || 'GET',
597-
headers: _req.headers,
598597
socket: _req.socket,
599598
})
600599

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
@@ -264,6 +264,13 @@ export function runTests(ctx) {
264264
expect(ctx.nextOutput).toContain(animatedWarnText)
265265
})
266266

267+
it('should not forward cookie header', async () => {
268+
const query = { w: ctx.w, q: 30, url: '/api/conditional-cookie' }
269+
const opts = { headers: { accept: 'image/webp', cookie: '1' } }
270+
const res = await fetchViaHTTP(ctx.appPort, '/_next/image', query, opts)
271+
expect(res.status).toBe(400)
272+
})
273+
267274
if (ctx.dangerouslyAllowSVG) {
268275
it('should maintain vector svg', async () => {
269276
const query = { w: ctx.w, q: 90, url: '/test.svg' }

0 commit comments

Comments
 (0)