[GH-ISSUE #1949] The "Host" field in the request header is forcefully modified #1941

Open
opened 2026-03-03 19:55:38 +03:00 by kerem · 4 comments
Owner

Originally created by @xsvlz on GitHub (Feb 26, 2024).
Original GitHub issue: https://github.com/ProxymanApp/Proxyman/issues/1949

Originally assigned to: @NghiaTranUIT on GitHub.

Description

In my work, I have the following usage requirement:

I need to map the access of mobile devices to the production environment URL to the offline environment URL, for example:

xx.yy.com(production) -> 10.2.2.2:8100(offline)

At the same time, I need to set a specific value for the Host field in the request Header to access my specific business environment, for example:

Host: scene_biz.xx.yy.com

When sending requests using Proxyman, even if I manually set the Host field in the request Header to scene_biz.xx.yy.com, the actual request will still be modified to match the URL, i.e., 10.2.2.2:8100. Regardless of whether I use map remote, script, or no tools at all, simply constructing a request and sending it to Proxyman, the Host field in the Header will be tampered with.

Steps to Reproduce

  1. Construct a request using Proxyman, where the URL is in the format of ip:port and the Host in the request header is different from the URL.
  2. Send the request.
  3. Examine the request result, where the Host field in the request header has been tampered with to match the content of the requested URL.

Based on my testing, it seems that the above-mentioned abnormal behavior only occurs when the URL contains a port number.
e.g.
The Host header won't be tampered with:

curl -H "Host: xx.yy.com" http://10.2.2.2

The Host header will be tampered with and changed to "10.2.2.2:8100":

curl -H "Host: xx.yy.com" http://10.2.2.2:8100

Current Behavior

The "Host" field in the request header is forcibly tampered with to match the content of the requested URL.

Expected Behavior

The Host field in the request header should not be tampered.

Environment

  • App version: e.g Proxyman 5.0.0
  • macOS version: e.g macOS Sonoma 14.2.1 (23C71)
Originally created by @xsvlz on GitHub (Feb 26, 2024). Original GitHub issue: https://github.com/ProxymanApp/Proxyman/issues/1949 Originally assigned to: @NghiaTranUIT on GitHub. ## Description <!--- Description for the bug? --> In my work, I have the following usage requirement: I need to map the access of mobile devices to the production environment URL to the offline environment URL, for example: `xx.yy.com(production) -> 10.2.2.2:8100(offline)` At the same time, I need to set a specific value for the Host field in the request Header to access my specific business environment, for example: `Host: scene_biz.xx.yy.com` When sending requests using Proxyman, even if I manually set the Host field in the request Header to `scene_biz.xx.yy.com`, the actual request will still be modified to match the URL, i.e., `10.2.2.2:8100`. Regardless of whether I use map remote, script, or no tools at all, simply constructing a request and sending it to Proxyman, the Host field in the Header will be tampered with. ## Steps to Reproduce <!-- Add relevant code and/or a live example --> 1. Construct a request using Proxyman, where the URL is in the format of **ip:port** and the Host in the request header is different from the URL. 2. Send the request. 3. Examine the request result, where the Host field in the request header has been tampered with to match the content of the requested URL. Based on my testing, it seems that the above-mentioned abnormal behavior only occurs when the URL contains a port number. e.g. The `Host` header won't be tampered with: ``` curl -H "Host: xx.yy.com" http://10.2.2.2 ``` The `Host` header will be tampered with and changed to "10.2.2.2:8100": ``` curl -H "Host: xx.yy.com" http://10.2.2.2:8100 ``` ## Current Behavior <!--- What went wrong? --> The "Host" field in the request header is forcibly tampered with to match the content of the requested URL. ## Expected Behavior <!--- What should have happened? --> The Host field in the request header should not be tampered. ## Environment - App version: e.g Proxyman 5.0.0 - macOS version: e.g macOS Sonoma 14.2.1 (23C71)
Author
Owner

@xsvlz commented on GitHub (Feb 26, 2024):

To provide a more visual representation, I have captured screenshots of the two examples I mentioned earlier. After importing these two requests using curl, there are different outcomes.

  • Normal Case:
    CleanShot 2024-02-26 at 20 03 53@2x

  • Exceptional Case:
    CleanShot 2024-02-26 at 20 04 17@2x

<!-- gh-comment-id:1963998109 --> @xsvlz commented on GitHub (Feb 26, 2024): To provide a more visual representation, I have captured screenshots of the two examples I mentioned earlier. After importing these two requests using curl, there are different outcomes. - Normal Case: ![CleanShot 2024-02-26 at 20 03 53@2x](https://github.com/ProxymanApp/Proxyman/assets/52330309/f2768926-d803-4dc5-b2ac-d4c6e3f45624) - Exceptional Case: ![CleanShot 2024-02-26 at 20 04 17@2x](https://github.com/ProxymanApp/Proxyman/assets/52330309/91715e37-c34b-4bfb-b7bd-499417c5d552)
Author
Owner

@NghiaTranUIT commented on GitHub (Mar 1, 2024):

I need to map the access of mobile devices to the production environment URL to the offline environment URL, for example:

xx.yy.com(production) -> 10.2.2.2:8100(offline)

Can you use the Map Remote with the option: Preserve the Host Header?

Map Remote is useful if you want to map between the Localhost <-> Production.

Screenshot 2024-03-01 at 10 30 00


For other tools, Proxyman automatically construct the Host header again with a given URL.

<!-- gh-comment-id:1972439856 --> @NghiaTranUIT commented on GitHub (Mar 1, 2024): > I need to map the access of mobile devices to the production environment URL to the offline environment URL, for example: > xx.yy.com(production) -> 10.2.2.2:8100(offline) Can you use the Map Remote with the option: `Preserve the Host Header`? Map Remote is useful if you want to map between the Localhost <-> Production. ![Screenshot 2024-03-01 at 10 30 00](https://github.com/ProxymanApp/Proxyman/assets/5878421/e615198e-9cb8-47d1-beb1-631bdedec5eb) ------------------- For other tools, Proxyman automatically construct the Host header again with a given URL.
Author
Owner

@xsvlz commented on GitHub (Mar 1, 2024):

Can you use the Map Remote with the option: Preserve the Host Header?

Map Remote is useful if you want to map between the Localhost <-> Production.

My use case is quite complex, as I need to forward requests from address A to address B while modifying the Host header to address C. In Charles, I would use two features: "Map Remote" and "Rewrite". However, I couldn't find the "Rewrite" feature in Proxyman, so I resorted to using "Scripting" to manually modify the request address and headers.

Please note that for regular URL requests (e.g., http://example.com), I can successfully modify the Host header using the aforementioned operations. However, for URL requests in the format of "ip:port" (e.g., http://10.123.123.123:8080), regardless of the tool I use to modify the headers, the Host header is always changed to 10.123.123.123:8080 when sending the request.

This is also why I believe there is a bug.

<!-- gh-comment-id:1972464320 --> @xsvlz commented on GitHub (Mar 1, 2024): > Can you use the Map Remote with the option: `Preserve the Host Header`? > > Map Remote is useful if you want to map between the Localhost <-> Production. My use case is quite complex, as I need to forward requests from address A to address B while modifying the Host header to address C. In Charles, I would use two features: "Map Remote" and "Rewrite". However, I couldn't find the "Rewrite" feature in Proxyman, so I resorted to using "Scripting" to manually modify the request address and headers. Please note that for regular URL requests (e.g., `http://example.com`), I can successfully modify the Host header using the aforementioned operations. However, for URL requests in the format of "ip:port" (e.g., `http://10.123.123.123:8080`), regardless of the tool I use to modify the headers, the Host header is always changed to `10.123.123.123:8080` when sending the request. This is also why I believe there is a bug.
Author
Owner

@NghiaTranUIT commented on GitHub (Mar 4, 2024):

@xsvlz By default, the Scripting will automatically override the Host with the new URL.

You can use this one to preserve the Host Header in the Script:

async function onRequest(context, url, request) {

  request.headers["Host"] = "data.httpbin.org"
  request.preserveHostHeader = true
  
  // Done
  return request;
}

It's already supported on v5.0.0.


Linked ticket: https://github.com/ProxymanApp/Proxyman/issues/769#issuecomment-770147548

<!-- gh-comment-id:1976538790 --> @NghiaTranUIT commented on GitHub (Mar 4, 2024): @xsvlz By default, the Scripting will automatically override the Host with the new URL. You can use this one to preserve the Host Header in the Script: ```js async function onRequest(context, url, request) { request.headers["Host"] = "data.httpbin.org" request.preserveHostHeader = true // Done return request; } ``` It's already supported on v5.0.0. ---------- Linked ticket: https://github.com/ProxymanApp/Proxyman/issues/769#issuecomment-770147548
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/Proxyman#1941
No description provided.