cloudflare / cloudflare/cloudflared
🐛 no forward request for `Host` header including no-ASCII characters
- Dominant language
- Go
- Stars
- 15.6k
- Forks
- 1.4k
- PR merge metrics
- No merged PRs in 30d
Description
**Describe the bug**
400 Bad Request error when using cloudflare tunnel, It seems that the issue is with the `Host` Header.
Generally, the `Host` matches url, but the issue is with domain containing non-ASCII characters.
In some HTTP client requests, `request.URL.Host` is converted to `punycode` for DNS lookup, but `request.Host` Header may not (still non-ASCII), it results url mismatch with Host Header.
However, the issue can't be fixed by editing cloudflared source code, it seems that cloudflare edge returning a 400 Bad Request due to `Host` header mismatch. edge doesn't forward the request to local cloudflared service, because I can't receive any log info under `--loglevel debug` mode.
The following log is that I mocked request by curl, and the response is 400 Bad Request:
```log
❯ curl https://test.ᱛ.com -I -H "Host: test.ᱛ.com"
HTTP/1.1 400 Bad Request
Server: cloudflare
Date: Thu, 09 Jan 2025 06:49:13 GMT
Content-Type: text/html
Content-Length: 155
Connection: close
CF-RAY: -
```
If you send punycode domain in `Host` Header, it will work fine:
```log
❯ curl https://test.ᱛ.com -I -H "Host: test.xn--02f.com"
HTTP/1.1 404 Not Found
Date: Thu, 09 Jan 2025 06:49:02 GMT
Content-Type: text/html; charset=utf-8
Connection: keep-alive
x-request-id: d30a13bb-6572-47e6-b197-07c6bb232030
cf-cache-status: DYNAMIC
Report-To: {"endpoints":[{"url":"https:\/\/a.nel.cloudflare.com\/report\/v4?s=t4Az5lZMh95U6wdaj3GiYWSWukrIWOhMdYeu9TxgiBE2%2F0hoRn6g2PViR1xWwKG5AeMmM64erU8DpXcX6fUHXHK9wOAYcGRO8EibbcIN558%2FHqaDWn0%2FekRkI4N6DFk0LIKh"}],"group":"cf-nel","max_age":604800}
NEL: {"success_fraction":0,"report_to":"cf-nel","max_age":604800}
Server: cloudflare
CF-RAY: 8ff27c2e7d68658e-SIN
alt-svc: h3=":443"; ma=86400
server-timing: cfL4;desc="?proto=TCP&rtt=4790&min_rtt=3257&rtt_var=2316&sent=4&recv=5&lost=0&retrans=0&sent_bytes=2704&recv_bytes=479&delivery_rate=889161&cwnd=242&unsent_bytes=0&cid=e1431823fd76aa9c&ts=238&x=0"
```
**To Reproduce**
Steps to reproduce the behavior:
1. Configure '...'
2. Run '....'
3. See error
**Environment and versions**
- OS: Windows
- Architecture: amd64
- Version: 2025.1.0
Contributor guide
Assessment
This issue has not been assessed yet.