4. 可能的安全问题
当 HTTP/1.1 连接中只涉及两个不同的参与方 (即客户端和服务器) 时, 协议转换不会引入新的安全问题: 每一方本来就必须准备好另一方随时在连接上发送任意数据. 然而, 如果请求或响应包含第三方数据, HTTP 连接通常会涉及两个以上的参与方. 例如, 浏览器 (参与方 1) 可能向源站 (参与方 2) 发送 HTTP 请求, 其中路径, 头部或内容由来自不同源的某个网站 (参与方 3) 控制. 转换后的协议, 例如 WebSocket [WEBSOCKET], 也经常用于传送由第三方选择的数据.
如果第三方数据源不可信, 那么它提供的数据就可能是 "attacker-controlled". attacker-controlled 数据与 optimistic protocol transition 的组合会产生两个重要的安全问题.
4.1. Request Smuggling
在 Request Smuggling 攻击 ([HTTP/1.1], Section 11.2) 中, attacker-controlled 数据被选择成一种会被服务器解释为额外 HTTP 请求的形式. 这些攻击允许攻击者代表客户端发言, 同时绕过客户端自身关于它会发出哪些请求的规则. 如果客户端和服务器对二者之间流动的数据有不同解释, 就可能发生 Request Smuggling.
如果服务器接受协议转换请求, 它会按照新协议解释后续字节. 如果服务器拒绝该请求, 它会将这些字节解释为 HTTP/1.1. 然而, 在收到服务器响应状态码之前, 客户端无法知道服务器将采用哪种解释. 如果客户端 optimistic 地使用新协议, 就会产生一种风险: 服务器可能把新协议中的 attacker-controlled 数据解释为客户端发出的额外 HTTP 请求.
作为一个简单示例, 考虑一个 HTTP CONNECT 客户端向不可信应用提供连接能力. 如果客户端使用 TLS Client Certificates ([TLS], Section 4.4.2) 等连接级认证方法向代理服务器认证, 攻击者就可以在其 TCP 连接开头向代理服务器发送一个 HTTP/1.1 POST 请求 ([HTTP], Section 9.3.3). 如果客户端 optimistic 地交付这些数据, 且 CONNECT 请求失败, 服务器会把该应用的数据误解为客户端随后发出的已认证请求.
## REQUESTS ##
# The malicious application requests a TCP connection to a nonexistent
# destination, which will fail.
CONNECT no-such-destination.example:443 HTTP/1.1
Host: no-such-destination.example:443
# Before connection fails, the malicious application sends data on the
# proxied TCP connection that forms a valid POST request to the proxy.
# The vulnerable client optimistically forwards this data to the proxy.
POST /upload HTTP/1.1
Host: proxy.example
Content-Length: 123456
<POST body controlled by the malicious application>
## RESPONSES ##
# When TCP connection establishment fails, the proxy responds by
# rejecting the CONNECT request, but the client has already forwarded
# the malicious TCP payload data to the proxy.
HTTP/1.1 504 Gateway Timeout
Content-Length: 0
# The proxy interprets the smuggled POST request as coming from the
# client. If connection-based authentication is in use (e.g., using
# TLS client certificate authentication), the proxy treats this
# malicious request as authenticated.
HTTP/1.1 200 OK
Content-Length: 0
图 1: 使用 HTTP CONNECT 的 Request Smuggling 攻击示例.
4.2. Parser Exploits
一类相关攻击利用协议分歧来触发服务器请求解析逻辑中的漏洞. 当 HTTP 客户端受服务器信任, 但转换后的数据源不受信任时, 这些攻击适用. 如果服务器软件是在部分或全部 HTTP 请求数据并非 attacker-controlled 的假设下开发的, optimistic 传输可能使这一假设被破坏, 从而暴露服务器 HTTP 请求 parser 中的漏洞.