Skip to content

SSRF 防护(SSRF protection)#

Available since 2.12.0

服务器端请求伪造(SSRF)攻击滥用工作流节点向内部网络资源、云元数据端点或不应访问的本地主机服务发起请求。

🌐 Server-Side Request Forgery (SSRF) attacks abuse workflow nodes to make requests to internal network resources, cloud metadata endpoints, or localhost services that shouldn't be accessible.

/// 警告 SSRF 保护是一种额外的应用层防御。你应始终在基础设施上配置网络级别的防护(防火墙、安全组、网络策略)作为你的主要防线。n8n 的 SSRF 保护在这些控制措施之上增加了纵深防御。 ///

启用 SSRF 保护(Enable SSRF protection)#

1
N8N_SSRF_PROTECTION_ENABLED=true

启用后,n8n 会验证所有来自用户可控节点(例如 HTTP 请求节点)的出站 HTTP 请求,使用配置的阻止和允许范围进行检测。这包括重定向目标和 DNS 解析,以防止绕过技术,如 DNS 重新绑定。

🌐 When enabled, n8n validates all outbound HTTP requests from user-controllable nodes (such as the HTTP Request node) against the configured blocked and allowed ranges. This includes redirect targets and DNS resolution to prevent bypass techniques like DNS rebinding.

默认阻止范围(Default blocked ranges)#

当启用 SSRF 保护时,默认会阻止以下 IP 范围:

🌐 When SSRF protection is enabled, the following IP ranges are blocked by default:

范围 描述
10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16 RFC 1918 私有地址
127.0.0.0/8, ::1/128 回环
169.254.0.0/16, fe80::/10 链路本地
fc00::/7, fd00::/8 IPv6 唯一本地
0.0.0.0/8, 192.0.0.0/24, 192.0.2.0/24, 198.18.0.0/15, 198.51.100.0/24, 203.0.113.0/24 保留/特殊用途

你可以用 N8N_SSRF_BLOCKED_IP_RANGES=default,100.0.0.0/8 扩展此列表。

🌐 You can extend this list with N8N_SSRF_BLOCKED_IP_RANGES=default,100.0.0.0/8.

允许访问内部服务(Allow access to internal services)#

如果你的工作流程需要访问合法的内部服务,请使用允许列表。允许列表优先于阻止列表,遵循以下顺序:主机名允许列表 > IP允许列表 > IP阻止列表。

🌐 If your workflows need to reach legitimate internal services, use allowlists. Allowlists take precedence over blocklists, following this order: hostname allowlist > IP allowlist > IP blocklist.

按主机名模式允许(支持像 *.n8n.internal 这样的通配符):

🌐 Allow by hostname pattern (supports wildcards like *.n8n.internal):

1
N8N_SSRF_ALLOWED_HOSTNAMES=*.n8n.internal,*.company.local

允许的 IP 范围:

🌐 Allow by IP range:

1
N8N_SSRF_ALLOWED_IP_RANGES=10.0.1.0/24,10.0.2.50/32

/// 警告 仅允许在你控制范围内的主机名(内部 DNS 区域)。主机名允许列表会绕过 IP 黑名单检查。 ///

有关完整的配置选项列表,请参阅 SSRF 保护环境变量

🌐 Refer to SSRF protection environment variables for the full list of configuration options.

有关设置环境变量的更多信息,请参阅配置方法

🌐 Refer to Configuration methods for more information on setting environment variables.