Strip CF-Connecting-IP header from all outbound requests#7914
Conversation
🦋 Changeset detectedLatest commit: f5675a0 The changes in this PR will be included in the next version bump. This PR includes changesets to release 5 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
A wrangler prerelease is available for testing. You can install this latest build in your project with: npm install --save-dev https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/14082081202/npm-package-wrangler-7914You can reference the automatically updated head of this PR with: npm install --save-dev https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/prs/7914/npm-package-wrangler-7914Or you can use npx https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/14082081202/npm-package-wrangler-7914 dev path/to/script.jsAdditional artifacts:cloudflare-workers-bindings-extension: wget https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/14082081202/npm-package-cloudflare-workers-bindings-extension-7914 -O ./cloudflare-workers-bindings-extension.0.0.0-v81ac03b8a.vsix && code --install-extension ./cloudflare-workers-bindings-extension.0.0.0-v81ac03b8a.vsixcreate-cloudflare: npx https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/14082081202/npm-package-create-cloudflare-7914 --no-auto-update@cloudflare/kv-asset-handler: npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/14082081202/npm-package-cloudflare-kv-asset-handler-7914miniflare: npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/14082081202/npm-package-miniflare-7914@cloudflare/pages-shared: npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/14082081202/npm-package-cloudflare-pages-shared-7914@cloudflare/unenv-preset: npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/14082081202/npm-package-cloudflare-unenv-preset-7914@cloudflare/vite-plugin: npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/14082081202/npm-package-cloudflare-vite-plugin-7914@cloudflare/vitest-pool-workers: npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/14082081202/npm-package-cloudflare-vitest-pool-workers-7914@cloudflare/workers-editor-shared: npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/14082081202/npm-package-cloudflare-workers-editor-shared-7914@cloudflare/workers-shared: npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/14082081202/npm-package-cloudflare-workers-shared-7914@cloudflare/workflows-shared: npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/14082081202/npm-package-cloudflare-workflows-shared-7914Note that these links will no longer work once the GitHub Actions artifact expires.
Please ensure constraints are pinned, and |
0adafea to
63500ea
Compare
63500ea to
d4c3b39
Compare
| }); | ||
| }); | ||
|
|
||
| global.fetch = mockFetch as typeof global.fetch; |
There was a problem hiding this comment.
This should use MSW if possible
| handleRuntimeStdio, | ||
| liveReload: false, | ||
|
|
||
| outboundService: stripHeader("cf-connecting-ip"), |
There was a problem hiding this comment.
I'm not sure this is the right place for this. This will strip cf-connecting-ip on outgoing fetches from the Proxy worker, which we don't want to do. I think we should be adding this for local user workers? (LocalRuntimeController)
28b301a to
60d1e61
Compare
60d1e61 to
4879bb9
Compare
| bindVectorizeToProd: input.dev?.bindVectorizeToProd ?? false, | ||
| multiworkerPrimary: input.dev?.multiworkerPrimary, | ||
| imagesLocalMode: input.dev?.imagesLocalMode ?? false, | ||
| outboundService: input.dev?.outboundService, |
There was a problem hiding this comment.
This makes the dev.outboundService options working with startDevWorker
| } | ||
|
|
||
| return ( | ||
| config.outboundService?.(request) ?? |
There was a problem hiding this comment.
We will use the user defined outboundService instead of fetch-ing it ourselves if it is available.
| outboundService(request) { | ||
| if (request.headers.has("CF-Connecting-IP")) { | ||
| request.headers.delete("CF-Connecting-IP"); | ||
| } |
There was a problem hiding this comment.
This outboundService applies to the User Worker only. We were trying to add it to all workers in the LocalRuntimeController which might includes wrapped bindings and crash because it does not support outboundService.
|
should we be doing this in miniflare? |
Good point. I didn't notice this was done on the miniflare side. I will give it another look to see if we can strip it there. |
|
Hey there, curious if there are any plans to get this in the next version of wrangler. I'm unable to locally test on any of my customers sites (#8333). Or is there any quick work around I can add to my code to get around this limitation in the meantime? |
|
@LukePammant one (less than ideal) workaround I've discovered that may or may not work for you is that you can use remote mode instead of local: |
fca99d2 to
29e8140
Compare
29e8140 to
cada740
Compare
|
I've pushed a new commit that implements this in Miniflare. There's a test for the positive case, but it's hard to test the negative case in CI because it interacts badly with bot detection. To test manually, try making a fetch request to |
| const landingPage = await mf.dispatchFetch("http://example.com/"); | ||
| t.assert( | ||
| !(await landingPage.text()).includes( | ||
| "Unfortunately, it is resolving to an IP address that is creating a conflict within Cloudflare's system" |
There was a problem hiding this comment.
This feels a bit fragile... if the backend slightly changed this error message this assertion would always pass.
fb431dc to
ce6d6d3
Compare
|
Failed to automatically backport this PR's changes to Wrangler v3. Please manually create a PR targeting the Depending on your changes, running |
|
A Wrangler prerelease is available for testing. You can install this latest build in your project with: npm install --save-dev https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/14970437289/npm-package-wrangler-7914Prereleases for other packages:
wget https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/14970437289/npm-package-cloudflare-workers-bindings-extension-7914 -O ./cloudflare-workers-bindings-extension.0.0.0-v262c37821.vsix && code --install-extension ./cloudflare-workers-bindings-extension.0.0.0-v262c37821.vsix
npx https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/14970437289/npm-package-create-cloudflare-7914 --no-auto-update
npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/14970437289/npm-package-cloudflare-kv-asset-handler-7914
npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/14970437289/npm-package-miniflare-7914
npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/14970437289/npm-package-cloudflare-pages-shared-7914
npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/14970437289/npm-package-cloudflare-unenv-preset-7914
npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/14970437289/npm-package-cloudflare-vite-plugin-7914
npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/14970437289/npm-package-cloudflare-vitest-pool-workers-7914
npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/14970437289/npm-package-cloudflare-workers-editor-shared-7914
npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/14970437289/npm-package-cloudflare-workers-shared-7914
npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/14970437289/npm-package-cloudflare-workflows-shared-7914Note that these links will no longer work once the GitHub Actions artifact expires. |
| // The CF-Connecting-IP header value of "fake-value" should be stripped by Miniflare, and should be replaced with a generic 127.0.0.1 | ||
| t.notDeepEqual(await landingPage.text(), "fake-value"); | ||
| }); | ||
| test("Miniflare: does not strip CF-Connecting-IP when configured", async (t) => { |
There was a problem hiding this comment.
Can we add an empty line here?
Fixes #7835, #7924
Strip the CF-Connecting-IP header from outbound requests.
This cannot be effectively tested in CI because it interacts badly and in strange ways with bot management and various other protections.To test manually:fixtures/worker-ts)return fetch("https://www.cloudflare.com", request)to the Workerwrangler devpnpx wrangler@latest dev), validate that an error page is returned