Skip to content

Comments

fix(next/image): fix image-optimizer.ts headers (#82114)#2

Open
MitchLewis930 wants to merge 1 commit intopr_032_beforefrom
pr_032_after
Open

fix(next/image): fix image-optimizer.ts headers (#82114)#2
MitchLewis930 wants to merge 1 commit intopr_032_beforefrom
pr_032_after

Conversation

@MitchLewis930
Copy link

PR_032

The headers were forwarded to the serverless function for "internal"
images but not "external" images.

This changes the behavior to be the same for both such that neither
receive headers.
@MitchLewis930 MitchLewis930 requested a review from Copilot January 31, 2026 01:02
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes a security issue in the Next.js image optimizer by preventing sensitive headers (like cookies) from being forwarded to internal image requests. The change removes the headers forwarding in image-optimizer.ts and adds test coverage to verify that cookie headers are no longer passed through.

Changes:

  • Removed headers forwarding in the internal image request handler
  • Added test case to verify cookie headers are blocked
  • Added API endpoint to test cookie header blocking behavior

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
packages/next/src/server/image-optimizer.ts Removed headers parameter from internal image request to prevent forwarding sensitive headers
test/integration/image-optimizer/test/util.ts Added test case verifying cookie headers are not forwarded to image requests
test/integration/image-optimizer/app/pages/api/conditional-cookie.js Added test API endpoint that checks for cookie headers to validate the fix

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants