Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
N
next.js
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Alex
next.js
Commits
2bd65884
Unverified
Commit
2bd65884
authored
Feb 10, 2025
by
Zack Tanner
Committed by
GitHub
Feb 10, 2025
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add additional x-middleware-set-cookie filtering (#75869)
Backports: - #75561
parent
0d9f6059
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
22 additions
and
0 deletions
+22
-0
send-response.ts
packages/next/src/server/send-response.ts
+5
-0
app-middleware.test.ts
test/e2e/app-dir/app-middleware/app-middleware.test.ts
+6
-0
route.js
test/e2e/app-dir/app-middleware/app/cookies/api/route.js
+11
-0
No files found.
packages/next/src/server/send-response.ts
View file @
2bd65884
...
...
@@ -36,6 +36,11 @@ export async function sendResponse(
// Copy over the response headers.
response
.
headers
?.
forEach
((
value
,
name
)
=>
{
// `x-middleware-set-cookie` is an internal header not needed for the response
if
(
name
.
toLowerCase
()
===
'x-middleware-set-cookie'
)
{
return
}
// The append handling is special cased for `set-cookie`.
if
(
name
.
toLowerCase
()
===
'set-cookie'
)
{
// TODO: (wyattjoh) replace with native response iteration when we can upgrade undici
...
...
test/e2e/app-dir/app-middleware/app-middleware.test.ts
View file @
2bd65884
...
...
@@ -191,6 +191,12 @@ describe('app-dir with middleware', () => {
const
response
=
await
next
.
fetch
(
'/rsc-cookies/cookie-options'
)
expect
(
response
.
status
).
toBe
(
200
)
expect
(
response
.
headers
.
get
(
'x-middleware-set-cookie'
)).
toBeNull
()
const
response2
=
await
next
.
fetch
(
'/cookies/api'
)
expect
(
response2
.
status
).
toBe
(
200
)
expect
(
response2
.
headers
.
get
(
'x-middleware-set-cookie'
)).
toBeNull
()
expect
(
response2
.
headers
.
get
(
'set-cookie'
)).
toBeDefined
()
expect
(
response2
.
headers
.
get
(
'set-cookie'
)).
toContain
(
'example'
)
})
it
(
'should ignore x-middleware-set-cookie as a request header'
,
async
()
=>
{
...
...
test/e2e/app-dir/app-middleware/app/cookies/api/route.js
0 → 100644
View file @
2bd65884
import
{
NextResponse
}
from
'next/server'
export
function
GET
()
{
const
response
=
new
NextResponse
()
response
.
cookies
.
set
({
name
:
'example'
,
value
:
'example'
,
})
return
response
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment