Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Ensure HTTP Host Header format compliance #1905

Merged
merged 1 commit into from
Feb 3, 2025

Conversation

sfiction
Copy link
Contributor

@sfiction sfiction commented Feb 2, 2025

  • Non-default ports are explicitly included in the Host header
  • Default ports (443 for HTTPS) are omitted
  • IPv6 addresses are properly enclosed in square brackets ([ ]) per RFC 3986

smartdns 在发送 https 请求时,会添加 Host 字段,内容为 https_flag->httphost。上游为 flag_http->httphost => server->httphost => server->serverserver->server 则来自配置文件中服务器地址的解析结果,当 url 中 host 为 ipv6 地址时,util.c:parse_ip 会移除首尾的 [ ]。而在 RFC 规范 中,Host 字段中的 ipv6 地址必须用方括号包裹。cloudflare 和 google 的服务器都会拒绝错误格式的 Host 字段。目前可以用 -http-host 选项暂时解决这个问题。

配置:

# cloudflare
server-https https://[2606:4700:4700::64]/dns-query
# google
server-https https://[2001:4860:4860::64]/dns-query

报错:

dns_client.c:2876] http server query from 2606:4700:4700::64:443 failed, server return http code : 403, Forbidden
dns_client.c:2876] http server query from 2001:4860:4860::64:443 failed, server return http code : 400, Bad Request

其他复现方式:

# www.google.com AAAA
curl -v 'https://[2606:4700:4700::64]:443/dns-query?dns=IlkBAAABAAAAAAAAA3d3dwZnb29nbGUDY29tAAAcAAE' -H 'Host: 2606:4700:4700::64'
curl -v 'https://[2001:4860:4860::64]:443/dns-query?dns=IlkBAAABAAAAAAAAA3d3dwZnb29nbGUDY29tAAAcAAE' -H 'Host: 2001:4860:4860::64'

- Non-default ports are explicitly included in the Host header
- Default ports (443 for HTTPS) are omitted
- IPv6 addresses are properly enclosed in square brackets (`[ ]`) per
  RFC 3986
@pymumu pymumu merged commit d7c92f0 into pymumu:master Feb 3, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants