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
1b3b090d
Commit
1b3b090d
authored
Jan 07, 2026
by
Jiachi Liu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add failing test
parent
ac5e593b
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
223 additions
and
0 deletions
+223
-0
.gitignore
test/e2e/middleware-non-ascii-headers/app/.gitignore
+1
-0
middleware.js
test/e2e/middleware-non-ascii-headers/app/middleware.js
+28
-0
next.config.js
test/e2e/middleware-non-ascii-headers/app/next.config.js
+1
-0
headers.js
...e2e/middleware-non-ascii-headers/app/pages/api/headers.js
+7
-0
middleware-non-ascii-headers.test.ts
...re-non-ascii-headers/middleware-non-ascii-headers.test.ts
+186
-0
No files found.
test/e2e/middleware-non-ascii-headers/app/.gitignore
0 → 100644
View file @
1b3b090d
.next
test/e2e/middleware-non-ascii-headers/app/middleware.js
0 → 100644
View file @
1b3b090d
import
{
NextResponse
}
from
'next/server'
/**
* Middleware that forwards request headers including non-ASCII values.
* This simulates how Cloudflare or other CDNs might add headers with
* non-ASCII characters (e.g., cf-ipcity: Montréal).
*
* The issue (#85631) is that when middleware forwards headers containing
* non-ASCII characters, they get passed through x-middleware-request-* headers
* which must be ASCII-safe. This causes errors on Vercel's runtime.
*
* @param {import('next/server').NextRequest} request
*/
export
async
function
middleware
(
request
)
{
// Simply forward all existing headers through NextResponse.next()
// This is the common pattern that triggers the issue when incoming
// headers contain non-ASCII values (e.g., from Cloudflare geolocation)
const
headers
=
new
Headers
(
request
.
headers
)
// Add a marker header to prove middleware ran
headers
.
set
(
'x-middleware-ran'
,
'true'
)
return
NextResponse
.
next
({
request
:
{
headers
,
},
})
}
test/e2e/middleware-non-ascii-headers/app/next.config.js
0 → 100644
View file @
1b3b090d
module
.
exports
=
{}
test/e2e/middleware-non-ascii-headers/app/pages/api/headers.js
0 → 100644
View file @
1b3b090d
/**
* API route that returns all request headers as JSON.
* Used to verify middleware header handling.
*/
export
default
function
handler
(
req
,
res
)
{
res
.
status
(
200
).
json
(
req
.
headers
)
}
test/e2e/middleware-non-ascii-headers/middleware-non-ascii-headers.test.ts
0 → 100644
View file @
1b3b090d
import
{
join
}
from
'path'
import
{
NextInstance
}
from
'e2e-utils'
import
{
fetchViaHTTP
}
from
'next-test-utils'
import
{
createNext
,
FileRef
}
from
'e2e-utils'
/**
* Test for issue #85631: Middleware crashes when processing headers with non-ASCII characters.
*
* When middleware forwards headers containing non-ASCII values (e.g., Cloudflare's
* cf-ipcity: "Montréal"), the request fails because x-middleware-request-* headers
* must be ASCII-safe per HTTP spec.
*
* Error: "Header 'x-middleware-request-cf-ipcity: Montréal' contains non-ASCII characters"
*
* Note: HTTP headers can only contain ISO-8859-1 (Latin-1) characters (char codes 0-255).
* Characters outside this range cannot be sent via HTTP headers at all.
* The issue specifically affects Latin-1 characters like French accents (é, è, ê),
* German umlauts (ü, ö, ä), and other Western European characters.
*/
describe
(
'Middleware Non-ASCII Headers'
,
()
=>
{
let
next
:
NextInstance
afterAll
(()
=>
next
.
destroy
())
beforeAll
(
async
()
=>
{
next
=
await
createNext
({
files
:
{
pages
:
new
FileRef
(
join
(
__dirname
,
'app/pages'
)),
'next.config.js'
:
new
FileRef
(
join
(
__dirname
,
'app/next.config.js'
)),
'middleware.js'
:
new
FileRef
(
join
(
__dirname
,
'app/middleware.js'
)),
},
})
})
it
(
'should handle headers with French accented characters (Montréal)'
,
async
()
=>
{
// This is the exact scenario from issue #85631 - Cloudflare's cf-ipcity header
const
res
=
await
fetchViaHTTP
(
next
.
url
,
'/api/headers'
,
{},
{
headers
:
{
'x-city'
:
'Montréal'
,
},
}
)
expect
(
res
.
status
).
toBe
(
200
)
const
headers
=
await
res
.
json
()
expect
(
headers
[
'x-middleware-ran'
]).
toBe
(
'true'
)
expect
(
headers
[
'x-city'
]).
toBe
(
'Montréal'
)
})
it
(
'should handle headers with German umlauts (München)'
,
async
()
=>
{
const
res
=
await
fetchViaHTTP
(
next
.
url
,
'/api/headers'
,
{},
{
headers
:
{
'x-city'
:
'München'
,
},
}
)
expect
(
res
.
status
).
toBe
(
200
)
const
headers
=
await
res
.
json
()
expect
(
headers
[
'x-middleware-ran'
]).
toBe
(
'true'
)
expect
(
headers
[
'x-city'
]).
toBe
(
'München'
)
})
it
(
'should handle headers with Spanish characters (España)'
,
async
()
=>
{
const
res
=
await
fetchViaHTTP
(
next
.
url
,
'/api/headers'
,
{},
{
headers
:
{
'x-country'
:
'España'
,
},
}
)
expect
(
res
.
status
).
toBe
(
200
)
const
headers
=
await
res
.
json
()
expect
(
headers
[
'x-middleware-ran'
]).
toBe
(
'true'
)
expect
(
headers
[
'x-country'
]).
toBe
(
'España'
)
})
it
(
'should handle headers with Nordic characters (Malmö, København)'
,
async
()
=>
{
const
res
=
await
fetchViaHTTP
(
next
.
url
,
'/api/headers'
,
{},
{
headers
:
{
'x-city'
:
'Malmö'
,
'x-region'
:
'København'
,
},
}
)
expect
(
res
.
status
).
toBe
(
200
)
const
headers
=
await
res
.
json
()
expect
(
headers
[
'x-middleware-ran'
]).
toBe
(
'true'
)
expect
(
headers
[
'x-city'
]).
toBe
(
'Malmö'
)
expect
(
headers
[
'x-region'
]).
toBe
(
'København'
)
})
it
(
'should handle headers with French region names (Île-de-France)'
,
async
()
=>
{
const
res
=
await
fetchViaHTTP
(
next
.
url
,
'/api/headers'
,
{},
{
headers
:
{
'x-region'
:
'Île-de-France'
,
},
}
)
expect
(
res
.
status
).
toBe
(
200
)
const
headers
=
await
res
.
json
()
expect
(
headers
[
'x-middleware-ran'
]).
toBe
(
'true'
)
expect
(
headers
[
'x-region'
]).
toBe
(
'Île-de-France'
)
})
it
(
'should handle headers with Austrian characters (Österreich)'
,
async
()
=>
{
const
res
=
await
fetchViaHTTP
(
next
.
url
,
'/api/headers'
,
{},
{
headers
:
{
'x-country'
:
'Österreich'
,
},
}
)
expect
(
res
.
status
).
toBe
(
200
)
const
headers
=
await
res
.
json
()
expect
(
headers
[
'x-middleware-ran'
]).
toBe
(
'true'
)
expect
(
headers
[
'x-country'
]).
toBe
(
'Österreich'
)
})
it
(
'should handle multiple headers with various Latin-1 characters'
,
async
()
=>
{
const
res
=
await
fetchViaHTTP
(
next
.
url
,
'/api/headers'
,
{},
{
headers
:
{
'x-city'
:
'Montréal'
,
'x-region'
:
'Île-de-France'
,
'x-country'
:
'Österreich'
,
'x-greeting'
:
'Grüß Gott'
,
},
}
)
expect
(
res
.
status
).
toBe
(
200
)
const
headers
=
await
res
.
json
()
expect
(
headers
[
'x-middleware-ran'
]).
toBe
(
'true'
)
expect
(
headers
[
'x-city'
]).
toBe
(
'Montréal'
)
expect
(
headers
[
'x-region'
]).
toBe
(
'Île-de-France'
)
expect
(
headers
[
'x-country'
]).
toBe
(
'Österreich'
)
expect
(
headers
[
'x-greeting'
]).
toBe
(
'Grüß Gott'
)
})
it
(
'should handle headers with Portuguese characters (São Paulo)'
,
async
()
=>
{
const
res
=
await
fetchViaHTTP
(
next
.
url
,
'/api/headers'
,
{},
{
headers
:
{
'x-city'
:
'São Paulo'
,
},
}
)
expect
(
res
.
status
).
toBe
(
200
)
const
headers
=
await
res
.
json
()
expect
(
headers
[
'x-middleware-ran'
]).
toBe
(
'true'
)
expect
(
headers
[
'x-city'
]).
toBe
(
'São Paulo'
)
})
})
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