Summary
FastGPT's URL filtering logic for blocking cloud metadata endpoints can be bypassed using multiple URL encoding techniques that evade its simple prefix-based checks.
When combined with a disabled-by-default internal IP validation, these flaws can allow attackers controlling outbound URLs to reach cloud metadata services from the FastGPT server environment.
Affected context
This vulnerability affects FastGPT deployments where:
- The application allows users, workflows, or agents to supply or influence outbound URLs.
- The
isInternalAddress()function inpackages/service/common/system/utils.tsis relied upon to block access to cloud metadata endpoints. - The broader private IP validation (
isInternalIPv4/isInternalIPv6) remains disabled via the defaultCHECK_INTERNAL_IP = falseconfiguration.
In such setups, the application runs in a cloud or container environment where standard metadata endpoints (e.g., 169.254.169.254, metadata.google.internal) are reachable from the server or runtime node.
Exploit preconditions
- Attack surface: Any feature that causes the FastGPT backend to perform HTTP(S) requests to user-controlled or user-influenced URLs (e.g., tools, connectors, web content fetchers).
- Required access: Ability to configure, submit, or indirectly control URLs processed by the FastGPT server; no direct network access to the metadata service is required.
- Trigger point: The server-side call path that invokes
isInternalAddress()to validate a target URL before performing an outbound request. - Why exploitation is possible:
- The blocklist uses
fullUrl.startsWith()against hardcoded strings for known metadata URLs. - Multiple URL encodings and variations can be used that still resolve to the same metadata endpoint but do not match the simplistic prefix patterns.
- The general internal IP protection (
CHECK_INTERNAL_IP) is false by default, so requests that bypass the prefix checks are not subjected to any fallback IP-level validation. - As a result, the server can be induced to perform SSRF requests to cloud metadata endpoints.
Why this happens
The underlying flaw is a classic blocklist-based SSRF defense combined with incomplete canonicalization of URLs before access checks.
Instead of normalizing and validating the effective destination (scheme, host, port, and resolved IP), the code:
- Relies on
fullUrl.startsWith()against a small, hardcoded set of metadata URL prefixes. - Does not robustly canonicalize or normalize URLs before the prefix comparison, leaving gaps for alternative encodings, hostname representations, or path tricks.
- Leaves broader internal IP checks disabled by default (
CHECK_INTERNAL_IP = false), removing a critical defense-in-depth layer.
This maps to CWE-918: Server-Side Request Forgery (SSRF), where an application sends requests to internal or protected resources based on untrusted input, and insufficient validation allows access to sensitive network locations.
Potential impact
- Access to cloud instance metadata endpoints that may expose:
- Temporary access tokens or credentials.
- Instance identity documents or service account information.
- Network configuration and environment-specific secrets.
- Use of obtained credentials to access other cloud services, storage, or APIs.
- Pivoting into internal services accessible only from the FastGPT hosting environment.
- Enumeration or probing of internal network ranges, depending on available endpoints and credentials.
- Escalation from application-level compromise to broader infrastructure compromise in some cloud environments.
General mitigation guidance
Effective mitigation focuses on strong SSRF-hardening patterns and removing reliance on simple blocklists:
- Prefer allowlist-based egress control:
- Restrict outbound HTTP(S) traffic from the application to a minimal set of approved domains or services.
- Deny access to link-local and metadata IP ranges (e.g.,
169.254.169.254) at the network or host firewall level, independent of application logic. - Implement robust URL and IP validation:
- Parse and canonicalize URLs using a standards-compliant library before applying any checks.
- Resolve hostnames and validate the resulting IP address is not private, loopback, link-local, or otherwise internal, before allowing the request.
- Avoid string-based prefix checks for security decisions; use structured comparisons on scheme, host, port, and resolved IP ranges.
- Enforce secure-by-default configuration:
- Default internal IP checks and SSRF protections to enabled, requiring explicit opt-out with clear documentation of implications.
- Centralize and standardize outbound request utilities with SSRF-safe defaults rather than ad-hoc HTTP calls spread across code.
- Harden the runtime environment:
- Use cloud or container security controls to block access to metadata endpoints where feasible (e.g., metadata protection features, IMDSv2-only, or disabling token issuance).
- Apply least-privilege to instance roles and service accounts so that accidental metadata access yields minimal permissions.
These measures reduce the risk even if application-level URL validation has gaps.
How teams detect issues like this
Detection can combine code-centric and operational approaches:
- Static analysis and code scanning:
- Flag direct use of low-level HTTP clients where URLs may contain user input without passing through a vetted SSRF-safe wrapper.
- Identify security checks that rely on string prefix matching (
startsWith) or naive substring patterns for URL or host validation. - Detect configuration flags that disable internal IP protection or SSRF mitigations and require security review when changed.
- Security-focused code review:
- Trace data flows from user-controllable URL parameters (or tools/agents that construct URLs) into outbound HTTP calls.
- Confirm that URL parsing, normalization, DNS resolution, and IP validation occur in a single trusted component.
- Review default configuration values to ensure protections are opt-out rather than opt-in.
- Runtime monitoring and logging:
- Log outbound requests including destination host/IP and response characteristics (with appropriate privacy controls).
- Configure alerts on access attempts to known metadata endpoints (e.g.,
169.254.169.254,metadata.google.internal) and other internal ranges. - Monitor for abnormal patterns of egress traffic originating from FastGPT components.
- Automated tooling:
- Integrate SSRF-focused tests into CI/CD, using fuzzing or encoding variations on URLs to validate protections.
- Use SAST/DAST tools that specifically check for SSRF sinks and weak URL validation logic.

