当多个虚拟服务器共享同一个监听套接字并通过 SNI 加以区分时,nginx 的 stream SSL 模块在握手流程中执行 ssl_verify_client 检查的时机过晚。客户端如果发送受证书保护的 server 块的 SNI 主机名,但不提供客户端证书,就可以绕过双向 TLS 并访问受保护的后端。
| 字段 | 值 |
|---|---|
| CVE | CVE-2026-120967 |
| CVSS 3.1 | 4.8 Medium — AV:N/AC:H/PR:N/UI:N/S:U/C:H/I:N/A:N |
| CWE | CWE-295(证书验证不当) |
| 组件 | ngx_stream_ssl_module(SNI 路由) |
| 受影响版本 | nginx 1.25.5 – 1.31.8 |
| 修复版本 | nginx 1.30.7 / 1.31.9 |
| 所需认证 | 无 |
| 披露日期 | 2026-11-18 |
当两个 stream 服务器共享同一套接字地址且仅通过 ssl_server_name 区分时,nginx 会根据 TLS SNI 扩展选择 server 块。在受影响版本中,与所选 server 块关联的 ssl_verify_client 检查是在 stream 路由决策已经确定之后才执行的。客户端如果发送 SNI = secure.test 但不提供客户端证书,就会被路由到受保护的后端,而不会触发证书验证失败。
实验环境布局:
nginx:1.31.8 stream :9443
server { ssl_server_name default.invalid; ... } ← no mTLS
server { ssl_server_name secure.test; ← mTLS required
ssl_verify_client on;
ssl_client_certificate ca.pem; ... }
↓
backend (raw TCP) — replies "secret" to any request
flowchart LR
A([Attacker\nNo client cert]) -->|TLS SNI = secure.test\nNo client certificate| B[nginx stream\n1.31.8]
B -->|SNI matches protected\nserver block| C{ssl_verify_client\napplied AFTER routing}
C -->|Routes to backend\nbefore cert check| D[Protected Backend\nAccessed]
D --> E([mTLS Bypass\nConfidential data exposed])
style A fill:#3d1a1a,stroke:#f85149,color:#f85149
style E fill:#1a1f2e,stroke:#58a6ff,color:#58a6ff
警告: 仅限 Docker Compose 实验环境。
docker compose up --build -d
sleep 5
python3 poc.py
预期输出——存在漏洞的 nginx:
[+] BYPASS CONFIRMED — backend reached without client certificate!
SNI: secure.test cert: none response: "secret"
[!] VULNERABLE — ssl_verify_client bypassed via SNI routing race
python3 poc.py --host 127.0.0.1 --port 9443
| 参数 | 描述 |
|---|---|
--host HOST | nginx 主机(默认:127.0.0.1) |
--port PORT | 流端口(默认:9443) |
--sni NAME | 要发送的 SNI 主机名(默认:secure.test) |
--no-cert | 跳过客户端证书(默认 — 这就是绕过方式) |
--with-cert | 提供有效的客户端证书(基线 — 应当成功) |
python3 poc.py --with-cert
# Expected: HTTP 200, backend reached with valid cert
# nginx 1.31.9
python3 poc.py
# TLS error: certificate verify failed
# [+] NOT vulnerable — ssl_verify_client enforced before routing
| 指标 | 说明 |
|---|---|
在 mTLS 端口上 TLS 握手成功,但日志中缺少 SSL_client_cert 字段 | nginx 访问日志:检查是否缺少 $ssl_client_cert |
| 后端被意外客户端访问 | 后端访问日志:存在无有效客户端身份的连接 |
TLS 握手中出现 SNI secure.test 但无客户端证书 | 网络抓包:ClientHello 中包含 SNI,但无 Certificate 握手消息 |
能够访问 nginx stream 端口的网络中的攻击者可以绕过双向 TLS 认证,并连接到任何仅依赖 nginx 的 ssl_verify_client on 进行访问控制的后端。
升级至 nginx 1.30.7 或 1.31.9。该修复确保在路由决策提交之前强制执行 ssl_verify_client。
| 操作 | 详情 |
|---|---|
| 升级 nginx | 1.30.7(稳定版)或 1.31.9(主线版) |
| 临时缓解措施 | 将 mTLS 服务器迁移至专用监听套接字(不与无 mTLS 的服务器共享) |
| 后端校验 | 在后端层增加双向 TLS 校验,作为纵深防御 |
免责声明: 仅限授权安全研究与受控实验环境使用。MIT 许可证。