tobychui / zoraxy

A general purpose HTTP reverse proxy and forwarding tool. Now written in Go!
https://zoraxy.arozos.com
GNU Affero General Public License v3.0
2.64k stars 154 forks source link

[BUG] The HTTP Host Header cannot be modified. #255

Closed IntBoat closed 1 month ago

IntBoat commented 1 month ago

Describe the bug In Custom Headers, if you try to change the Host Header in the Header Key, it cannot be modified, while other keys work fine.

To Reproduce Steps to reproduce the behavior:

  1. Go to HTTP Proxy
  2. Click on Edit
  3. Edit Custom Headers, add: Zoraxy -> Origin, Add Host Headers

Expected behavior The HTTP Host Header should be modified.

Host Environment (please complete the following information):

I am trying to use an HTTP proxy to forward a URL to a router's configuration webpage on an internal network. However, I noticed that after setting up the forwarding, the page encounters a redirect loop issue. When using Cloudflare Tunnel, simply changing the Host Header to the internal IP address resolves this problem.

When attempting to modify the Host Header to the internal IP address in Zoraxy, I found that the issue still persists. Upon further inspection and comparison, it appears that Zoraxy did not modify the Host Header, although modifying or adding other Header Keys works fine.

tobychui commented 1 month ago

Hey @IntBoat

This is not a bug, but a feature. Zoraxy automatically rewrite the host field in the header based on the inbound host-name, outbound target and a few more sniffing logic and preset rules. Conditions where you need to modify the Host field are usually due to an invalid setting of the upstream service config. (Maybe you didn't set the "base url" or something similar in the upstream app?)

For sure I can add a manual override of the automatic sniffing / rewrite logic, but I would love to know more about your use cases so I can design a better UX for user who might need this feature (which is a rare case in homelab setups).

IntBoat commented 1 month ago

@tobychui Thank you for your prompt and detailed response. I appreciate the effort you put into developing such a great program.

If the application is well-designed and uses relative redirects or redirects based on the host header, this issue wouldn't happen. Unfortunately, in some cases, we can't always tweak the code or settings to fix it.

For instance, in my situation, the router lacks the necessary settings for adjustments, so it has to be handled by Zoraxy. This is also one of the reasons why Cloudflare Tunnels provide the ability to change the Host.

tobychui commented 1 month ago

圖片

Ok I have added an advance setting dropdown in header editor so for edge cases. Should be ready to use in next release.