Skip to content

Commit 034f85e

Browse files
committed
fix: use constant internal origin instead of req.headers.host in revalidation patch
1 parent da4b7fc commit 034f85e

3 files changed

Lines changed: 13 additions & 2 deletions

File tree

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
"@opennextjs/cloudflare": patch
3+
---
4+
5+
fix: use constant internal origin instead of req.headers.host in revalidation patch
6+
7+
The `res.revalidate()` patch now uses a constant internal origin (`https://self.local`)
8+
instead of the user-controllable `req.headers.host` for the `WORKER_SELF_REFERENCE.fetch()`
9+
URL. The service binding routes to the correct worker regardless of the URL host, so the
10+
host value is only metadata. This eliminates host header injection without affecting
11+
functionality.

packages/cloudflare/src/cli/build/patches/plugins/res-revalidate.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ describe("patchResRevalidate", () => {
9595
- method: 'HEAD',
9696
- headers: revalidateHeaders
9797
- });
98-
+ const res = await (await import("@opennextjs/cloudflare")).getCloudflareContext().env.WORKER_SELF_REFERENCE.fetch(\`\${req.headers.host.includes("localhost") ? "http":"https" }://\${req.headers.host}\${urlPath}\`,{method:'HEAD', headers:revalidateHeaders});
98+
+ const res = await (await import("@opennextjs/cloudflare")).getCloudflareContext().env.WORKER_SELF_REFERENCE.fetch(\`https://self.local\${urlPath}\`,{method:'HEAD', headers:revalidateHeaders});
9999
// we use the cache header to determine successful revalidate as
100100
// a non-200 status code can be returned from a successful revalidate
101101
// e.g. notFound: true returns 404 status code but is successful

packages/cloudflare/src/cli/build/patches/plugins/res-revalidate.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ rule:
5353
has:
5454
kind: identifier
5555
56-
fix: await (await import("@opennextjs/cloudflare")).getCloudflareContext().env.WORKER_SELF_REFERENCE.fetch(\`\${$REQ.headers.host.includes("localhost") ? "http":"https" }://\${$REQ.headers.host}$URL_PATH\`,{method:'HEAD', headers:$HEADERS})
56+
fix: await (await import("@opennextjs/cloudflare")).getCloudflareContext().env.WORKER_SELF_REFERENCE.fetch(\`https://self.local$URL_PATH\`,{method:'HEAD', headers:$HEADERS})
5757
`;
5858

5959
export const patchResRevalidate: CodePatcher = {

0 commit comments

Comments
 (0)