reverse-proxy: POST not working in IIS/Express due to IsUpgradableRequest
– Admin Edit: Unrelated issue content hidden –
I’m currently unable to get Request Transforms to work on NETCore 3.1 in VS19 16.6.5.
{
"RouteId": "oh/rest",
"BackendId": "oh",
"Match": {
"Host": "localhost",
"Path": "/rest/{*remainder}"
},
"Transforms": [
{ "X-Forwarded": "" },
{ "RequestHeaderOriginalHost": "true" }
]
}
From wireshark:
POST /rest/items/Flush2Relay_Switch1 HTTP/1.1\r\n
Host: otherhost:8080\r\n
Accept: application/json, text/plain, */*\r\n
Accept-Encoding: gzip, deflate, br\r\n
Accept-Language: en-US, en; q=0.9\r\n
Cache-Control: no-cache\r\n
Connection: close\r\n
[truncated]Cookie: HIDDDEN
Pragma: no-cache\r\n
Referer: https://localhost:44354/paperui/index.html\r\n
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.106 Safari/537.36 Edg/83.0.478.54\r\n
Origin: https://localhost:44354\r\n
sec-fetch-site: same-origin\r\n
sec-fetch-mode: cors\r\n
sec-fetch-dest: empty\r\n
X-Forwarded-Proto: https\r\n
X-Forwarded-Host: localhost:44354\r\n
X-Forwarded-For: ::1\r\n
Content-Length: 0\r\n
\r\n
[Full request URI: http://otherhost:8080/rest/items/Flush2Relay_Switch1]
[HTTP request 1/1]
[Response in frame: 52458]
The proxy is proxying correctly but the incoming request is not being modified. Is this feature still in development?
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Comments: 19 (13 by maintainers)
Commits related to this issue
- Mitigate POST issue in IIS #255 — committed to microsoft/reverse-proxy by Tratcher 4 years ago
- Mitigate POST issue in IIS #255 — committed to microsoft/reverse-proxy by Tratcher 4 years ago
- Mitigate POST issue in IIS #255 (#335) — committed to microsoft/reverse-proxy by Tratcher 4 years ago
Here’s a workaround you can do without modifying YARP. Add this in Startup anywhere before UseEndpoints, or even in the MapReverseProxy pipeline. Note this completely disables WebSocket proxying.
You could choose to be more selective by checking the upgrade header first.
I’m going to add the same check for preview3 as a temporary mitigation.
Yup, it repros in IIS Express. A quick debug shows IsUpgradableRequest is returning true in IIS Express for mysterious reasons. https://github.com/microsoft/reverse-proxy/blob/92bbf67c5dfca6539a7d23f7f920519f6145a166/src/ReverseProxy/Service/Proxy/HttpProxy.cs#L94
That puts it on the websocket code path which drops the request body.
Thanks for the report @maeneak, we’ll get to the bottom of this.
Well that explains it… https://github.com/dotnet/aspnetcore/blob/df712cc4a97d0bc8d573979008a5a2cc381f8117/src/Servers/IIS/IIS/src/Core/IISHttpContext.FeatureCollection.cs#L210 Compare to HttpSys: https://github.com/dotnet/aspnetcore/blob/0fbf919d505b8ff1708ad29d43c68d4d7fd5c1a5/src/Servers/HttpSys/src/RequestProcessing/Request.cs#L259
Filed https://github.com/dotnet/aspnetcore/issues/23172
Transforms were introduced in preview2 which has not been released yet. You can either build the repo locally or wait for preview2 to release (soon).