Skip to content

Commit b9f8c97

Browse files
committed
Make the runtime work only with absolute URLs
1 parent 36373e1 commit b9f8c97

File tree

2 files changed

+4
-6
lines changed

2 files changed

+4
-6
lines changed

packages/next/server/web/spec-compliant/response.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ class BaseResponse extends Body implements Response {
4545
)
4646
}
4747

48-
return new Response(url, {
48+
return new Response(String(new URL(url)), {
4949
headers: { Location: url },
5050
status,
5151
})

packages/next/server/web/spec-extension/response.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,8 @@ export class NextResponse extends Response {
7979
'Failed to execute "redirect" on "response": Invalid status code'
8080
)
8181
}
82-
const destination = typeof url === 'string' ? url : url.toString()
82+
83+
const destination = String(new URL(String(url)))
8384
return new NextResponse(destination, {
8485
headers: { Location: destination },
8586
status,
@@ -89,10 +90,7 @@ export class NextResponse extends Response {
8990
static rewrite(destination: string | NextURL) {
9091
return new NextResponse(null, {
9192
headers: {
92-
'x-middleware-rewrite':
93-
typeof destination === 'string'
94-
? destination
95-
: destination.toString(),
93+
'x-middleware-rewrite': String(new URL(String(destination))),
9694
},
9795
})
9896
}

0 commit comments

Comments
 (0)