Skip to content

Commit 15ce690

Browse files
committed
add additional x-middleware-set-cookie filtering (#75561)
Previously when we removed this from the response we only did so for requests that flowed through middleware and static handlers. We should ensure it's filtered in `sendResponse` as well. The header is only needed internally.
1 parent 8129a61 commit 15ce690

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

packages/next/src/server/send-response.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@ export async function sendResponse(
2525

2626
// Copy over the response headers.
2727
response.headers?.forEach((value, name) => {
28+
// `x-middleware-set-cookie` is an internal header not needed for the response
29+
if (name.toLowerCase() === 'x-middleware-set-cookie') {
30+
return
31+
}
32+
2833
// The append handling is special cased for `set-cookie`.
2934
if (name.toLowerCase() === 'set-cookie') {
3035
// TODO: (wyattjoh) replace with native response iteration when we can upgrade undici
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { NextResponse } from 'next/server'
2+
3+
export function GET() {
4+
const response = new NextResponse()
5+
response.cookies.set({
6+
name: 'example',
7+
value: 'example',
8+
})
9+
10+
return response
11+
}

0 commit comments

Comments
 (0)