-
Notifications
You must be signed in to change notification settings - Fork 143
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: remove
cf-connecting-ip
headers from external override requests (
#724) Co-authored-by: conico974 <nicodorseuil@yahoo.fr>
- Loading branch information
1 parent
dd9face
commit 94d6eca
Showing
3 changed files
with
56 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
--- | ||
"@opennextjs/aws": patch | ||
--- | ||
|
||
fix: remove `cf-connecting-ip` headers from external override requests | ||
|
||
this change removes `cf-connecting-ip` headers from requests being sent to | ||
external urls during rewrites, this allows such overrides, when run inside a | ||
Cloudflare worker to rewrite to urls also hosted on Cloudflare |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
packages/tests-unit/tests/overrides/proxyExternalRequest/fetch.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import fetchProxy from "@opennextjs/aws/overrides/proxyExternalRequest/fetch.js"; | ||
import { vi } from "vitest"; | ||
|
||
describe("proxyExternalRequest/fetch", () => { | ||
// Note: if the url is hosted on the Cloudflare network we want to make sure that a `cf-connecting-ip` header is not being sent as that causes a DNS error | ||
// (see: https://developers.cloudflare.com/support/troubleshooting/cloudflare-errors/troubleshooting-cloudflare-1xxx-errors/#error-1000-dns-points-to-prohibited-ip) | ||
it("the proxy should remove any cf-connecting-ip headers (with any casing) before passing it to fetch", async () => { | ||
const fetchMock = vi.fn<typeof global.fetch>(async () => new Response()); | ||
globalThis.fetch = fetchMock; | ||
|
||
const { proxy } = fetchProxy; | ||
|
||
await proxy({ | ||
headers: { | ||
"header-1": "valid header 1", | ||
"header-2": "valid header 2", | ||
"cf-connecting-ip": "forbidden header 1", | ||
"header-3": "valid header 3", | ||
"CF-Connecting-IP": "forbidden header 2", | ||
"CF-CONNECTING-IP": "forbidden header 3", | ||
"header-4": "valid header 4", | ||
}, | ||
}); | ||
|
||
expect(fetchMock.mock.calls.length).toEqual(1); | ||
|
||
const headersPassedToFetch = Object.keys( | ||
fetchMock.mock.calls[0][1]?.headers ?? {}, | ||
); | ||
|
||
expect(headersPassedToFetch).toContain("header-1"); | ||
expect(headersPassedToFetch).toContain("header-2"); | ||
expect(headersPassedToFetch).not.toContain("cf-connecting-ip"); | ||
expect(headersPassedToFetch).toContain("header-3"); | ||
expect(headersPassedToFetch).not.toContain("CF-Connecting-IP"); | ||
expect(headersPassedToFetch).not.toContain("CF-CONNECTING-IP"); | ||
expect(headersPassedToFetch).toContain("header-4"); | ||
}); | ||
}); |