Skip to content

Commit

Permalink
[fix] don't redirect to external URLs when normalizing paths (#4414)
Browse files Browse the repository at this point in the history
  • Loading branch information
benmccann authored Mar 22, 2022
1 parent 2865f41 commit 32a700a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/curvy-foxes-change.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sveltejs/kit': patch
---

[fix] don't redirect to external URLs when normalizing paths
5 changes: 4 additions & 1 deletion packages/kit/src/runtime/server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ export async function respond(request, options, state) {
return new Response(undefined, {
status: 301,
headers: {
location: normalized + (url.search === '?' ? '' : url.search)
location:
// ensure paths starting with '//' are not treated as protocol-relative
(normalized.startsWith('//') ? url.origin + normalized : normalized) +
(url.search === '?' ? '' : url.search)
}
});
}
Expand Down

0 comments on commit 32a700a

Please sign in to comment.