-
Notifications
You must be signed in to change notification settings - Fork 788
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
fix: miniflare now sets the "Host" header to match the upstream URL #4630
Conversation
🦋 Changeset detectedLatest commit: 66ea286 The changes in this PR will be included in the next version bump. This PR includes changesets to release 3 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/7396783059/npm-package-wrangler-4630 You can reference the automatically updated head of this PR with: npm install --save-dev https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/prs/7396783059/npm-package-wrangler-4630 Or you can use npx https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/7396783059/npm-package-wrangler-4630 dev path/to/script.js Additional artifacts:npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/7396783059/npm-package-miniflare-4630 npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/7396783059/npm-package-cloudflare-pages-shared-4630 npx https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/7396783059/npm-package-create-cloudflare-4630 --no-auto-update Note that these links will no longer work once the GitHub Actions artifact expires.
| Please ensure constraints are pinned, and |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #4630 +/- ##
==========================================
+ Coverage 75.58% 75.67% +0.08%
==========================================
Files 243 243
Lines 13084 13087 +3
Branches 3368 3368
==========================================
+ Hits 9890 9903 +13
+ Misses 3194 3184 -10
|
86029d3
to
b3337e9
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice! I've added some comments, but LGTM! 👍
@@ -33,15 +34,39 @@ function getUserRequest( | |||
request: Request<unknown, IncomingRequestCfProperties>, | |||
env: Env | |||
) { | |||
// The original URL is a header that is passed by Miniflare to the user worker | |||
// in case the request was rewritten on its way to the user worker. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you update this comment to clarify that ORIGINAL_URL
is also set when calling Miniflare#dispatchFetch(...)
with the passed URL?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I updated the comment, but I am not 100% it is what you wanted.
CoreHeaders.PROXY_SHARED_SECRET | ||
); | ||
if (proxySharedSecret) { | ||
if (proxySharedSecret === env[CoreBindings.TEXT_PROXY_SHARED_SECRET]) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unlikely to be a problem, but really this should be crypto.subtle.timingSafeEqual()
to prevent timing attacks. This would require the shared secret to be an encoding of some uniformly distributed byte array (e.g. random hex string).
!crypto.subtle.timingSafeEqual(secretBuffer, expectedSecret) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated to use this approach.
5797645
to
d98e0f8
Compare
…ating host from original URL header
…local mode Some full-stack frameworks, such as Next.js, check that the Host header for a server side action request matches the host where the application is expected to run. In `wrangler dev` we have a Proxy Worker in between the browser and the actual User Worker. This Proxy Worker is forwarding on the request from the browser, but then the actual User Worker is running on a different host:port combination than that which the browser thinks it should be on. This was causing the framework to think the request is malicious and blocking it. Now we update the request's Host header to that passed from the Proxy Worker in a custom `MF-Original-Url` header, but only do this if the request also contains a shared secret between the Proxy Worker and User Worker, which is passed via the `MF-Proxy-Shared-Secret` header. This last feature is to prevent a malicious website from faking the Host header in a request directly to the User Worker. Fixes cloudflare/next-on-pages#588
This avoids prop drilling.
This helps to avoid an attacker guessing the secret via the timing of the comparison.
d98e0f8
to
66ea286
Compare
notes: - this is needed so that we can add e2e tests for server actions: cloudflare/workers-sdk#4630 - we the commit also updates node from 18 to 20 in e2e github acitons testing, this is necessary for using the latest wrangler release, see: cloudflare/workers-sdk#4563 (comment)
notes: - this is needed so that we can add e2e tests for server actions: cloudflare/workers-sdk#4630 - we the commit also updates node from 18 to 20 in e2e github acitons testing, this is necessary for using the latest wrangler release, see: cloudflare/workers-sdk#4563 (comment)
notes: - this is needed so that we can add e2e tests for server actions: cloudflare/workers-sdk#4630 - we the commit also updates node from 18 to 20 in e2e github acitons testing, this is necessary for using the latest wrangler release, see: cloudflare/workers-sdk#4563 (comment)
notes: - this is needed so that we can add e2e tests for server actions: cloudflare/workers-sdk#4630 - we the commit also updates node from 18 to 20 in e2e github acitons testing, this is necessary for using the latest wrangler release, see: cloudflare/workers-sdk#4563 (comment)
* add vitest.config.ts file with retry for better tests stability * add new e2e features to test wasm * avoid inconsistent kebab-case * use latest wrangler release notes: - this is needed so that we can add e2e tests for server actions: cloudflare/workers-sdk#4630 - we the commit also updates node from 18 to 20 in e2e github acitons testing, this is necessary for using the latest wrangler release, see: cloudflare/workers-sdk#4563 (comment) * add app server-actions e2e test * remove unnecessary existsSync assertion in processVercelOutput unit tests
Fixes #4643
Fixes cloudflare/next-on-pages#588
It is good to review this PR commit by commit.
What this PR solves / how to test:
Some full-stack frameworks, such as Next.js, check that the Host header for a server
side action request matches the host where the application is expected to run.
In
wrangler dev
we have a Proxy Worker in between the browser and the actual User Worker.This Proxy Worker is forwarding on the request from the browser, but then the actual User
Worker is running on a different host:port combination than that which the browser thinks
it should be on. This was causing the framework to think the request is malicious and blocking
it.
Now we update the request's Host header to that passed from the Proxy Worker in a custom
MF-Original-Url
header, but only do this if the request also contains a shared secret between the Proxy Worker
and User Worker, which is passed via the
MF-Proxy-Shared-Secret
header. This last feature is toprevent a malicious website from faking the Host header in a request directly to the User Worker.
The
worker-app
fixture has been updated to check that this is working as expected.Author has addressed the following: