-
Notifications
You must be signed in to change notification settings - Fork 155
fix: remove cf-connecting-ip
headers from external override requests
#724
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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-header` headers from external override requests | ||
|
||
this change removes `cf-connecting-header` headers from requests being sent to | ||
dario-piotrowicz marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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 hidden or 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 hidden or 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"); | ||
}); | ||
}); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.