大网数据广告活动
服务器运维问答

Is the Host: header required over SSL?

· 52CE 我爱测

Is the Host: header required over SSL even if the request is not HTTP/1.1? So, if a client connects over SSL, and sends the following request: GET / HTTP/1.0 Should the web server throw a bad request due to the missing Host: head…

问题原文

原帖链接 · ImBoredAllTheTime · CC BY-SA 4.0

Is the Host: header required over SSL even if the request is not HTTP/1.1?

So, if a client connects over SSL, and sends the following request:

GET / HTTP/1.0
  1. Should the web server throw a bad request due to the missing Host: header?
  2. Should the web server respond with an HTTP/1.0 200 OK response?
    (the index.html file always exists, so a request to /, would never lead to 403/404)

Update:

If I disable SNI in openssl s_client, apache works without the Host: header.

Why does it need the Host: header when SNI is on?

社区高分解答

原帖链接 · kbolino · CC BY-SA 4.0

To answer the part of the question added in an update,

Why does it need the Host: header when SNI is on?

"Need" is a strong word but it helps to understand that SNI and HTTP headers operate at two different layers and accordingly serve two different purposes.

SNI is primarily used to determine which certificate to give the client. In a setup with multiple virtual hosts, before the payload is decrypted, the server has to present a certificate to the client. Since the certificate contains the name of the site, traditionally in the common name of the certificate subject, but lately in the X.509 extension subject alternative names, presenting the wrong certificate would cause the client to reject the connection before even sending the HTTP request to the server.

Whereas, the Host header is primarily used to determine which resource to serve. In well behaved clients this is redundant with the name in SNI but HTTP/1.1 was developed around the same time as SSL 3.0 and thus well before the TLS-SNI extension even existed. In fact, it was the combination of HTTP/1.1 and SSL/TLS where the need for SNI was discovered in the first place.

It may be worth noting that HTTP/2 does not require the Host header but has a functional equivalent in the form of the :authority pseudo-header. Though the information in that header will still be redundant with TLS-SNI in most cases, it simplifies the implementation to always include it.

Always including the Host (or :authority) header also leaves open the possibility of barebones SSL termination (though in practice there is very little support for HTTP/2 without TLS). However, not validating that the host/authority matches the name in TLS-SNI could open up a security hole in some setups.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2021-04-13)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。