Skip to content

Commit

Permalink
make sure that the original request headers are not passed along when…
Browse files Browse the repository at this point in the history
… fetching external images (#717)
  • Loading branch information
dario-piotrowicz authored Mar 21, 2024
1 parent 8951ab0 commit c3fb67b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changeset/lazy-avocados-swim.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@cloudflare/next-on-pages': patch
---

make sure that the original request headers are not passed along when fetching external images
9 changes: 5 additions & 4 deletions packages/next-on-pages/templates/_worker.js/utils/images.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,11 +158,12 @@ export async function handleImageResizingRequest(

// TODO: implement proper image resizing

const imageReq = new Request(imageUrl, { headers: request.headers });
const imageResp =
const imgFetch =
isRelative && imageUrl.pathname in buildOutput
? await assetsFetcher.fetch(imageReq)
: await fetch(imageReq);
? assetsFetcher.fetch.bind(assetsFetcher)
: fetch;

const imageResp = await imgFetch(imageUrl);

return formatResp(imageResp, imageUrl, imagesConfig);
}
Expand Down

0 comments on commit c3fb67b

Please sign in to comment.