-
Notifications
You must be signed in to change notification settings - Fork 789
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: miniflare now sets the "Host" header to match the upstream URL (#…
…4630) * fix: miniflare now sets the "Host" header to match the upstream URL * feat: miniflare exposes unsafeProxySignature config that controls updating host from original URL header * fix: ensure User Worker gets the correct Host header in wrangler dev 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 * rename "proxy signature" to "proxy shared secret" * Move proxy shared secret to where it is needed This avoids prop drilling. * Use timingSafeEqual for secret comparison This helps to avoid an attacker guessing the secret via the timing of the comparison.
- Loading branch information
1 parent
9e03272
commit 037de5e
Showing
12 changed files
with
244 additions
and
46 deletions.
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,22 @@ | ||
--- | ||
"miniflare": patch | ||
"wrangler": patch | ||
--- | ||
|
||
fix: ensure User Worker gets the correct Host header in wrangler dev 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 https://github.com/cloudflare/next-on-pages/issues/588 |
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
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
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
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
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
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
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
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
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
Oops, something went wrong.